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 ( import (
"fmt" "fmt"
"strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// getCmd represents the get command // getCmd represents the get command
var disableCmd = &cobra.Command{ var disableCmd = &cobra.Command{
Use: fmt.Sprintf(toggleUse, "disable"), Use: fmt.Sprintf(toggleUse, "disable", strings.Join(toggleArgs, "|")),
Short: "Disable a feature", Short: "Disable a feature",
Long: fmt.Sprintf(toggleLong, "Disable", "disable"), Long: fmt.Sprintf(toggleLong, "Disable", "disable"),
ValidArgs: toggleArgs, ValidArgs: toggleArgs,

View file

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

View file

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

View file

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