From 87cf2082f81c8f0eb59b4acd5548724e6267b487 Mon Sep 17 00:00:00 2001 From: 1138-4EB <1138-4EB@users.noreply.github.com> Date: Fri, 10 Aug 2018 03:30:15 +0100 Subject: [PATCH] style: clean cli/cmd/root.go --- cli/cmd/root.go | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/cli/cmd/root.go b/cli/cmd/root.go index 7eb01e29..412a0877 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -37,19 +37,12 @@ func init() { cobra.OnInitialize(initConfig) rootCmd.SetVersionTemplate("File Browser {{printf \"version %s\" .Version}}\n") - rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.cli.yaml)") - - // Cobra also supports local flags, which will only run - // when this action is called directly. - //rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (defaults are './.filebrowser[ext]', '$HOME/.filebrowser[ext]' or '/etc/filebrowser/.filebrowser[ext]')") } // initConfig reads in config file and ENV variables if set. func initConfig() { - if cfgFile != "" { - // Use config file from the flag. - viper.SetConfigFile(cfgFile) - } else { + if cfgFile == "" { // Find home directory. home, err := homedir.Dir() if err != nil { @@ -60,6 +53,9 @@ func initConfig() { viper.AddConfigPath(home) viper.AddConfigPath("/etc/filebrowser/") viper.SetConfigName(".filebrowser") + } else { + // Use config file from the flag. + viper.SetConfigFile(cfgFile) } viper.SetEnvPrefix("FB") @@ -73,19 +69,3 @@ func initConfig() { fmt.Println("Using config file:", viper.ConfigFileUsed()) } } - -/* - // Add a configuration file if set. - if config != "" { - ext := filepath.Ext(config) - dir := filepath.Dir(config) - config = strings.TrimSuffix(config, ext) - - if dir != "" { - viper.AddConfigPath(dir) - config = strings.TrimPrefix(config, dir) - } - - viper.SetConfigName(config) - } -*/ \ No newline at end of file