Skip to content

Commit 1e12bb7

Browse files
author
1138-4EB
authored
fix(config): ensure provided config path is used (filebrowser#508)
1 parent 69d1fdc commit 1e12bb7

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

cmd/filebrowser/main.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,36 +117,25 @@ func setupViper() {
117117
viper.BindPFlag("AlternativeRecaptcha", flag.Lookup("alternative-recaptcha"))
118118
viper.BindPFlag("ReCaptchaKey", flag.Lookup("recaptcha-key"))
119119
viper.BindPFlag("ReCaptchaSecret", flag.Lookup("recaptcha-secret"))
120-
121-
viper.SetConfigName("filebrowser")
122-
viper.AddConfigPath(".")
123120
}
124121

125122
func printVersion() {
126123
fmt.Println("filebrowser version", filebrowser.Version)
127124
os.Exit(0)
128125
}
129126

130-
func main() {
131-
setupViper()
132-
flag.Parse()
133-
134-
if showVer {
135-
printVersion()
136-
}
137-
127+
func initConfig() {
138128
// Add a configuration file if set.
139129
if config != "" {
140-
ext := filepath.Ext(config)
141-
dir := filepath.Dir(config)
142-
config = strings.TrimSuffix(config, ext)
143-
144-
if dir != "" {
130+
cfg := strings.TrimSuffix(config, filepath.Ext(config))
131+
if dir := filepath.Dir(cfg); dir != "" {
145132
viper.AddConfigPath(dir)
146-
config = strings.TrimPrefix(config, dir)
133+
cfg = strings.TrimPrefix(cfg, dir)
147134
}
148-
149-
viper.SetConfigName(config)
135+
viper.SetConfigName(cfg)
136+
} else {
137+
viper.SetConfigName("filebrowser")
138+
viper.AddConfigPath(".")
150139
}
151140

152141
// Read configuration from a file if exists.
@@ -156,6 +145,17 @@ func main() {
156145
panic(err)
157146
}
158147
}
148+
}
149+
150+
func main() {
151+
setupViper()
152+
flag.Parse()
153+
154+
if showVer {
155+
printVersion()
156+
}
157+
158+
initConfig();
159159

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

0 commit comments

Comments
 (0)