Upgrade notice
Currently, the upgrade notice works only for GitHub releases.
The upgrade notice is disabled by default. You can easily enable it based on your usage:
-
Printer
p := printer.New( printer.WithUpgradeNotice("mszostok", "codeowners-validator", upgradeOpts...), )
It prints the notice to the standard error channel (
stderr
). As a result, output processing, such as executing<cli> -ojson | jq .gitCommit
, works properly even if the upgrade notice is displayed.
-
Cobra CLI
extension.NewVersionCobraCmd( // 2. Explicit turn on upgrade notice extension.WithUpgradeNotice("mszostok", "codeowners-validator"), ),
It prints the notice on standard error channel (
stderr
). As a result, output processing, such as executing<cli> version -ojson | jq .gitCommit
, works properly even if the upgrade notice is displayed.
-
Standalone
notice := upgrade.NewGitHubDetector("mszostok", "codeowners-validator") err := notice.PrintIfFoundGreater(os.Stderr, "0.5.4")
Once enabled, each execution checks for new releases. If a newer version has been found, it displays an upgrade notice for each output format to the standard
error channel (stderr
).
You can customize almost all aspects of the upgrade check:
-
Set maximum duration time for the update check operation (default:
10s
):upgrade.WithUpdateCheckTimeout(30*time.Second)
-
Set a custom function to compare release versions (default: SemVer check):
upgrade.WithIsVersionGreater(func(current string, new string) bool { //.. compare current with new .. return true })
-
Set the minimum time that must elapse before checking for a new release (default:
0min
):upgrade.WithMinElapseTimeForRecheck(time.Second)
-
Change formatting:
upgrade.WithFormatting(&style.Formatting{ Header: style.Header{}, Key: style.Key{}, Val: style.Val{}, Date: style.Date{}, })
-
Change layout:
upgrade.WithLayout(&style.Layout{ GoTemplate: forBoxLayoutGoTpl, })
-
Change both formatting and layout:
upgrade.WithStyle(&style.Config{})
-
Define a custom renderer:
upgrade.WithRenderer(func(in *upgrade.Info, isSmartTerminal bool) (string, error) { return fmt.Sprintf(` Version %q New Version %q `, in.Version, in.NewVersion), nil })
-
Add a post-render hook:
upgrade.WithPostRenderHook(func(body string, isSmartTerminal bool) (string, error) { return body + "\ncustom footer", nil })
-
Change config directory where cache is stored:
upgrade.WithConfigDir("~/.config"),
-
Change file name for state file:
upgrade.WithStateFileName("foo-upgrade-state.yaml")