Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Allow for setting of file location by env #4

Merged
merged 1 commit into from
May 13, 2020

Conversation

dantuck
Copy link
Collaborator

@dantuck dantuck commented May 11, 2020

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

  • Ledger file location is set by -l first and then if not set uses env var.

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

- Ledger file location is set by -l first and then if not set uses env var.
@ebcrowder
Copy link
Owner

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
Copy link
Collaborator Author

dantuck commented May 12, 2020

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
Copy link
Owner

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

Awesome - thanks again for the contribution.

@ebcrowder ebcrowder merged commit 511241e into ebcrowder:master May 13, 2020
@dantuck dantuck deleted the feature/file-env branch May 13, 2020 02:50
@dantuck
Copy link
Collaborator Author

dantuck commented May 13, 2020

Glad to help. More to come.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants