Skip to content

Commit

Permalink
fix(notice): validate correct keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Nov 4, 2024
1 parent 075eaca commit c457f23
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/cli/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 7 additions & 15 deletions src/cli/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const (
YAML string = "yaml"
TOML string = "toml"

AUTOUPGRADE = "autoupgrade"
UPGRADENOTICE = "upgradenotice"
AUTOUPGRADE = "upgrade"
UPGRADENOTICE = "notice"

Version = 3
)
Expand Down
2 changes: 1 addition & 1 deletion website/docs/installation/upgrade.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ oh-my-posh upgrade
<TabItem value="cli">

```powershell
oh-my-posh enable autoupgrade
oh-my-posh enable upgrade
```

</TabItem>
Expand Down

0 comments on commit c457f23

Please sign in to comment.