From 0941ed854975769a691221ad1ddf4bfde47d391f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Sun, 15 Apr 2018 01:25:21 +0200 Subject: [PATCH] Add reset-config flag --- commands/dispatch.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/commands/dispatch.go b/commands/dispatch.go index d78de678..14306b6b 100644 --- a/commands/dispatch.go +++ b/commands/dispatch.go @@ -36,7 +36,7 @@ var rootCmd = &cobra.Command{ storage.Initialize(viper.GetString("dir")) - initConfig(storage.Path.Config()) + initConfig(storage.Path.Config(), viper.GetBool("reset_config")) viper.SetConfigName("config") viper.AddConfigPath(storage.Path.Root()) @@ -77,18 +77,20 @@ func init() { rootCmd.AddCommand(configCmd) rootCmd.PersistentFlags().String("dir", storage.DefaultDirectory(), "directory to store config and data in") + rootCmd.PersistentFlags().Bool("reset-config", false, "reset to the default configuration, overwriting the current one") rootCmd.Flags().IntP("port", "p", 80, "port to listen on") rootCmd.Flags().Bool("dev", false, "development mode") viper.BindPFlag("dir", rootCmd.PersistentFlags().Lookup("dir")) + viper.BindPFlag("reset_config", rootCmd.PersistentFlags().Lookup("reset-config")) viper.BindPFlag("port", rootCmd.Flags().Lookup("port")) viper.BindPFlag("dev", rootCmd.Flags().Lookup("dev")) viper.SetDefault("verify_client_certificates", true) } -func initConfig(configPath string) { - if _, err := os.Stat(configPath); os.IsNotExist(err) { +func initConfig(configPath string, overwrite bool) { + if _, err := os.Stat(configPath); overwrite || os.IsNotExist(err) { config, err := assets.Asset("config.default.toml") if err != nil { log.Println(err)