triggerUpdate runs `devbox version -v` and triggers an update since a new version is available. It parses the output to get the new launcher and devbox versions.
(stdErr io.Writer)
| 172 | // version is available. It parses the output to get the new launcher and |
| 173 | // devbox versions. |
| 174 | func triggerUpdate(stdErr io.Writer) (*updatedVersions, error) { |
| 175 | exePath := os.Getenv(envir.LauncherPath) |
| 176 | if exePath == "" { |
| 177 | ux.Fwarningf(stdErr, "expected LAUNCHER_PATH to be set. Defaulting to \"devbox\".") |
| 178 | exePath = "devbox" |
| 179 | } |
| 180 | |
| 181 | // TODO savil. Add a --json flag to devbox version and parse the output as JSON |
| 182 | cmd := exec.Command(exePath, "version", "-v") |
| 183 | |
| 184 | buf := new(bytes.Buffer) |
| 185 | cmd.Stdout = io.MultiWriter(stdErr, buf) |
| 186 | cmd.Stderr = stdErr |
| 187 | if err := cmd.Run(); err != nil { |
| 188 | return nil, errors.WithStack(err) |
| 189 | } |
| 190 | |
| 191 | // Parse the output to ascertain the new devbox and launcher versions |
| 192 | updated := &updatedVersions{} |
| 193 | for _, line := range strings.Split(buf.String(), "\n") { |
| 194 | if strings.HasPrefix(line, "Version:") { |
| 195 | updated.devboxVersion = strings.TrimSpace(strings.TrimPrefix(line, "Version:")) |
| 196 | } |
| 197 | |
| 198 | if strings.HasPrefix(line, "Launcher:") { |
| 199 | updated.launcherVersion = strings.TrimSpace(strings.TrimPrefix(line, "Launcher:")) |
| 200 | } |
| 201 | } |
| 202 | return updated, nil |
| 203 | } |
| 204 | |
| 205 | func printSuccessMessage(w io.Writer, toolName, oldVersion, newVersion string) { |
| 206 | var msg string |
no test coverage detected