feat(upgrade): configure using cli

resolves #5734
This commit is contained in:
Jan De Dobbeleer 2024-10-11 20:54:15 +02:00 committed by Jan De Dobbeleer
parent 4be054dd4b
commit 9fbc61561d
3 changed files with 21 additions and 4 deletions

View file

@ -3,6 +3,8 @@ package cli
import (
"fmt"
"github.com/jandedobbeleer/oh-my-posh/src/cache"
"github.com/jandedobbeleer/oh-my-posh/src/config"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/upgrade"
@ -18,6 +20,7 @@ This command is used to %s one of the following features:
- notice`
toggleArgs = []string{
"notice",
"autoupgrade",
}
)
@ -59,7 +62,14 @@ func toggleFeature(cmd *cobra.Command, feature string, enable bool) {
return
}
env.Cache().Set(upgrade.CACHEKEY, "disabled", -1)
env.Cache().Set(upgrade.CACHEKEY, "disabled", cache.INFINITE)
case "autoupgrade":
if enable {
env.Cache().Set(config.AUTOUPGRADE, "true", cache.INFINITE)
return
}
env.Cache().Delete(config.AUTOUPGRADE)
default:
_ = cmd.Help()
}

View file

@ -14,6 +14,8 @@ const (
YAML string = "yaml"
TOML string = "toml"
AUTOUPGRADE = "auto_upgrade"
Version = 2
)
@ -103,11 +105,16 @@ func (cfg *Config) Features() shell.Features {
feats = append(feats, shell.FTCSMarks)
}
if !cfg.AutoUpgrade && !cfg.DisableNotice {
autoUpgrade := cfg.AutoUpgrade
if _, OK := cfg.env.Cache().Get(AUTOUPGRADE); OK {
autoUpgrade = true
}
if !autoUpgrade && !cfg.DisableNotice {
feats = append(feats, shell.Notice)
}
if cfg.AutoUpgrade {
if autoUpgrade {
feats = append(feats, shell.Upgrade)
}

View file

@ -38,7 +38,7 @@ const (
A new release of Oh My Posh is available: %s %s
To upgrade, run: 'oh-my-posh upgrade'
To enable automated upgrades, set 'auto_upgrade' to 'true' in your configuration.
To enable automated upgrades, run: 'oh-my-posh enable autoupgrade'.
`
)