mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-18 08:36:13 +00:00
Answers #591's open question 2: CLI-only users get no update notice from soundtouch-service's periodic background check. Both binaries gain a soundtouch-cli/soundtouch-backup update-check command that does a single, on-demand GitHub Releases check via the existing pkg/service/updatecheck package. Running the command is itself the opt-in, so unlike the service there's no config flag or persisted state. pkg/service/updatecheck.Checker was already designed decoupled from handlers.Server/main.go specifically so other binaries could import it directly; this is that follow-through.
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gesellix/bose-soundtouch/pkg/service/updatecheck"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// updateCheckRepo is the GitHub repo checked for newer releases, matching
|
|
// soundtouch-service's periodic background check (#591,
|
|
// _/i591/design-update-check.md).
|
|
const updateCheckRepo = "gesellix/Bose-SoundTouch"
|
|
|
|
// updateCheckCommand assembles the on-demand `soundtouch-cli update-check`
|
|
// command, the CLI-side answer to that design doc's open question 2
|
|
// (CLI-only users get no update notice from the service's background
|
|
// checker). Unlike the service's opt-in periodic check, running this
|
|
// command *is* the opt-in: no config flag, no persisted state, just one
|
|
// GitHub API request each time it's invoked.
|
|
func updateCheckCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "update-check",
|
|
Usage: "Check GitHub for a newer soundtouch-cli release",
|
|
Action: runUpdateCheck,
|
|
}
|
|
}
|
|
|
|
func runUpdateCheck(c *cli.Context) error {
|
|
checker := updatecheck.NewChecker(nil, updateCheckRepo, version)
|
|
|
|
result, err := checker.CheckNow(c.Context)
|
|
if err != nil {
|
|
return fmt.Errorf("update check failed: %w", err)
|
|
}
|
|
|
|
printUpdateCheckResult(result)
|
|
|
|
return nil
|
|
}
|
|
|
|
func printUpdateCheckResult(result updatecheck.Result) {
|
|
if result.LatestVersion == "" {
|
|
fmt.Printf("Running %s, not a released version, skipping comparison.\n", result.CurrentVersion)
|
|
return
|
|
}
|
|
|
|
if result.Available {
|
|
fmt.Printf("A newer version is available: %s (you're on %s)\n", result.LatestVersion, result.CurrentVersion)
|
|
fmt.Println(result.ReleaseURL)
|
|
|
|
return
|
|
}
|
|
|
|
fmt.Printf("You're on the latest version (%s).\n", result.CurrentVersion)
|
|
}
|