From 0d683ec2a5c01cfb591e23fb7f5db008fe115180 Mon Sep 17 00:00:00 2001 From: Danny Olson Date: Mon, 15 Apr 2024 10:06:00 -0700 Subject: [PATCH] Add config unset flag The unset flag takes a value removes it from the config file if it is relevant. It ignores arbitrary keys and for now only supports: access-token base-uri --- cmd/config/config.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/config/config.go b/cmd/config/config.go index 14526c2f..9ed15df3 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -80,8 +80,19 @@ func run() func(*cobra.Command, []string) error { } return writeConfig(config.NewConfig(rawConfig), v, setKeyFn) - case viper.GetBool(UnsetFlag): - fmt.Fprintln(cmd.OutOrStdout(), "called --unset flag") + case viper.IsSet(UnsetFlag): + config, v, err := getConfig() + if err != nil { + return err + } + + unsetKeyFn := func(key string, value interface{}, v *viper.Viper) { + if key != viper.GetString("unset") { + v.Set(key, value) + } + } + + return writeConfig(config, v, unsetKeyFn) } return nil