MCPcopy Create free account
hub / github.com/ddev/ddev / init

Function init

cmd/ddev/cmd/root.go:147–185  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

145}
146
147func init() {
148 // This flag represents the output.JSONOutput variable, and parsed very early in pkg/output/output_setup.go
149 RootCmd.PersistentFlags().BoolP("json-output", "j", false, "If true, user-oriented output will be in JSON format.")
150 RootCmd.PersistentFlags().BoolVarP(&ddevapp.SkipHooks, "skip-hooks", "", false, "If true, any hook normally run by the command will be skipped.")
151
152 // Override Cobra version template for JSON output
153 if output.JSONOutput {
154 userOutFunc := util.CaptureUserOut()
155 output.UserOut.WithField("raw", map[string]string{"version": RootCmd.Version}).Printf("%s version %s", RootCmd.DisplayName(), RootCmd.Version)
156 RootCmd.SetVersionTemplate(userOutFunc())
157 }
158
159 // Determine if Docker is running by getting the version.
160 // This helps to prevent a user from seeing the Cobra error: "Error: unknown command "<custom command>" for ddev"
161 _, err := dockerutil.GetDockerVersion()
162
163 if err != nil && !dockerutil.CanRunWithoutDocker() {
164 util.Failed("Docker error: %v\nFor help go to: https://docs.ddev.com/en/stable/users/install/docker-installation/#troubleshooting-docker", err)
165 }
166
167 // Populate custom/script commands so they're visible.
168 // We really don't want ~/.ddev or .ddev/homeadditions to have root ownership, breaks things.
169 if os.Geteuid() != 0 {
170 err := ddevapp.PopulateExamplesCommandsHomeadditions("")
171 if err != nil {
172 util.Warning("populateExamplesAndCommands() failed: %v", err)
173 }
174
175 err = addCustomCommands(RootCmd)
176 if err != nil {
177 util.Warning("Adding custom/shell commands failed: %v", err)
178 }
179
180 // Add fallback nvm command which notifies user that nvm has been removed.
181 addCommandIfNotExists(RootCmd, NvmCmd)
182 }
183
184 setHelpFunc(RootCmd)
185}
186
187// checkDdevVersionAndOptInInstrumentation() reads global config and checks to see if current version is different
188// from the last saved version. If it is, prompt to request anon DDEV usage stats

Callers

nothing calls this directly

Calls 9

CaptureUserOutFunction · 0.92
GetDockerVersionFunction · 0.92
CanRunWithoutDockerFunction · 0.92
FailedFunction · 0.92
WarningFunction · 0.92
addCustomCommandsFunction · 0.85
addCommandIfNotExistsFunction · 0.85
setHelpFuncFunction · 0.85

Tested by

no test coverage detected