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

Commit

Permalink
add primary color config field and config set
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnirtl committed Feb 17, 2020
1 parent a3e3c0e commit 589eaf7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/commands/configcmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var setCmd = &cobra.Command{
options := []string{
fmt.Sprintf("hidesubcommandoutput: %t", viper.GetBool("hidesubcommandoutput")),
fmt.Sprintf("logfile: %s", viper.GetString("logfile")),
fmt.Sprintf("color: %s", viper.GetString("color")),
fmt.Sprintf("username: %s", viper.GetString("username")),
}

Expand Down Expand Up @@ -53,6 +54,11 @@ func setConfigVar(varname string) {

viper.Set("logfile", logfile)

case "color":
color := survey.Select("Select a new primary color", config.PrimaryColors)

viper.Set("color", color)

case "username":
username := survey.InputName("Enter new username", viper.GetString("username"))

Expand Down
1 change: 1 addition & 0 deletions internal/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func init() {
viper.SetDefault("username", "User")
viper.SetDefault("hidesubcommandoutput", true)
viper.SetDefault("logfile", "log.txt")
viper.SetDefault("color", "cyan")
viper.SetDefault("active", "-")
viper.SetDefault("envs", map[string]interface{}{})
}
Expand Down
8 changes: 8 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (

// NOTE viper gets initialized in commands/root.go.

// PrimaryColors are the available options for the color config field
var PrimaryColors []string = []string{"blue", "cyan", "magenta"}

// SaveConfig indicates whether config should be saved or not
var SaveConfig bool

Expand Down Expand Up @@ -82,6 +85,11 @@ func GetLogfile() string {
return GetFile(filename)
}

// GetColor returns the configured primary color.
func GetColor() string {
return viper.GetString("color")
}

// GetEnvNames returns configured envs.
func GetEnvNames() (envs []string) {
envsMap := viper.GetStringMap("envs")
Expand Down

0 comments on commit 589eaf7

Please sign in to comment.