ebcrowder / rust_ledger

Rust implementation of ledger, the command line accounting tool.
GNU General Public License v3.0
137 stars 19 forks source link

Allow for setting of file location by env #4

Closed dantuck closed 4 years ago

dantuck commented 4 years ago

Environment var RLEDGER_FILE added as optional to set location of ledger file

ebcrowder commented 4 years ago

Thanks for this!

From reading the code and testing the branch code a bit locally, it seems like the user would still have to pass in an argument of -l $RLEDGER_FILE in order for this to work. Was that the intent? From reading the original ledger docs (https://www.ledger-cli.org/3.0/doc/ledger3.html#Environment-variables), env vars can be used in lieu of arguments altogether, which would make calling the tool much less verbose if they are set.

I wonder if we can do that here, too? For example, if $RLEDGER_FILE was set, a user could simply do rust_ledger accounts for accounts, and so on.

We would probably have to unwind how I parse args in main.rs, but I could see that being useful.

However, this iteration looks good and I'd be happy to approve. Just wanted to run the above by you to see what you think.

dantuck commented 4 years ago

Actually I have implemented to that you can have the env var set and use it as you described. To test in one line you can do the following:

RLEDGER_FILE=~/rledger.yaml cargo run rust_ledger balances

or in your .profile or .zprofile

export RLEDGER_FILE="$HOME/rledger.yaml"

If by chance you have this env set you can always specify a different file with -l and that will ignore the env var and use what you pass in to the command.

ebcrowder commented 4 years ago

ah, I see that now! I was setting my env variable incorrectly 😬

Awesome - thanks again for the contribution.

dantuck commented 4 years ago

Glad to help. More to come.