Skip to content

Commit

Permalink
feat: merge config and profile command
Browse files Browse the repository at this point in the history
  • Loading branch information
linfan committed May 26, 2022
1 parent 86c988c commit 504e95d
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 51 deletions.
1 change: 0 additions & 1 deletion cmd/ktctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func main() {
rootCmd.AddCommand(command.NewRecoverCommand())
rootCmd.AddCommand(command.NewCleanCommand())
rootCmd.AddCommand(command.NewConfigCommand())
rootCmd.AddCommand(command.NewProfileCommand())
rootCmd.SetHelpCommand(&cobra.Command{Hidden: true})
rootCmd.SetUsageTemplate(general.UsageTemplate(false))
rootCmd.SilenceUsage = true
Expand Down
6 changes: 5 additions & 1 deletion pkg/kt/command/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ func NewConfigCommand() *cobra.Command {
opt.HideGlobalFlags(cmd)
return cmd.Help()
},
Example: "ktctl config [show | get <key> | set <key> <value> | unset <key>]",
Example: "ktctl config <sub-command> [options]",
}

cmd.AddCommand(general.SimpleSubCommand("show", "Show all available and configured options", config.Show, config.ShowHandle))
cmd.AddCommand(general.SimpleSubCommand("get", "Fetch default value of specified option", config.Get, nil))
cmd.AddCommand(general.SimpleSubCommand("set", "Customize default value of specified option", config.Set, nil))
cmd.AddCommand(general.SimpleSubCommand("unset", "Restore default value of specified option", config.Unset, config.UnsetHandle))
cmd.AddCommand(general.SimpleSubCommand("list-profile", "List all pre-saved profiles", config.ListProfile, nil))
cmd.AddCommand(general.SimpleSubCommand("save-profile", "Save current configured options as a profile", config.SaveProfile, nil))
cmd.AddCommand(general.SimpleSubCommand("load-profile", "Load config from a profile", config.LoadProfile, config.LoadProfileHandle))
cmd.AddCommand(general.SimpleSubCommand("drop-profile", "Delete a profile", config.DropProfile, nil))

cmd.SetUsageTemplate(general.UsageTemplate(false))
opt.SetOptions(cmd, cmd.Flags(), opt.Get().Config, opt.ConfigFlags())
Expand Down
4 changes: 4 additions & 0 deletions pkg/kt/command/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"strings"
)

func profileFile(profile string) string {
return fmt.Sprintf("%s/%s", util.KtProfileDir, profile)
}

func loadCustomConfig() map[string]map[string]string {
config := make(map[string]map[string]string)
if customize, exist := opt.GetCustomizeKtConfig(); exist {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package profile
package config

import (
"fmt"
"github.com/rs/zerolog/log"
"os"
)

func Remove(args []string) error {
func DropProfile(args []string) error {
if len(args) != 1 {
return fmt.Errorf("must specifiy a profile name")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package profile
package config

import (
"fmt"
Expand All @@ -8,7 +8,7 @@ import (
"io/ioutil"
)

func List(args []string) error {
func ListProfile(args []string) error {
if len(args) > 0 {
return fmt.Errorf("parameter '%s' is invalid", args[0])
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package profile
package config

import (
"fmt"
Expand All @@ -11,7 +11,7 @@ import (

var dryRun bool

func Load(args []string) error {
func LoadProfile(args []string) error {
if len(args) != 1 {
return fmt.Errorf("must specifiy a profile name")
}
Expand All @@ -35,6 +35,6 @@ func Load(args []string) error {
return nil
}

func LoadHandle(cmd *cobra.Command) {
func LoadProfileHandle(cmd *cobra.Command) {
cmd.Flags().BoolVar(&dryRun, "dryRun", false, "Print profile content without load it")
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package profile
package config

import (
"fmt"
Expand All @@ -9,7 +9,7 @@ import (
"strings"
)

func Save(args []string) error {
func SaveProfile(args []string) error {
if len(args) != 1 {
return fmt.Errorf("must specifiy a profile name")
}
Expand Down
30 changes: 0 additions & 30 deletions pkg/kt/command/profile.go

This file was deleted.

10 changes: 0 additions & 10 deletions pkg/kt/command/profile/common.go

This file was deleted.

0 comments on commit 504e95d

Please sign in to comment.