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

@ -5,12 +5,12 @@
* Ported for PrismJS by fvrests [@fvrests] * Ported for PrismJS by fvrests [@fvrests]
*/ */
code[class*="language-"], 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;
@ -30,159 +30,159 @@ pre[class*="language-"] {
@media print { @media print {
text-shadow: none; text-shadow: none;
} }
} }
/* Selection */ /* Selection */
code[class*="language-"]::-moz-selection, code[class*="language-"]::-moz-selection,
pre[class*="language-"]::-moz-selection, pre[class*="language-"]::-moz-selection,
code[class*="language-"] ::-moz-selection, code[class*="language-"] ::-moz-selection,
pre[class*="language-"] ::-moz-selection { pre[class*="language-"] ::-moz-selection {
background: #44415a; background: #44415a;
} }
code[class*="language-"]::selection, code[class*="language-"]::selection,
pre[class*="language-"]::selection, pre[class*="language-"]::selection,
code[class*="language-"] ::selection, code[class*="language-"] ::selection,
pre[class*="language-"] ::selection { pre[class*="language-"] ::selection {
background: #44415a; background: #44415a;
} }
/* Code (block & inline) */ /* Code (block & inline) */
:not(pre) > code[class*="language-"], :not(pre) > code[class*="language-"],
pre[class*="language-"] { pre[class*="language-"] {
color: #e0def4; color: #e0def4;
background: #232136; background: #232136;
} }
/* Code blocks */ /* Code blocks */
pre[class*="language-"] { pre[class*="language-"] {
padding: 1em; padding: 1em;
margin: 0.5em 0; margin: 0.5em 0;
overflow: auto; overflow: auto;
} }
/* Inline code */ /* Inline code */
:not(pre) > code[class*="language-"] { :not(pre) > code[class*="language-"] {
padding: 0.1em; padding: 0.1em;
border-radius: 0.3em; border-radius: 0.3em;
white-space: normal; white-space: normal;
color: #e0def4; color: #e0def4;
background: #232136; background: #232136;
} }
/* Text style & opacity */ /* Text style & opacity */
.token.entity { .token.entity {
cursor: help; cursor: help;
} }
.token.important, .token.important,
.token.bold { .token.bold {
font-weight: bold; font-weight: bold;
} }
.token.italic, .token.italic,
.token.selector, .token.selector,
.token.doctype, .token.doctype,
.token.attr-name, .token.attr-name,
.token.inserted, .token.inserted,
.token.deleted, .token.deleted,
.token.comment, .token.comment,
.token.prolog, .token.prolog,
.token.cdata, .token.cdata,
.token.constant, .token.constant,
.token.parameter, .token.parameter,
.token.url { .token.url {
font-style: italic; font-style: italic;
} }
.token.url { .token.url {
text-decoration: underline; text-decoration: underline;
} }
.namespace { .namespace {
opacity: 0.7; opacity: 0.7;
} }
/* Syntax highlighting */ /* Syntax highlighting */
.token.constant { .token.constant {
color: #e0def4; color: #e0def4;
} }
.token.comment, .token.comment,
.token.prolog, .token.prolog,
.token.cdata, .token.cdata,
.token.punctuation { .token.punctuation {
color: #908caa; color: #908caa;
} }
.token.delimiter, .token.delimiter,
.token.important, .token.important,
.token.atrule, .token.atrule,
.token.operator, .token.operator,
.token.keyword { .token.keyword {
color: #3e8fb0; color: #3e8fb0;
} }
.token.tag, .token.tag,
.token.tag .punctuation, .token.tag .punctuation,
.token.doctype, .token.doctype,
.token.variable, .token.variable,
.token.regex, .token.regex,
.token.class-name, .token.class-name,
.token.selector, .token.selector,
.token.inserted { .token.inserted {
color: #9ccfd8; color: #9ccfd8;
} }
.token.boolean, .token.boolean,
.token.entity, .token.entity,
.token.number, .token.number,
.token.symbol, .token.symbol,
.token.function { .token.function {
color: #ea9a97; color: #ea9a97;
} }
.token.string, .token.string,
.token.char, .token.char,
.token.property, .token.property,
.token.attr-value, .token.attr-value,
.token.attr-value .punctuation { .token.attr-value .punctuation {
color: #f6c177; color: #f6c177;
} }
.token.parameter, .token.parameter,
.token.url, .token.url,
.token.name, .token.name,
.token.attr-name, .token.attr-name,
.token.builtin { .token.builtin {
color: #c4a7e7; color: #c4a7e7;
} }
.token.deleted { .token.deleted {
color: #eb6f92; color: #eb6f92;
} }
/* Insertions & deletions */ /* Insertions & deletions */
.token.inserted { .token.inserted {
background: rgba(156 207 216 0.12); background: rgba(156 207 216 0.12);
} }
.token.deleted { .token.deleted {
background: rgba(235 111 146 0.12); background: rgba(235 111 146 0.12);
} }
/* Line highlighting */ /* Line highlighting */
pre[data-line] { pre[data-line] {
position: relative; position: relative;
} }
pre[class*="language-"] > code[class*="language-"] { pre[class*="language-"] > code[class*="language-"] {
position: relative; position: relative;
z-index: 1; z-index: 1;
} }
.line-highlight, .line-highlight,
.highlight-lines .highlighted { .highlight-lines .highlighted {
position: absolute; position: absolute;
left: 0; left: 0;
right: 0; right: 0;
@ -198,4 +198,4 @@ pre[class*="language-"] > code[class*="language-"] {
line-height: inherit; line-height: inherit;
white-space: pre; white-space: pre;
} }