MCPcopy Index your code
hub / github.com/devspace-sh/devspace / BuildRoot

Function BuildRoot

cmd/root.go:179–307  ·  view source on GitHub ↗

BuildRoot creates a new root command from the

(f factory.Factory, excludePlugins bool)

Source from the content-addressed store, hash-verified

177
178// BuildRoot creates a new root command from the
179func BuildRoot(f factory.Factory, excludePlugins bool) *cobra.Command {
180 // list plugins
181 var (
182 plugins []plugin.Metadata
183 err error
184 )
185 if !excludePlugins {
186 plugins, err = f.NewPluginManager(f.GetLog()).List()
187 if err != nil {
188 f.GetLog().Fatal(err)
189 }
190
191 plugin.SetPlugins(plugins)
192 }
193
194 // try to parse the raw config
195 var rawConfig *RawConfig
196
197 // This check is necessary to avoid process loops where a variable inside
198 // the devspace.yaml would execute another devspace command which would again
199 // load the config and execute DevSpace config parsing etc.
200 if os.Getenv(expression.DevSpaceSkipPreloadEnv) == "" {
201 rawConfig, err = parseConfig(f)
202 if err != nil {
203 f.GetLog().Debugf("error parsing raw config: %v", err)
204 } else {
205 env.GlobalGetEnv = rawConfig.GetEnv
206 }
207 }
208
209 // build the root cmd
210 rootCmd := NewRootCmd(f)
211 rootCmd.SetHelpCommand(&cobra.Command{
212 Use: "no-help",
213 Hidden: true,
214 })
215 persistentFlags := rootCmd.PersistentFlags()
216 globalFlags = flags.SetGlobalFlags(persistentFlags)
217 kill.SetStopFunction(func(message string) {
218 if message == "" {
219 os.Exit(1)
220 } else {
221 f.GetLog().Fatal(message)
222 }
223 })
224
225 rootCmd.SetUsageTemplate(`Usage:{{if .Runnable}}
226 {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
227 {{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
228
229Aliases:
230 {{.NameAndAliases}}{{end}}{{if .HasExample}}
231
232Examples:
233{{.Example}}{{end}}{{if .HasAvailableSubCommands}}
234
235Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
236 {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}

Callers 3

mainFunction · 0.92
mainFunction · 0.92
ExecuteFunction · 0.70

Calls 15

SetPluginsFunction · 0.92
SetStopFunctionFunction · 0.92
NewAddCmdFunction · 0.92
NewCleanupCmdFunction · 0.92
NewListCmdFunction · 0.92
NewRemoveCmdFunction · 0.92
NewResetCmdFunction · 0.92
NewSetCmdFunction · 0.92
NewUseCmdFunction · 0.92
NewUpdateCmdFunction · 0.92
AddPluginCommandsFunction · 0.92

Tested by

no test coverage detected