refactor(upgrade): allow setting from CLI

This commit is contained in:
Jan De Dobbeleer 2024-10-11 21:51:14 +02:00 committed by Jan De Dobbeleer
parent 42b776be36
commit 87404454a4
4 changed files with 213 additions and 187 deletions

View file

@ -6,7 +6,6 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/cache" "github.com/jandedobbeleer/oh-my-posh/src/cache"
"github.com/jandedobbeleer/oh-my-posh/src/config" "github.com/jandedobbeleer/oh-my-posh/src/config"
"github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/upgrade"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -19,8 +18,8 @@ This command is used to %s one of the following features:
- notice` - notice`
toggleArgs = []string{ toggleArgs = []string{
"notice", config.UPGRADENOTICE,
"autoupgrade", config.AUTOUPGRADE,
} }
) )
@ -55,22 +54,24 @@ func toggleFeature(cmd *cobra.Command, feature string, enable bool) {
env.Init() env.Init()
defer env.Close() defer env.Close()
var key string
switch feature { switch feature {
case "notice": case "notice":
if enable { key = config.UPGRADENOTICE
env.Cache().Delete(upgrade.CACHEKEY)
return
}
env.Cache().Set(upgrade.CACHEKEY, "disabled", cache.INFINITE)
case "autoupgrade": case "autoupgrade":
if enable { key = config.AUTOUPGRADE
env.Cache().Set(config.AUTOUPGRADE, "true", cache.INFINITE) }
if len(key) == 0 {
_ = cmd.Help()
return return
} }
env.Cache().Delete(config.AUTOUPGRADE) if enable {
default: env.Cache().Set(key, "true", cache.INFINITE)
_ = cmd.Help() return
} }
env.Cache().Delete(key)
} }

View file

@ -14,7 +14,8 @@ const (
YAML string = "yaml" YAML string = "yaml"
TOML string = "toml" TOML string = "toml"
AUTOUPGRADE = "auto_upgrade" AUTOUPGRADE = "autoupgrade"
UPGRADENOTICE = "upgradenotice"
Version = 2 Version = 2
) )
@ -103,7 +104,12 @@ func (cfg *Config) Features() shell.Features {
autoUpgrade = true autoUpgrade = true
} }
if cfg.UpgradeNotice && !autoUpgrade { upgradeNotice := cfg.UpgradeNotice
if _, OK := cfg.env.Cache().Get(UPGRADENOTICE); OK {
upgradeNotice = true
}
if upgradeNotice && !autoUpgrade {
feats = append(feats, shell.Notice) feats = append(feats, shell.Notice)
} }

View file

@ -4,6 +4,9 @@ title: Upgrade
sidebar_label: ♻️ Upgrade sidebar_label: ♻️ Upgrade
--- ---
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
## Manual ## Manual
While you can always follow the upgrade steps listed under the installation section, While you can always follow the upgrade steps listed under the installation section,
@ -13,11 +16,24 @@ you can also use the `upgrade` command to update Oh My Posh to the latest versio
oh-my-posh upgrade oh-my-posh upgrade
``` ```
## Automatic ## Automated
In case you want to enable auto-upgrades, you need to edit your configuration file. <Tabs
If you don't yet have a configuration file, have a look at the [customize page][customize] to get started, defaultValue="cli"
afterwards you can add the following line to your configuration file: groupId="sample"
values={[
{ label: 'CLI', value: 'cli', },
{ label: 'Configuration', value: 'config', },
]
}>
<TabItem value="cli">
```powershell
oh-my-posh enable autoupgrade
```
</TabItem>
<TabItem value="config">
import Config from "@site/src/components/Config.js"; import Config from "@site/src/components/Config.js";
@ -27,4 +43,7 @@ import Config from "@site/src/components/Config.js";
}} }}
/> />
</TabItem>
</Tabs>
[customize]: /docs/installation/customize#custom-configuration [customize]: /docs/installation/customize#custom-configuration

View file

@ -9,8 +9,8 @@ code[class*="language-"],
pre[class*="language-"] { pre[class*="language-"] {
color: #e0def4; color: #e0def4;
background: #232136; background: #232136;
font-family: "Cartograph CF", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", font-family: "Cartograph CF", ui-monospace, SFMono-Regular, Menlo, Monaco,
monospace; Consolas, "Liberation Mono", "Courier New", monospace;
text-align: left; text-align: left;
white-space: pre; white-space: pre;
word-spacing: normal; word-spacing: normal;