From c457f23734745c0a0624fc4d85d969699022cbfc Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Mon, 4 Nov 2024 18:51:37 +0100 Subject: [PATCH] fix(notice): validate correct keyword --- src/cli/disable.go | 3 ++- src/cli/enable.go | 22 +++++++--------------- src/config/config.go | 4 ++-- website/docs/installation/upgrade.mdx | 2 +- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/cli/disable.go b/src/cli/disable.go index a9ce42e7..ff03ca8e 100644 --- a/src/cli/disable.go +++ b/src/cli/disable.go @@ -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, diff --git a/src/cli/enable.go b/src/cli/enable.go index 42c34719..208abeb8 100644 --- a/src/cli/enable.go +++ b/src/cli/enable.go @@ -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) } diff --git a/src/config/config.go b/src/config/config.go index f6650350..05af4b64 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -14,8 +14,8 @@ const ( YAML string = "yaml" TOML string = "toml" - AUTOUPGRADE = "autoupgrade" - UPGRADENOTICE = "upgradenotice" + AUTOUPGRADE = "upgrade" + UPGRADENOTICE = "notice" Version = 3 ) diff --git a/website/docs/installation/upgrade.mdx b/website/docs/installation/upgrade.mdx index f4fdd60e..4608a7b3 100644 --- a/website/docs/installation/upgrade.mdx +++ b/website/docs/installation/upgrade.mdx @@ -29,7 +29,7 @@ oh-my-posh upgrade ```powershell -oh-my-posh enable autoupgrade +oh-my-posh enable upgrade ```