Skip to content

Commit

Permalink
refactor: reset -> unset
Browse files Browse the repository at this point in the history
  • Loading branch information
linfan committed May 18, 2022
1 parent 1d25ede commit a566f57
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/kt/command/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ func NewConfigCommand() *cobra.Command {
hideGlobalFlags(cmd)
return cmd.Help()
},
Example: "ktctl config [list | get key | set key=value | reset key]",
Example: "ktctl config [list | get key | set key=value | unset key]",
}

cmd.AddCommand(SubConfig("show", "List all available and configured options", config.Show, config.ShowHandle))
cmd.AddCommand(SubConfig("get", "Fetch default value of specified option", config.Get, nil))
cmd.AddCommand(SubConfig("set", "Customize default value of specified option", config.Set, nil))
cmd.AddCommand(SubConfig("reset", "Restore default value of specified option", config.Reset, config.ResetHandle))
cmd.AddCommand(SubConfig("unset", "Restore default value of specified option", config.Unset, config.UnsetHandle))
cmd.AddCommand(SubConfig("save", "Save current configured options as a profile", config.Save, config.SaveHandle))
cmd.AddCommand(SubConfig("load", "Show profiles or load config from a profile", config.Load, nil))

Expand Down
2 changes: 1 addition & 1 deletion pkg/kt/command/config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func Get(args []string) error {
}
config, err := loadConfig()
if err != nil {
return fmt.Errorf("config file is damaged, please try repair it or use 'ktctl config reset --all'")
return fmt.Errorf("config file is damaged, please try repair it or use 'ktctl config unset --all'")
}
for _, item := range args {
v, err2 := getConfigValue(config, item)
Expand Down
16 changes: 8 additions & 8 deletions pkg/kt/command/config/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ import (
"github.com/spf13/cobra"
)

var resetAll bool
var unsetAll bool

func Reset(args []string) error {
if resetAll {
func Unset(args []string) error {
if unsetAll {
return saveConfig(make(map[string]map[string]string))
}
if len(args) < 1 {
return fmt.Errorf("must specifiy a config item")
}
config, err := loadConfig()
if err != nil {
return fmt.Errorf("config file is damaged, please try repair it or use 'ktctl config reset --all'")
return fmt.Errorf("config file is damaged, please try repair it or use 'ktctl config unset --all'")
}
for _, item := range args {
err = resetConfigValue(config, item)
err = unsetConfigValue(config, item)
if err != nil {
return fmt.Errorf("%s, please check available config items with 'ktctl config show --all'", err)
}
}
return saveConfig(config)
}

func ResetHandle(cmd *cobra.Command) {
cmd.Flags().BoolVar(&resetAll, "all", false, "Reset all config options")
func UnsetHandle(cmd *cobra.Command) {
cmd.Flags().BoolVar(&unsetAll, "all", false, "Unset all config options")
}

func resetConfigValue(config map[string]map[string]string, key string) error {
func unsetConfigValue(config map[string]map[string]string, key string) error {
group, item, err := parseConfigItem(key)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/kt/command/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func Set(args []string) error {
}
config, err := loadConfig()
if err != nil {
return fmt.Errorf("config file is damaged, please try repair it or use 'ktctl config reset --all'")
return fmt.Errorf("config file is damaged, please try repair it or use 'ktctl config unset --all'")
}
var key, value string
if len(args) == 1 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kt/command/config/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Show(args []string) error {
}
config, err := loadConfig()
if err != nil {
return fmt.Errorf("config file is damaged, please try repair it or use 'ktctl config reset --all'")
return fmt.Errorf("config file is damaged, please try repair it or use 'ktctl config unset --all'")
}
for i := 0; i < reflect.TypeOf(opt.DaemonOptions{}).NumField(); i++ {
group := reflect.TypeOf(opt.DaemonOptions{}).Field(i)
Expand Down

0 comments on commit a566f57

Please sign in to comment.