fix(notice): validate correct keyword

This commit is contained in:
Jan De Dobbeleer 2024-11-04 18:51:37 +01:00 committed by Jan De Dobbeleer
parent 075eacaaf9
commit c457f23734
4 changed files with 12 additions and 19 deletions

View file

@ -2,13 +2,14 @@ package cli
import (
"fmt"
"strings"
"github.com/spf13/cobra"
)
// getCmd represents the get command
var disableCmd = &cobra.Command{
Use: fmt.Sprintf(toggleUse, "disable"),
Use: fmt.Sprintf(toggleUse, "disable", strings.Join(toggleArgs, "|")),
Short: "Disable a feature",
Long: fmt.Sprintf(toggleLong, "Disable", "disable"),
ValidArgs: toggleArgs,

View file

@ -2,6 +2,7 @@ package cli
import (
"fmt"
"strings"
"github.com/jandedobbeleer/oh-my-posh/src/cache"
"github.com/jandedobbeleer/oh-my-posh/src/config"
@ -11,12 +12,12 @@ import (
)
var (
toggleUse = "%s [notice]"
toggleUse = "%s [%s]"
toggleLong = `%s a feature
This command is used to %s one of the following features:
- notice`
- upgradenotice`
toggleArgs = []string{
config.UPGRADENOTICE,
config.AUTOUPGRADE,
@ -25,7 +26,7 @@ This command is used to %s one of the following features:
// getCmd represents the get command
var enableCmd = &cobra.Command{
Use: fmt.Sprintf(toggleUse, "enable"),
Use: fmt.Sprintf(toggleUse, "enable", strings.Join(toggleArgs, "|")),
Short: "Enable a feature",
Long: fmt.Sprintf(toggleLong, "Enable", "enable"),
ValidArgs: toggleArgs,
@ -54,24 +55,15 @@ func toggleFeature(cmd *cobra.Command, feature string, enable bool) {
env.Init()
defer env.Close()
var key string
switch feature {
case "notice":
key = config.UPGRADENOTICE
case "autoupgrade":
key = config.AUTOUPGRADE
}
if len(key) == 0 {
if len(feature) == 0 {
_ = cmd.Help()
return
}
if enable {
env.Cache().Set(key, "true", cache.INFINITE)
env.Cache().Set(feature, "true", cache.INFINITE)
return
}
env.Cache().Delete(key)
env.Cache().Delete(feature)
}

View file

@ -14,8 +14,8 @@ const (
YAML string = "yaml"
TOML string = "toml"
AUTOUPGRADE = "autoupgrade"
UPGRADENOTICE = "upgradenotice"
AUTOUPGRADE = "upgrade"
UPGRADENOTICE = "notice"
Version = 3
)

View file

@ -29,7 +29,7 @@ oh-my-posh upgrade
<TabItem value="cli">
```powershell
oh-my-posh enable autoupgrade
oh-my-posh enable upgrade
```
</TabItem>