-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Flag precedence failure for config file (v1) #706
Comments
Hi @ragecryx , I agree, the file shouldn't be required; it just shouldn't be loaded if it doesn't exist (at least as optional behavior). For now you can work around it by checking for file existence before calling PRs welcome for this. Thanks! |
@jszwedko I was willing to write a fix but the Before hook seems generic enough that skipping the failure check will break someone else's code. This should be handled on altsrc level, like EDIT: |
Yeah, I think handling this within I'd target Thanks for taking a look at this! |
How do you check that the fix exists if you haven't parsed the flags yet? For example, the file flag is |
@tonglil since Something like: app.Before = func(c *cli.Context) error {
if _, err := os.Stat(c.String("load")); os.IsNotExist(err) {
return ...
}
return altsrc.NewYamlSourceFromFlagFunc(flags, c.String("load"))(c)
} |
I made this fix #713 , I tested it in my project and it works with or without config file but I feel bad having the error not logged anywhere. Any tips about that? |
Hiya! There's a known issue with the current implementation of the CLI, where altsrc is generally clunky and poorly documented. My current idea is that I'm going to move all of the |
I have a setup as described in Values from alternate input sources (YAML, TOML, and others)
I try to run the executable with command line arguments, like:
tool dostuff --host my.super.host
config file doesn't exist and I don't provide one and the execution stops instead of relying on the provided arguments. The failure seems to happen on
command.go:197
(caused byaltsrc/flag.go:57
probably) where there is no YAML file to open thus it prints help and exits.Is there any workaround for this? Is it solved in v2?
The text was updated successfully, but these errors were encountered: