Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
clean config cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnirtl committed Feb 18, 2020
1 parent f7b29da commit 6a8dc35
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions internal/commands/configcmd/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ var catCmd = &cobra.Command{
Example: "dockma config cat",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
filepath := config.GetFile(("config.json"))
filepath := config.GetFile("config.json")

content, err := ioutil.ReadFile(filepath)

if err != nil {
utils.ErrorAndExit(errors.New("Could not read config file"))
} else {
fmt.Printf("%sHere comes the dockma configuration file:%s\n", chalk.Cyan, chalk.ResetColor)
fmt.Printf("Here comes the %s file:\n", chalk.Cyan.Color("Dockma config"))

fmt.Println(string(content))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/configcmd/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var homeCmd = &cobra.Command{
Example: "dockma config home",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Dockma config home dir: %s%s%s\n", chalk.Cyan, viper.GetString("home"), chalk.ResetColor)
fmt.Printf("Dockma config home dir: %s\n", chalk.Cyan.Color(viper.GetString("home")))
},
}

Expand Down
33 changes: 21 additions & 12 deletions internal/commands/configcmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,36 @@ import (
"github.com/ttacon/chalk"
)

var configVars []string = []string{"hidesubcommandoutput", "logfile", "username"}

var setCmd = &cobra.Command{
Use: "set",
Short: "Set Dockma config vars in an interactive walkthrough",
Long: "Set Dockma config vars in an interactive walkthrough",
Example: "dockma config set",
Args: cobra.NoArgs,
Use: "set",
Short: "Set Dockma config vars in an interactive walkthrough",
Long: "Set Dockma config vars in an interactive walkthrough",
Example: "dockma config set",
Args: cobra.OnlyValidArgs,
ValidArgs: configVars,
Run: func(cmd *cobra.Command, args []string) {
options := []string{
fmt.Sprintf("hidesubcommandoutput: %t", viper.GetBool("hidesubcommandoutput")),
fmt.Sprintf("logfile: %s", viper.GetString("logfile")),
fmt.Sprintf("username: %s", viper.GetString("username")),
}
var selected []string

selected := survey.MultiSelect("Select config items to change", options, nil)
if len(args) == 0 {
options := []string{
fmt.Sprintf("hidesubcommandoutput: %t", viper.GetBool("hidesubcommandoutput")),
fmt.Sprintf("logfile: %s", viper.GetString("logfile")),
fmt.Sprintf("username: %s", viper.GetString("username")),
}

selected = survey.MultiSelect("Select config items to change", options, nil)
} else {
selected = args
}

for _, varnameRaw := range selected {
varname := strings.Split(varnameRaw, ":")

setConfigVar(varname[0])

message := fmt.Sprintf("Set %s%s%s: %s%s%s", chalk.Cyan, varname[0], chalk.ResetColor, chalk.Cyan, viper.GetString(varname[0]), chalk.ResetColor)
message := fmt.Sprintf("Set %s: %s", chalk.Cyan.Color(varname[0]), chalk.Cyan.Color(viper.GetString(varname[0])))
err := fmt.Errorf("Failed to set '%s'", varname[0])
config.Save(message, err)
}
Expand Down

0 comments on commit 6a8dc35

Please sign in to comment.