mirror of
https://github.com/rancher/k3k.git
synced 2026-08-18 03:46:31 +00:00
Use K3K_ env prefix for k3kcli viper binding
This commit is contained in:
+3
-3
@@ -92,10 +92,10 @@ func CobraFlagNamespace(appCtx *AppContext, flag *pflag.FlagSet) {
|
||||
}
|
||||
|
||||
func InitializeConfig(cmd *cobra.Command) {
|
||||
// Use a "K3KCLI" prefix so that only namespaced environment variables (e.g.
|
||||
// K3KCLI_VERSION) bind to flags. Without a prefix, common environment variables
|
||||
// Use a "K3K" prefix so that only namespaced environment variables (e.g.
|
||||
// K3K_VERSION) bind to flags. Without a prefix, common environment variables
|
||||
// such as VERSION, MODE or TOKEN would silently override the matching CLI flags.
|
||||
viper.SetEnvPrefix("K3KCLI")
|
||||
viper.SetEnvPrefix("K3K")
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
|
||||
viper.AutomaticEnv()
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ func Test_InitializeConfig_envPrefix(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "prefixed env binds to flag",
|
||||
envName: "K3KCLI_VERSION",
|
||||
envName: "K3K_VERSION",
|
||||
want: "1h",
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user