Skip to content

Commit

Permalink
config: merge new config keys into existing one before writing
Browse files Browse the repository at this point in the history
  • Loading branch information
phiros committed Apr 1, 2019
1 parent 9a67051 commit 8c43afa
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var configCommand = &cobra.Command{
firstArgument := args[0]
configKey := firstArgument
containsEquals := strings.Index(firstArgument, "=") > 0
err := viper.ReadInConfig()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
}
if containsEquals {
// write to config
configKeyValue := strings.Split(firstArgument, "=")
Expand All @@ -37,16 +41,16 @@ var configCommand = &cobra.Command{
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
}
err = viper.MergeInConfig()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
}
err = viper.WriteConfigAs(filepath.Join(dir, configFileName))
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
}
return
}
err := viper.ReadInConfig()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
}
configValue := viper.Get(configKey)
switch v := configValue.(type) {
case string:
Expand Down

0 comments on commit 8c43afa

Please sign in to comment.