BuildRoot creates a new root command from the
(f factory.Factory, excludePlugins bool)
| 177 | |
| 178 | // BuildRoot creates a new root command from the |
| 179 | func 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 | |
| 229 | Aliases: |
| 230 | {{.NameAndAliases}}{{end}}{{if .HasExample}} |
| 231 | |
| 232 | Examples: |
| 233 | {{.Example}}{{end}}{{if .HasAvailableSubCommands}} |
| 234 | |
| 235 | Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}} |
| 236 | {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} |
no test coverage detected