MCPcopy
hub / github.com/helm/helm / newRootCmdWithConfig

Function newRootCmdWithConfig

pkg/cmd/root.go:150–312  ·  view source on GitHub ↗
(actionConfig *action.Configuration, out io.Writer, args []string, logSetup func(bool))

Source from the content-addressed store, hash-verified

148}
149
150func newRootCmdWithConfig(actionConfig *action.Configuration, out io.Writer, args []string, logSetup func(bool)) (*cobra.Command, error) {
151 cmd := &cobra.Command{
152 Use: "helm",
153 Short: "The Helm package manager for Kubernetes.",
154 Long: globalUsage,
155 SilenceUsage: true,
156 PersistentPreRun: func(_ *cobra.Command, _ []string) {
157 if err := startProfiling(); err != nil {
158 log.Printf("Warning: Failed to start profiling: %v", err)
159 }
160 },
161 PersistentPostRun: func(_ *cobra.Command, _ []string) {
162 if err := stopProfiling(); err != nil {
163 log.Printf("Warning: Failed to stop profiling: %v", err)
164 }
165 },
166 }
167
168 flags := cmd.PersistentFlags()
169
170 settings.AddFlags(flags)
171 addKlogFlags(flags)
172
173 // We can safely ignore any errors that flags.Parse encounters since
174 // those errors will be caught later during the call to cmd.Execution.
175 // This call is required to gather configuration information prior to
176 // execution.
177 flags.ParseErrorsAllowlist.UnknownFlags = true
178 flags.Parse(args)
179
180 logSetup(settings.Debug)
181
182 // newRootCmdWithConfig is only called from NewRootCmd. NewRootCmd sets up
183 // NewConfiguration without a custom logger. So, the slog default is used. logSetup
184 // can change the default logger to the one in the logger package. This happens for
185 // the Helm client. This means the actionConfig logger is different from the slog
186 // default logger. If they are different we sync the actionConfig logger to the slog
187 // current default one.
188 if actionConfig.Logger() != slog.Default() {
189 actionConfig.SetLogger(slog.Default().Handler())
190 }
191
192 // Validate color mode setting
193 switch settings.ColorMode {
194 case "never", "auto", "always":
195 // Valid color mode
196 default:
197 return nil, fmt.Errorf("invalid color mode %q: must be one of: never, auto, always", settings.ColorMode)
198 }
199
200 // Configure color output based on ColorMode setting
201 configureColorOutput(settings)
202
203 // Setup shell completion for the color flag
204 _ = cmd.RegisterFlagCompletionFunc("color", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
205 return []string{"never", "auto", "always"}, cobra.ShellCompDirectiveNoFileComp
206 })
207

Callers 3

NewRootCmdFunction · 0.85
TestRootCmdLoggerFunction · 0.85

Calls 15

startProfilingFunction · 0.85
stopProfilingFunction · 0.85
addKlogFlagsFunction · 0.85
configureColorOutputFunction · 0.85
newDefaultRegistryClientFunction · 0.85
newCreateCmdFunction · 0.85
newDependencyCmdFunction · 0.85
newPullCmdFunction · 0.85
newShowCmdFunction · 0.85
newLintCmdFunction · 0.85
newPackageCmdFunction · 0.85
newRepoCmdFunction · 0.85

Tested by 2

TestRootCmdLoggerFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…