RunUpdate downloads and installs the latest version of Chief.
(opts UpdateOptions)
| 15 | |
| 16 | // RunUpdate downloads and installs the latest version of Chief. |
| 17 | func RunUpdate(opts UpdateOptions) error { |
| 18 | fmt.Println("Checking for updates...") |
| 19 | |
| 20 | // First check if an update is available |
| 21 | result, err := update.CheckForUpdate(opts.Version, update.Options{ |
| 22 | ReleasesURL: opts.ReleasesURL, |
| 23 | }) |
| 24 | if err != nil { |
| 25 | return fmt.Errorf("checking for updates: %w", err) |
| 26 | } |
| 27 | |
| 28 | if !result.UpdateAvailable { |
| 29 | fmt.Printf("Already on latest version (v%s).\n", result.CurrentVersion) |
| 30 | return nil |
| 31 | } |
| 32 | |
| 33 | fmt.Printf("Downloading v%s (you have v%s)...\n", result.LatestVersion, result.CurrentVersion) |
| 34 | |
| 35 | // Perform the update |
| 36 | if _, err := update.PerformUpdate(opts.Version, update.Options{ |
| 37 | ReleasesURL: opts.ReleasesURL, |
| 38 | }); err != nil { |
| 39 | return err |
| 40 | } |
| 41 | |
| 42 | fmt.Printf("Updated to v%s. Restart 'chief serve' to apply.\n", result.LatestVersion) |
| 43 | return nil |
| 44 | } |
| 45 | |
| 46 | // CheckVersionOnStartup performs a non-blocking version check and prints a message if an update is available. |
| 47 | // This is called on startup for interactive CLI commands. |