Skip to content

Commit

Permalink
Start implementing 'config --save'
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
msp301 committed May 18, 2024
1 parent 150661e commit 4e1007c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ var configCmd = &cobra.Command{
if configFile != "" {
fmt.Printf("Config file used: %s\n\n", viper.ConfigFileUsed())
}

jsonStr, _ := json.MarshalIndent(viper.AllSettings(), "", " ")
fmt.Println(string(jsonStr))

save, _ := cmd.Flags().GetBool("save")
if save {
viper.WriteConfig()
fmt.Println("Configuration saved to", viper.ConfigFileUsed())
}
},
}

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

0 comments on commit 4e1007c

Please sign in to comment.