Align update command UX/state handling with AX conventions
This commit is contained in:
parent
ee154a2c15
commit
333857cb3a
3 changed files with 15 additions and 18 deletions
16
cmd.go
16
cmd.go
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"forge.lthn.ai/core/cli/pkg/cli"
|
"forge.lthn.ai/core/cli/pkg/cli"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
@ -47,7 +48,7 @@ Examples:
|
||||||
|
|
||||||
updateCmd.PersistentFlags().StringVar(&updateChannel, "channel", "stable", "Release channel: stable, beta, alpha, or dev")
|
updateCmd.PersistentFlags().StringVar(&updateChannel, "channel", "stable", "Release channel: stable, beta, alpha, or dev")
|
||||||
updateCmd.PersistentFlags().BoolVar(&updateForce, "force", false, "Force update even if already on latest version")
|
updateCmd.PersistentFlags().BoolVar(&updateForce, "force", false, "Force update even if already on latest version")
|
||||||
updateCmd.Flags().BoolVar(&updateCheck, "check", false, "Only check for updates, don't apply")
|
updateCmd.Flags().BoolVar(&updateCheck, "check", false, "Only check for updates, do not apply")
|
||||||
updateCmd.Flags().IntVar(&updateWatchPID, "watch-pid", 0, "Internal: watch for parent PID to die then restart")
|
updateCmd.Flags().IntVar(&updateWatchPID, "watch-pid", 0, "Internal: watch for parent PID to die then restart")
|
||||||
_ = updateCmd.Flags().MarkHidden("watch-pid")
|
_ = updateCmd.Flags().MarkHidden("watch-pid")
|
||||||
|
|
||||||
|
|
@ -55,7 +56,9 @@ Examples:
|
||||||
Use: "check",
|
Use: "check",
|
||||||
Short: "Check for available updates",
|
Short: "Check for available updates",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
previousCheck := updateCheck
|
||||||
updateCheck = true
|
updateCheck = true
|
||||||
|
defer func() { updateCheck = previousCheck }()
|
||||||
return runUpdate(cmd, args)
|
return runUpdate(cmd, args)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -70,24 +73,25 @@ func runUpdate(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
currentVersion := cli.AppVersion
|
currentVersion := cli.AppVersion
|
||||||
|
normalizedChannel := strings.TrimSpace(strings.ToLower(updateChannel))
|
||||||
|
|
||||||
cli.Print("%s %s\n", cli.DimStyle.Render("Current version:"), cli.ValueStyle.Render(currentVersion))
|
cli.Print("%s %s\n", cli.DimStyle.Render("Current version:"), cli.ValueStyle.Render(currentVersion))
|
||||||
cli.Print("%s %s/%s\n", cli.DimStyle.Render("Platform:"), runtime.GOOS, runtime.GOARCH)
|
cli.Print("%s %s/%s\n", cli.DimStyle.Render("Platform:"), runtime.GOOS, runtime.GOARCH)
|
||||||
cli.Print("%s %s\n\n", cli.DimStyle.Render("Channel:"), updateChannel)
|
cli.Print("%s %s\n\n", cli.DimStyle.Render("Channel:"), normalizedChannel)
|
||||||
|
|
||||||
// Handle dev channel specially - it's a prerelease tag, not a semver channel
|
// Handle dev channel specially - it's a prerelease tag, not a semver channel
|
||||||
if updateChannel == "dev" {
|
if normalizedChannel == "dev" {
|
||||||
return handleDevUpdate(currentVersion)
|
return handleDevUpdate(currentVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for newer version
|
// Check for newer version
|
||||||
release, updateAvailable, err := CheckForNewerVersion(repoOwner, repoName, updateChannel, true)
|
release, updateAvailable, err := CheckForNewerVersion(repoOwner, repoName, normalizedChannel, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.Wrap(err, "failed to check for updates")
|
return cli.Wrap(err, "failed to check for updates")
|
||||||
}
|
}
|
||||||
|
|
||||||
if release == nil {
|
if release == nil {
|
||||||
cli.Print("%s No releases found in %s channel\n", cli.WarningStyle.Render("!"), updateChannel)
|
cli.Print("%s No releases found in %s channel\n", cli.WarningStyle.Render("!"), normalizedChannel)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,7 +144,7 @@ func handleDevUpdate(currentVersion string) error {
|
||||||
client := NewGithubClient()
|
client := NewGithubClient()
|
||||||
|
|
||||||
// Fetch the dev release directly by tag
|
// Fetch the dev release directly by tag
|
||||||
release, err := client.GetLatestRelease(context.TODO(), repoOwner, repoName, "beta")
|
release, err := client.GetLatestRelease(context.Background(), repoOwner, repoName, "beta")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Try fetching the "dev" tag directly
|
// Try fetching the "dev" tag directly
|
||||||
return handleDevTagUpdate(currentVersion)
|
return handleDevTagUpdate(currentVersion)
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,7 @@ The `CheckOnStartup` field can take one of the following values:
|
||||||
|
|
||||||
If you are using the example CLI provided in `cmd/updater`, the following flags are available:
|
If you are using the example CLI provided in `cmd/updater`, the following flags are available:
|
||||||
|
|
||||||
* `--check-update`: Check for new updates without applying them.
|
* `--check`: Check for new updates without applying them.
|
||||||
* `--do-update`: Perform an update if available.
|
* `--channel`: Set the update channel (e.g., stable, beta, alpha). Defaults to `stable`.
|
||||||
* `--channel`: Set the update channel (e.g., stable, beta, alpha). If not set, it's determined from the current version tag.
|
* `--force`: Force update even when already on latest.
|
||||||
* `--force-semver-prefix`: Force 'v' prefix on semver tags (default `true`).
|
* `--watch-pid`: Internal flag used during restart after update.
|
||||||
* `--release-url-format`: A URL format for release assets.
|
|
||||||
* `--pull-request`: Update to a specific pull request (integer ID).
|
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,7 @@ var DoUpdate = func(url string) error {
|
||||||
return coreerr.E("DoUpdate", "failed to download update", err)
|
return coreerr.E("DoUpdate", "failed to download update", err)
|
||||||
}
|
}
|
||||||
defer func(Body io.ReadCloser) {
|
defer func(Body io.ReadCloser) {
|
||||||
err := Body.Close()
|
_ = Body.Close()
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("failed to close response body: %v\n", err)
|
|
||||||
}
|
|
||||||
}(resp.Body)
|
}(resp.Body)
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
|
@ -59,8 +56,6 @@ var DoUpdate = func(url string) error {
|
||||||
}
|
}
|
||||||
return coreerr.E("DoUpdate", "update failed", err)
|
return coreerr.E("DoUpdate", "update failed", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Update applied successfully.")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue