From 4403059569939a8cc519680c6e7fac9b9265208c Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 7 Dec 2018 23:53:24 +0100 Subject: [PATCH] config flags to config vars --- cmd/root.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 26eb702..4a4da2f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -51,9 +51,11 @@ func init() { cobra.OnInitialize(initConfig) // Global flag - rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.sofad.yaml)") + rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.sofad.yaml or the directory of the binary)") rootCmd.PersistentFlags().StringP("serverurl", "s", "", "The server url where the client will send the data to") - rootCmd.PersistentFlags().StringP("privatekey", "k", "", "The locaton of the private key which will be used to authenticate against the server") + viper.BindPFlag("server.serverurl", rootCmd.Flags().Lookup("serverurl")) + rootCmd.PersistentFlags().StringP("privatekey", "k", "", "The location of the private key which will be used to authenticate against the server") + viper.BindPFlag("server.privatekey", rootCmd.Flags().Lookup("privatekey")) } // initConfig reads in config file and ENV variables if set. @@ -69,7 +71,6 @@ func initConfig() { os.Exit(1) } - // Search config in home directory with name ".cliend" (without extension). viper.AddConfigPath(home) viper.SetConfigName(".sofad") }