Repository navigation
Flag / Env / Config / Default argument ordering #566
Replies: 2 comments
|
FYI, there's a concrete attempt at changing this here: #664 |
|
For the requested order, you can keep Kong's environment decoding and make the YAML resolver return no value when that flag has a configured environment variable present. Returning Use var cli struct {
Config kong.ConfigFlag `help:"Path to the YAML configuration file."`
Debug bool `default:"false" env:"DEBUG"`
}
kong.Parse(&cli, kong.Configuration(envFirstYAML))The complete loader and runnable example use Kong v1.16.1 and kong-yaml v0.2.0. The checks reproduce the original file-over-environment behavior, then verify Presence matters here, so the loader uses |
Uh oh!
There was an error while loading. Please reload this page.
Are there any solutions to prioritize args as
Command-line flag (e.g., --debug true)
Environment variable (e.g., DEBUG=true)
Configuration file (e.g., debug: true in config.yaml)
A sensible default (e.g., false)
The current solution I have swaps env / file:
flag
file
env
default
Saw this discussion on https://danielms.site/zet/2023/kong-is-an-amazing-cli-for-go-apps/ and wanted to bring it up.
Thanks :)
All reactions