MCPcopy Create free account
hub / github.com/FairwindsOps/pluto / bindFlags

Function bindFlags

cmd/root.go:133–153  ·  view source on GitHub ↗
(cmd *cobra.Command, v *viper.Viper)

Source from the content-addressed store, hash-verified

131}
132
133func bindFlags(cmd *cobra.Command, v *viper.Viper) {
134 cmd.Flags().VisitAll(func(f *pflag.Flag) {
135 if strings.Contains(f.Name, "-") {
136 envVarSuffix := strings.ToUpper(strings.ReplaceAll(f.Name, "-", "_"))
137 err := v.BindEnv(f.Name, fmt.Sprintf("%s_%s", envPrefix, envVarSuffix))
138 if err != nil {
139 klog.Errorf("error binding flag %s to env var %s_%s: %v", f.Name, envPrefix, envVarSuffix, err)
140 return
141 }
142 }
143
144 if !f.Changed && v.IsSet(f.Name) {
145 val := v.Get(f.Name)
146 err := cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val))
147 if err != nil {
148 klog.Errorf("error setting flag %s to %v: %v", f.Name, val, err)
149 return
150 }
151 }
152 })
153}
154
155var rootCmd = &cobra.Command{
156 Use: "pluto",

Callers 1

initializeConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…