Skip to content

Commit 4e1007c

Browse files
committed
Start implementing 'config --save'
Instead of having to write out the 'zb' config file yourself, make it possible for 'zb' to write the current settings to file so that it can be edited from a starting point rather than having to start from scratch.
1 parent 150661e commit 4e1007c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cmd/config.go

+9
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@ var configCmd = &cobra.Command{
1616
if configFile != "" {
1717
fmt.Printf("Config file used: %s\n\n", viper.ConfigFileUsed())
1818
}
19+
1920
jsonStr, _ := json.MarshalIndent(viper.AllSettings(), "", " ")
2021
fmt.Println(string(jsonStr))
22+
23+
save, _ := cmd.Flags().GetBool("save")
24+
if save {
25+
viper.WriteConfig()
26+
fmt.Println("Configuration saved to", viper.ConfigFileUsed())
27+
}
2128
},
2229
}
2330

2431
func init() {
32+
configCmd.PersistentFlags().BoolP("save", "s", false, "Write current configuration to file")
33+
viper.BindPFlag("save", configCmd.PersistentFlags().Lookup("save"))
2534
rootCmd.AddCommand(configCmd)
2635
}

0 commit comments

Comments
 (0)