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

Function Execute

cmd/root.go:129–176  ·  view source on GitHub ↗

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

()

Source from the content-addressed store, hash-verified

127// Execute adds all child commands to the root command and sets flags appropriately.
128// This is called by main.main(). It only needs to happen once to the rootCmd.
129func Execute() {
130 interrupt.Global.Start()
131
132 // disable klog
133 disableKlog()
134
135 // create a new factory
136 f := factory.DefaultFactory()
137
138 // build the root command
139 rootCmd := BuildRoot(f, false)
140
141 // set version for --version flag
142 rootCmd.Version = upgrade.GetVersion()
143
144 // before hooks
145 pluginErr := hook.ExecuteHooks(nil, nil, "root", "root.beforeExecute", "command:before:execute")
146 if pluginErr != nil {
147 f.GetLog().Fatalf("%+v", pluginErr)
148 }
149
150 // execute command
151 err := rootCmd.Execute()
152
153 // after hooks
154 pluginErr = hook.ExecuteHooks(nil, map[string]interface{}{"error": err}, "root.afterExecute", "command:after:execute")
155 if err != nil {
156 // Check if return code error
157 retCode, ok := errors.Cause(err).(*exit.ReturnCodeError)
158 if ok {
159 os.Exit(retCode.ExitCode)
160 }
161
162 // error hooks
163 pluginErr := hook.ExecuteHooks(nil, map[string]interface{}{"error": err}, "root.errorExecution", "command:error")
164 if pluginErr != nil {
165 f.GetLog().Fatalf("%+v", pluginErr)
166 }
167
168 if globalFlags.Debug {
169 f.GetLog().Fatalf("%+v", err)
170 } else {
171 f.GetLog().Fatal(err)
172 }
173 } else if pluginErr != nil {
174 f.GetLog().Fatalf("%+v", pluginErr)
175 }
176}
177
178// BuildRoot creates a new root command from the
179func BuildRoot(f factory.Factory, excludePlugins bool) *cobra.Command {

Callers 1

mainFunction · 0.92

Calls 10

DefaultFactoryFunction · 0.92
GetVersionFunction · 0.92
ExecuteHooksFunction · 0.92
disableKlogFunction · 0.85
BuildRootFunction · 0.70
StartMethod · 0.65
GetLogMethod · 0.65
ExecuteMethod · 0.65
FatalfMethod · 0.45
FatalMethod · 0.45

Tested by

no test coverage detected