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

Function NewRootCmd

cmd/root.go:51–123  ·  view source on GitHub ↗

NewRootCmd returns a new root command

(f factory.Factory)

Source from the content-addressed store, hash-verified

49
50// NewRootCmd returns a new root command
51func NewRootCmd(f factory.Factory) *cobra.Command {
52 return &cobra.Command{
53 Use: "devspace",
54 SilenceUsage: true,
55 SilenceErrors: true,
56 Short: "Welcome to the DevSpace!",
57 PersistentPreRunE: func(cobraCmd *cobra.Command, args []string) error {
58 // don't do anything if it is a plugin command
59 if cobraCmd.Annotations != nil && cobraCmd.Annotations[plugin.PluginCommandAnnotation] == "true" {
60 return nil
61 }
62
63 log := f.GetLog()
64 if globalFlags.Silent {
65 log.SetLevel(logrus.FatalLevel)
66 } else if globalFlags.Debug {
67 log.SetLevel(logrus.DebugLevel)
68 }
69
70 ansi.DisableColors(globalFlags.NoColors)
71
72 if globalFlags.KubeConfig != "" {
73 err := os.Setenv("KUBECONFIG", globalFlags.KubeConfig)
74 if err != nil {
75 log.Errorf("Unable to set KUBECONFIG variable: %v", err)
76 }
77 }
78
79 // parse the .env file
80 envFile := env.GlobalGetEnv("DEVSPACE_ENV_FILE")
81 if envFile != "" {
82 err := godotenv.Load(envFile)
83 if err != nil && !os.IsNotExist(err) {
84 log.Warnf("Error loading .env: %v", err)
85 }
86 }
87
88 // apply extra flags
89 if !cobraCmd.DisableFlagParsing {
90 extraFlags, err := flagspkg.ApplyExtraFlags(cobraCmd, os.Args, false)
91 if err != nil {
92 log.Warnf("Error applying extra flags: %v", err)
93 } else if len(extraFlags) > 0 {
94 log.Debugf("Applying extra flags from environment: %s", strings.Join(extraFlags, " "))
95 }
96
97 if globalFlags.Silent {
98 log.SetLevel(logrus.FatalLevel)
99 } else if globalFlags.Debug {
100 log.SetLevel(logrus.DebugLevel)
101 }
102
103 // call inactivity timeout
104 if globalFlags.InactivityTimeout > 0 {
105 m, err := idle.NewIdleMonitor()
106 if err != nil {
107 log.Warnf("Error creating inactivity monitor: %v", err)
108 } else if m != nil {

Callers 2

pipelines.goFile · 0.92
BuildRootFunction · 0.70

Calls 8

NewIdleMonitorFunction · 0.92
GetLogMethod · 0.65
LoadMethod · 0.65
StartMethod · 0.65
SetLevelMethod · 0.45
ErrorfMethod · 0.45
WarnfMethod · 0.45
DebugfMethod · 0.45

Tested by

no test coverage detected