fix config flag
Former-commit-id: 65a11b9443bda4265bf1fd364152bc73b6f9c1bd [formerly 305a3ac513356904f617a7f676af0a24f985d402] [formerly 1e28fe6c8425f10b0bf0d095906cc3d7e7a37bb9 [formerly 2334bb601d
]]
Former-commit-id: aca1773aca8a57a73c635990a4d41fba6e665736 [formerly 3e9b1d5cfff424d8b3d3c28687c885b77ab16587]
Former-commit-id: badcc38a9615287bc232a0aa3fb70310d16afe3c
pull/726/head
parent
c5fbb47147
commit
efe36312ec
|
@ -35,7 +35,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.StringVarP(&config, "config", "c", "", "JSON configuration file")
|
flag.StringVarP(&config, "config", "c", "", "Configuration file")
|
||||||
flag.IntVarP(&port, "port", "p", 0, "HTTP Port (default is random)")
|
flag.IntVarP(&port, "port", "p", 0, "HTTP Port (default is random)")
|
||||||
flag.StringVarP(&addr, "address", "a", "", "Address to listen to (default is all of them)")
|
flag.StringVarP(&addr, "address", "a", "", "Address to listen to (default is all of them)")
|
||||||
flag.StringVarP(&database, "database", "d", "./filemanager.db", "Database file")
|
flag.StringVarP(&database, "database", "d", "./filemanager.db", "Database file")
|
||||||
|
@ -81,7 +81,16 @@ func main() {
|
||||||
|
|
||||||
// Add a configuration file if set.
|
// Add a configuration file if set.
|
||||||
if config != "" {
|
if config != "" {
|
||||||
viper.SetConfigName(strings.TrimSuffix(config, filepath.Ext(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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read configuration from a file if exists.
|
// Read configuration from a file if exists.
|
||||||
|
|
Loading…
Reference in New Issue