You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 10, 2023. It is now read-only.
Support set/unset environment variables through tanzu config file
- The change allows users to configure env variables as part of tanzu
config file
- Env configuration can be set using `tanzu config set env.<variable> <value>`
command
- User can unset the already configured settings with new `tanzu config
unset env.<variable>` command
- In the case of conflicts, meaning user has set environment variable
outside tanzu config file with `export FOO=bar` and as part of tanzu
config file, higer precedence is given to user configured environment
variable to allow user to override config for one off command runs
@@ -67,7 +74,7 @@ var getConfigCmd = &cobra.Command{
67
74
68
75
varsetConfigCmd=&cobra.Command{
69
76
Use: "set <path> <value>",
70
-
Short: "Set config values at the given path. path values: [unstable-versions, features.global.<feature>, features.<plugin>.<feature>]",
77
+
Short: "Set config values at the given path. path values: [unstable-versions, features.global.<feature>, features.<plugin>.<feature>, env.global.<variable>, env.<plugin>.<variable>]",
returnerrors.New("unable to parse config path parameter into three parts ["+pathParam+"] (was expecting features.<plugin>.<feature>)")
109
+
iflen(paramArray) <2 {
110
+
returnerrors.New("unable to parse config path parameter into parts ["+pathParam+"] (was expecting 'features.<plugin>.<feature>' or 'env.<env_variable>')")
104
111
}
105
112
106
-
featuresLiteral:=paramArray[0]
107
-
plugin:=paramArray[1]
108
-
key:=paramArray[2]
113
+
configLiteral:=paramArray[0]
114
+
115
+
switchconfigLiteral {
116
+
caseConfigLiteralFeatures:
117
+
returnsetFeatures(cfg, paramArray, value)
118
+
caseConfigLiteralEnv:
119
+
returnsetEnvs(cfg, paramArray, value)
120
+
default:
121
+
returnerrors.New("unsupported config path parameter ["+configLiteral+"] (was expecting 'features.<plugin>.<feature>' or 'env.<env_variable>')")
returnerrors.New("unable to parse config path parameter into three parts ["+strings.Join(paramArray, ".") +"] (was expecting 'features.<plugin>.<feature>'")
returnerrors.New("unable to parse config path parameter into two parts ["+strings.Join(paramArray, ".") +"] (was expecting 'env.<variable>'")
148
+
}
149
+
envVariable:=paramArray[1]
124
150
151
+
ifcfg.ClientOptions==nil {
152
+
cfg.ClientOptions=&configv1alpha1.ClientOptions{}
153
+
}
154
+
ifcfg.ClientOptions.Env==nil {
155
+
cfg.ClientOptions.Env=make(map[string]string)
156
+
}
157
+
158
+
cfg.ClientOptions.Env[envVariable] =value
125
159
returnnil
126
160
}
127
161
@@ -256,3 +290,76 @@ var deleteServersCmd = &cobra.Command{
256
290
returnnil
257
291
},
258
292
}
293
+
294
+
varunsetConfigCmd=&cobra.Command{
295
+
Use: "unset <path>",
296
+
Short: "Unset config values at the given path. path values: [features.global.<feature>, features.<plugin>.<feature>, env.global.<variable>, env.<plugin>.<variable>]",
returnerrors.New("unable to parse config path parameter into parts ["+pathParam+"] (was expecting 'features.<plugin>.<feature>' or 'env.<env_variable>')")
324
+
}
325
+
326
+
configLiteral:=paramArray[0]
327
+
328
+
switchconfigLiteral {
329
+
caseConfigLiteralFeatures:
330
+
returnunsetFeatures(cfg, paramArray)
331
+
caseConfigLiteralEnv:
332
+
returnunsetEnvs(cfg, paramArray)
333
+
default:
334
+
returnerrors.New("unsupported config path parameter ["+configLiteral+"] (was expecting 'features.<plugin>.<feature>' or 'env.<env_variable>')")
returnerrors.New("unable to parse config path parameter into three parts ["+strings.Join(paramArray, ".") +"] (was expecting 'features.<plugin>.<feature>'")
0 commit comments