config flags to config vars

This commit is contained in:
kolaente 2018-12-07 23:53:24 +01:00
parent c2252ba522
commit 4403059569
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 4 additions and 3 deletions

View File

@ -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")
}