Skip to content
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

Override config file option value with option parameter #25

Open
VonC opened this issue Oct 28, 2019 · 3 comments · May be fixed by #26
Open

Override config file option value with option parameter #25

VonC opened this issue Oct 28, 2019 · 3 comments · May be fixed by #26

Comments

@VonC
Copy link

VonC commented Oct 28, 2019

The "Features with examples" sections includes:

Default values from a JSON config file, unmarshalled via your config struct

It refers to eg-config, which shows the program returns the config file default value, even when the command-line option specifies a different value.

$ config --bar moon
hello
world

Is this a bug or a feature?

If I store a static value 'world' for bar in config.json, but want to override it for this one-time execution on the command line, with --bar moon, I expect to see moon, not world.

I only expect to see world if I don't specify any option, which means the value of bar should be its default one, read from the config.json file.

Do I interpret that incorrectly?
Should I expect to override on command-line, with options, a default value read from a configuration file?

@jpillora
Copy link
Owner

jpillora commented Oct 28, 2019 via email

@VonC
Copy link
Author

VonC commented Oct 28, 2019

@jpillora OK, I thought I was using opts incorrectly ;-)

I'll have a look at the code then.

In the meantime, I found the "workaround" of:

  • redeclaring my Config fields as regular go flags
  • parsing those flags
  • overriding the config.value if said flags are valued

Not very convenient, but it works.

VonC added a commit to VonC/opts that referenced this issue Oct 28, 2019
A command-line parameter ought to override a default value from a JSON
configuration file.
See issue jpillora#25
@VonC
Copy link
Author

VonC commented Nov 4, 2019

@jpillora By any chance, did you review my proposed fix for this bug, with #26?

It does work quite well.

VonC added a commit to VonC/opts that referenced this issue Mar 12, 2022
A command-line parameter ought to override a default value from a JSON
configuration file.
See issue jpillora#25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants