-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Json config file must be overriden by env variable and by command-line argument #26
base: master
Are you sure you want to change the base?
Conversation
Thanks for the PR! Took a quick look, I think the true solution to this is a multistage flags parse.
This removes the need to store copies on item, and keeps the code simpler (1 pass instead of 2) This would require a pkg/flag replacement but also enables multi shorts (ps -aux) and flags after args. I’ll consider this if the above turns out to be too complex. Need to evaluate it. |
@jpillora OK. I don't fully get the multistage approach, so I look forward to see your patch. In the meantime, I'll keep my fork: that item copy solution was simpler for me to implement. I didn't test multi short options though. Are they currently supported by opts? |
any news on this ? |
Unfortunately no. I'd like to write my own flag parser, so I can peek at the flags without storing the result on the struct. |
A command-line parameter ought to override a default value from a JSON configuration file. See issue jpillora#25
Fix #25
I have added a "value copy" in
item
, in order to be able to restore that copied value after the JSON unmarshalling (opts/node_parse.go
Lines 145 to 155 in 8ed9e9c
Before, the JSON unmarshalled directly in
item.val
meant that any parameter/environment variable (previously set initem.val
) was overridden.Now, a "
--myparam myvalue
" correctly takes precedence over a static default "myparam" value stored in a JSON file.Same for a
MYPARAM
environment variable.All tests are OK.