checkDdevVersionAndOptInInstrumentation() reads global config and checks to see if current version is different from the last saved version. If it is, prompt to request anon DDEV usage stats and update the info.
(skipConfirmation bool)
| 188 | // from the last saved version. If it is, prompt to request anon DDEV usage stats |
| 189 | // and update the info. |
| 190 | func checkDdevVersionAndOptInInstrumentation(skipConfirmation bool) error { |
| 191 | if !output.JSONOutput && semver.Compare(versionconstants.DdevVersion, globalconfig.DdevGlobalConfig.LastStartedVersion) > 0 && !globalconfig.DdevGlobalConfig.InstrumentationOptIn && !globalconfig.DdevNoInstrumentation && !skipConfirmation { |
| 192 | allowStats := util.Confirm("It looks like you have a new DDEV release.\nMay we send anonymous DDEV usage statistics and errors?\nTo know what we will see please take a look at\nhttps://docs.ddev.com/en/stable/users/usage/diagnostics/#opt-in-usage-information\nPermission to beam up?") |
| 193 | if allowStats { |
| 194 | globalconfig.DdevGlobalConfig.InstrumentationOptIn = true |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | if globalconfig.DdevGlobalConfig.LastStartedVersion != versionconstants.DdevVersion && !skipConfirmation { |
| 199 | // If they have a new version (but not first-timer) then prompt to poweroff |
| 200 | if globalconfig.DdevGlobalConfig.LastStartedVersion != "v0.0" { |
| 201 | // Check if any containers are running before prompting for poweroff |
| 202 | activeProjects := ddevapp.GetActiveProjects() |
| 203 | sshAgent, _ := dockerutil.FindContainerByName("ddev-ssh-agent") |
| 204 | router, _ := dockerutil.FindContainerByName("ddev-router") |
| 205 | |
| 206 | // Only prompt for poweroff if there are active containers |
| 207 | // If all are nil/empty, the user has effectively already done a poweroff |
| 208 | if len(activeProjects) > 0 || sshAgent != nil || router != nil { |
| 209 | output.UserOut.Printf("You seem to have a new DDEV version (new=%s, old=%s)", versionconstants.DdevVersion, globalconfig.DdevGlobalConfig.LastStartedVersion) |
| 210 | okPoweroff := util.Confirm("During an upgrade it's important to `ddev poweroff`.\nMay I do `ddev poweroff` before continuing?\nThis does no harm and loses no data.") |
| 211 | if okPoweroff { |
| 212 | ddevapp.PowerOff() |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | // If they have a new version write the new version into last-started |
| 218 | globalconfig.DdevGlobalConfig.LastStartedVersion = versionconstants.DdevVersion |
| 219 | err := globalconfig.WriteGlobalConfig(globalconfig.DdevGlobalConfig) |
| 220 | if err != nil { |
| 221 | return err |
| 222 | } |
| 223 | |
| 224 | return nil |
| 225 | } |
| 226 | |
| 227 | return nil |
| 228 | } |
| 229 | |
| 230 | // addCommandIfNotExists adds cmdToAdd to rootCmd if a command with the same name does not already exist. |
| 231 | func addCommandIfNotExists(rootCmd *cobra.Command, cmdToAdd *cobra.Command) { |
no test coverage detected