-
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
V2: Making altsrc
flag optional in Before:
#793
Comments
EDIT: I have submitted a PR to address the specific issue originally described below for V1 (#802) and V2 (#803). I've actually run further into problems in that I would like to do more initialization in Before: altsrc.InitInputSourceWithContext(
flags,
func(context *cli.Context) (altsrc.InputSourceContext, error) {
if context.IsSet("load") {
// Fictitious function to load the configuration merging with Flags and ENV variables
altsrc.LoadTomlSourceFromFile(context.String("load"))
}
switch context.String("log-level") {
case "debug":
zerolog.SetGlobalLevel(zerolog.DebugLevel)
default:
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
// Make a connect all sub-commands will use
Queue, err := queue.RabbitMQ(context.String("aqmp-url"))
if err != nil {
return
}
return &altsrc.MapInputSource{}, nil
},
), |
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 |
Is there a way we can get an
altsrc
wrapper function to accomplish the following? Given that all of these features (env variables, flags, and config files) all override each other you do not want to mandate a configuration file be specified and instead make it OPTIONAL that it is specified:In
test.go
:In
test.toml
:And the above
test.go
will work as expected:The text was updated successfully, but these errors were encountered: