Skip to content

Commit

Permalink
fix(config): ensure provided config path is used (filebrowser#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
1138-4EB authored Aug 16, 2018
1 parent 69d1fdc commit 1e12bb7
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions cmd/filebrowser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,36 +117,25 @@ func setupViper() {
viper.BindPFlag("AlternativeRecaptcha", flag.Lookup("alternative-recaptcha"))
viper.BindPFlag("ReCaptchaKey", flag.Lookup("recaptcha-key"))
viper.BindPFlag("ReCaptchaSecret", flag.Lookup("recaptcha-secret"))

viper.SetConfigName("filebrowser")
viper.AddConfigPath(".")
}

func printVersion() {
fmt.Println("filebrowser version", filebrowser.Version)
os.Exit(0)
}

func main() {
setupViper()
flag.Parse()

if showVer {
printVersion()
}

func initConfig() {
// Add a configuration file if set.
if config != "" {
ext := filepath.Ext(config)
dir := filepath.Dir(config)
config = strings.TrimSuffix(config, ext)

if dir != "" {
cfg := strings.TrimSuffix(config, filepath.Ext(config))
if dir := filepath.Dir(cfg); dir != "" {
viper.AddConfigPath(dir)
config = strings.TrimPrefix(config, dir)
cfg = strings.TrimPrefix(cfg, dir)
}

viper.SetConfigName(config)
viper.SetConfigName(cfg)
} else {
viper.SetConfigName("filebrowser")
viper.AddConfigPath(".")
}

// Read configuration from a file if exists.
Expand All @@ -156,6 +145,17 @@ func main() {
panic(err)
}
}
}

func main() {
setupViper()
flag.Parse()

if showVer {
printVersion()
}

initConfig();

// Set up process log before anything bad happens.
switch viper.GetString("Logger") {
Expand Down

0 comments on commit 1e12bb7

Please sign in to comment.