exclude items from config when empty and rest options

This commit is contained in:
2021-04-23 13:11:15 +02:00
parent bacbd0f806
commit 188560395d
3 changed files with 50 additions and 23 deletions

View File

@@ -12,14 +12,14 @@ import (
"github.com/spf13/viper"
)
const VERSION = "1.0.3"
const VERSION = "1.0.4"
var CI bool = false
var VERBOSE bool = false
type Config struct {
Locations map[string]Location `mapstructure:"locations"`
Backends map[string]Backend `mapstructure:"backends"`
Locations map[string]Location `yaml:"locations"`
Backends map[string]Backend `yaml:"backends"`
}
var once sync.Once
@@ -197,3 +197,16 @@ func AddFlagsToCommand(cmd *cobra.Command, backend bool) {
cmd.PersistentFlags().StringSliceP("location", "l", []string{}, "Locations")
}
}
func (c *Config) SaveConfig() error {
file := viper.ConfigFileUsed()
if err := CopyFile(file, file+".old"); err != nil {
return err
}
colors.Secondary.Println("Saved a backup copy of your file next the the original.")
viper.Set("backends", c.Backends)
viper.Set("locations", c.Locations)
return viper.WriteConfig()
}