MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / RunUpdate

Function RunUpdate

internal/cmd/update.go:17–44  ·  view source on GitHub ↗

RunUpdate downloads and installs the latest version of Chief.

(opts UpdateOptions)

Source from the content-addressed store, hash-verified

15
16// RunUpdate downloads and installs the latest version of Chief.
17func 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.

Callers 3

runUpdateFunction · 0.92
TestRunUpdate_APIErrorFunction · 0.85

Calls 2

CheckForUpdateFunction · 0.92
PerformUpdateFunction · 0.92

Tested by 2

TestRunUpdate_APIErrorFunction · 0.68