diff --git a/Cargo.lock b/Cargo.lock index 0bac83e..1d80070 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,13 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "atty" version = "0.2.14" @@ -15,6 +23,11 @@ name = "autocfg" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bstr" version = "0.2.13" @@ -42,6 +55,20 @@ dependencies = [ "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "clap" +version = "2.33.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "colored" version = "2.0.0" @@ -135,11 +162,6 @@ dependencies = [ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "pargs" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "proc-macro2" version = "1.0.19" @@ -166,13 +188,13 @@ dependencies = [ [[package]] name = "rust_ledger" -version = "0.4.1" +version = "0.4.2" dependencies = [ "chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)", "colored 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "csv 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "monee 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "pargs 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)", "serde_yaml 0.8.13 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -211,6 +233,11 @@ dependencies = [ "yaml-rust 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "syn" version = "1.0.38" @@ -221,6 +248,14 @@ dependencies = [ "unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-width 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "time" version = "0.1.43" @@ -230,11 +265,21 @@ dependencies = [ "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unicode-xid" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "winapi" version = "0.3.9" @@ -263,11 +308,14 @@ dependencies = [ ] [metadata] +"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum bstr 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931" "checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" "checksum chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)" = "942f72db697d8767c22d46a598e01f2d3b475501ea43d0db4f16d90259182d0b" +"checksum clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)" = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" "checksum colored 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" "checksum csv 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279" "checksum csv-core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" @@ -281,7 +329,6 @@ dependencies = [ "checksum monee 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "10185d7e26610b2ca56d56254e26b1654bbe964e7bd94be07d726f964d19d2db" "checksum num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" "checksum num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" -"checksum pargs 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab9021fd518ce95acf9c8f7c325187d456268464b07965d7ee3e96adf30609e3" "checksum proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" "checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" "checksum regex-automata 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" @@ -289,9 +336,13 @@ dependencies = [ "checksum serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)" = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" "checksum serde_derive 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)" = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" "checksum serde_yaml 0.8.13 (registry+https://github.com/rust-lang/crates.io-index)" = "ae3e2dd40a7cdc18ca80db804b7f461a39bb721160a85c9a1fa30134bf3c02a5" +"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum syn 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)" = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4" +"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" "checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +"checksum unicode-width 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" "checksum unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +"checksum vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" "checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index fee7d9d..ea21d4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rust_ledger" -version = "0.4.1" +version = "0.4.2" authors = ["ebcrowder "] edition = "2018" license = "GPL-3.0" @@ -15,7 +15,7 @@ readme = "README.md" serde_yaml = "0.8.13" serde = { version = "1.0.114", features = ["derive"] } csv = "1.1.3" -pargs = "0.2.1" colored = "2.0.0" monee = "0.0.5" chrono = { version = "0.4", features = ["serde"] } +clap = "2.33.3" diff --git a/README.md b/README.md index 66eebc1..5e4f89c 100644 --- a/README.md +++ b/README.md @@ -17,20 +17,23 @@ As a former CPA, I could not resist building my own accounting system. - Includes a tool to convert `csv` files to `yaml` format ### Contributing + - See `CODE_OF_CONDUCT.md` for fundamental guidelines - PRs, issues and feature requests are welcome and encouraged -- Join us on Matrix (#rust_ledger:matrix.org) at https://matrix.to/#/!dYISGJYNNiZcUrxhcm:matrix.org?via=matrix.org +- Join us on Matrix (#rust_ledger:matrix.org) at https://matrix.to/#/!dYISGJYNNiZcUrxhcm:matrix.org?via=matrix.org ### Install -#### From Cargo +#### From Cargo `cargo install rust_ledger` #### Binaries for Linux, macOS, and Windows + We distribute binaries for the above platforms. See [releases](https://github.com/ebcrowder/rust_ledger/releases) for a complete list by version. Additionally, we currently ship binaries through the following package managers: + - Arch Linux AUR - rust_ledger-bin #### Build from Source @@ -43,42 +46,55 @@ Alternatively, clone this repo and do the following: ### Usage -`rust_ledger -f LEDGER_FILE_PATH COMMAND -o OPTION` +`rust_ledger --help` will provide a menu of all available commands and optional arguments. + +```bash +rust_ledger +Eric Crowder + +USAGE: + rust_ledger [SUBCOMMAND] + +FLAGS: + -h, --help Prints help information + -V, --version Prints version information + +SUBCOMMANDS: + account account module + balance balance module + csv csv module + help Prints this message or the help of the given subcommand(s) + register register module +``` + +`rust_ledger COMMAND -f LEDGER_FILE_PATH` LEDGER_FILE_PATH (denoted by `-f`) - relative path to location of yaml ledger file - - Optionally, the ledger file path can be set via the environment variable `RLEDGER_FILE` in lieu of specifying whenever the program is invoked. - - If `-f` is provided with a file path the file provided will be used instead of any `RLEDGER_FILE` set. +- Optionally, the ledger file path can be set via the environment variable `RLEDGER_FILE` in lieu of specifying whenever the program is invoked. +- If `-f` is provided with a file path the file provided will be used instead of any `RLEDGER_FILE` set. ``` -RLEDGER_FILE=~/rledger.yaml rust_ledger balances +RLEDGER_FILE=~/rledger.yaml rust_ledger balance ``` `RLEDGER_FILE` can be set as a system or user environment variable. ``` -export RLEDGER_FILE="$HOME/rledger.yaml" +export RLEDGER_FILE=$HOME/rledger.yaml ``` -COMMAND - ledger command (account, balance, register, or csv) - -OPTION (denoted by `-o`) - allows you to filter the output of the `register` command by account type. For example, if you wish to only see "expense" transactions in the output, you would pass in `expense` as the option here. Additionally, the csv tool uses this parameter for specifying the csv file to be parsed. - -GROUP (denoted by `-g`) - allows you to group the output of the `register` command by `year` or `month`. - -OFFSET (denoted by `-s`) - required for csv tool. Specifies the offsetting account that each transaction should be posted against. - ### Environment Variables `RLEDGER_FILE` - Path to rledger file. ex: `RLEDGER_FILE=~/rledger.yaml` `NO_COLOR` - Disables color output. ex: `NO_COLOR=true` -### Features +## Features -#### Transactions +### Transactions -Transactions can be expressed in two different ways. One is a "simplified" format for transactions that only impact two accounts: +Transactions can be expressed in two different ways. One is a "simplified" format for transactions that only impact two accounts: ```yaml - date: 2020-01-01 @@ -88,9 +104,9 @@ Transactions can be expressed in two different ways. One is a "simplified" forma account: expense:expense_general ``` -The sign (debit / credit) associated with the `offset_account` value is the opposite of the sign of the value contained in `amount` field. +The sign (debit / credit) associated with the `offset_account` value is the opposite of the sign of the value contained in `amount` field. -In the above example transaction, since `expense_general` was debited by 200, the `credit_card_amex` account will be credited by the same amount. +In the above example transaction, since `expense_general` was debited by 200, the `credit_card_amex` account will be credited by the same amount. Transactions that involve more than two accounts are expressed in the following manner: @@ -106,63 +122,113 @@ Transactions that involve more than two accounts are expressed in the following account: liability:credit_card_amex ``` -Transactions that only involve two accounts can also be expressed in the above format. +Transactions that only involve two accounts can also be expressed in the above format. -### Test +## Test - `cargo test` -### API +## API + +### account + +``` +rust_ledger-account +account module + +USAGE: + rust_ledger account [OPTIONS] -- account - - lists accounts - - example output: +FLAGS: + -h, --help Prints help information + -V, --version Prints version information +OPTIONS: + -f, --filename location of ledger file ``` - Account + +- lists accounts +- example output: + +``` + Account --------------------------------------- -asset:cash_checking -asset:cash_savings -liability:credit_card_amex -equity:equity -expense:grocery -expense:general -expense:mortgage +asset:cash_checking +asset:cash_savings +liability:credit_card_amex +equity:equity +expense:grocery +expense:general +expense:mortgage income:general ``` -- balance - - lists account balances to date - - example output: +### balance + +``` +rust_ledger-balance +balance module + +USAGE: + rust_ledger balance [OPTIONS] + +FLAGS: + -h, --help Prints help information + -V, --version Prints version information + +OPTIONS: + -f, --filename location of ledger file +``` + +- lists account balances to date +- example output: ``` - Account Balance + Account Balance --------------------------------------- asset - asset:cash_checking $ -700.00 - asset:cash_savings $ 1000.00 + asset:cash_checking $ -700.00 + asset:cash_savings $ 1000.00 liability - liability:credit_card_amex $ -455.00 + liability:credit_card_amex $ -455.00 equity - equity:equity $ -3500.00 + equity:equity $ -3500.00 expense - expense:grocery $ 635.00 - expense:general $ 1020.00 - expense:mortgage $ 2000.00 + expense:grocery $ 635.00 + expense:general $ 1020.00 + expense:mortgage $ 2000.00 income - income:general 0 + income:general 0 --------------------------------------- -check 0 +check 0 +``` + +### register + +``` +rust_ledger-register +register module + +USAGE: + rust_ledger register [OPTIONS] + +FLAGS: + -h, --help Prints help information + -V, --version Prints version information + +OPTIONS: + -f, --filename location of ledger file + -g, --group group register output by value + -o, --option