MCPcopy Create free account
hub / github.com/crashappsec/github-analyzer / bindFlags

Function bindFlags

cmd/github-analyzer/main.go:228–246  ·  view source on GitHub ↗

bindFlags binds cobra flags to viper environment variables

(cmd *cobra.Command, v *viper.Viper)

Source from the content-addressed store, hash-verified

226
227// bindFlags binds cobra flags to viper environment variables
228func bindFlags(cmd *cobra.Command, v *viper.Viper) {
229 cmd.Flags().VisitAll(func(f *pflag.Flag) {
230 // env variables have no dashes
231 if strings.Contains(f.Name, "-") {
232 envVarSuffix := strings.ToUpper(
233 strings.ReplaceAll(f.Name, "-", "_"),
234 )
235 v.BindEnv(
236 f.Name,
237 fmt.Sprintf("%s_%s", config.ViperEnvPrefix, envVarSuffix),
238 )
239 }
240
241 if !f.Changed && v.IsSet(f.Name) {
242 val := v.Get(f.Name)
243 cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val))
244 }
245 })
246}

Callers 1

initializeConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected