Skip to content

Commit 8c43afa

Browse files
committed
config: merge new config keys into existing one before writing
1 parent 9a67051 commit 8c43afa

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cmd-config.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ var configCommand = &cobra.Command{
2727
firstArgument := args[0]
2828
configKey := firstArgument
2929
containsEquals := strings.Index(firstArgument, "=") > 0
30+
err := viper.ReadInConfig()
31+
if err != nil {
32+
_, _ = fmt.Fprintln(os.Stderr, err)
33+
}
3034
if containsEquals {
3135
// write to config
3236
configKeyValue := strings.Split(firstArgument, "=")
@@ -37,16 +41,16 @@ var configCommand = &cobra.Command{
3741
if err != nil {
3842
_, _ = fmt.Fprintln(os.Stderr, err)
3943
}
44+
err = viper.MergeInConfig()
45+
if err != nil {
46+
_, _ = fmt.Fprintln(os.Stderr, err)
47+
}
4048
err = viper.WriteConfigAs(filepath.Join(dir, configFileName))
4149
if err != nil {
4250
_, _ = fmt.Fprintln(os.Stderr, err)
4351
}
4452
return
4553
}
46-
err := viper.ReadInConfig()
47-
if err != nil {
48-
_, _ = fmt.Fprintln(os.Stderr, err)
49-
}
5054
configValue := viper.Get(configKey)
5155
switch v := configValue.(type) {
5256
case string:

0 commit comments

Comments
 (0)