-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathenable.go
More file actions
54 lines (46 loc) · 1.14 KB
/
Copy pathenable.go
File metadata and controls
54 lines (46 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package cli
import (
"fmt"
"os"
"strings"
"github.com/jandedobbeleer/oh-my-posh/src/cache"
"github.com/jandedobbeleer/oh-my-posh/src/config"
"github.com/jandedobbeleer/oh-my-posh/src/cmdtree"
)
var (
toggleHelpText = `%s one of the following features:
`
toggleArgs = []string{
config.UPGRADENOTICE,
config.AUTOUPGRADE,
config.RELOAD,
}
toggleUse = fmt.Sprintf("%%s [%s]", strings.Join(toggleArgs, "|"))
toggleLong = strings.Join(append([]string{toggleHelpText}, toggleArgs...), "\n- ")
)
var enableCmd = &cmdtree.Command{
Use: fmt.Sprintf(toggleUse, "enable"),
Short: "Enable a feature",
Long: fmt.Sprintf(toggleLong, "Enable"),
ValidArgs: toggleArgs,
Args: NoArgsOrOneValidArg,
Run: func(cmd *cmdtree.Command, args []string) {
if len(args) == 0 {
_ = cmd.Help()
return
}
toggleFeature(cmd, args[0], true)
},
}
func init() {
RootCmd.AddCommand(enableCmd)
}
func toggleFeature(cmd *cmdtree.Command, feature string, enable bool) {
if feature == "" {
_ = cmd.Help()
return
}
cache.Init(os.Getenv("POSH_SHELL"), cache.Persist)
cache.Device.Set(feature, enable, cache.INFINITE)
cache.Close()
}