From 25a5bc0b89b054a91aebfe805ac009cd8ad4db28 Mon Sep 17 00:00:00 2001 From: Iwasaki Yudai Date: Fri, 28 Aug 2015 21:11:46 -0700 Subject: [PATCH] Fix default config file loading --- app/app.go | 8 ++++---- main.go | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/app.go b/app/app.go index a2d03e0..cf0b6b8 100644 --- a/app/app.go +++ b/app/app.go @@ -106,7 +106,7 @@ func ApplyConfigFile(options *Options, configFilePath string) error { } func applyConfigFile(options *Options, filePath string) error { - filePath = expandHomeDir(filePath) + filePath = ExpandHomeDir(filePath) if _, err := os.Stat(filePath); os.IsNotExist(err) { return err } @@ -138,7 +138,7 @@ func applyConfigFile(options *Options, filePath string) error { return nil } -func expandHomeDir(path string) string { +func ExpandHomeDir(path string) string { if path[0:2] == "~/" { return os.Getenv("HOME") + path[1:] } else { @@ -234,8 +234,8 @@ func (app *App) Run() error { ) if app.options.EnableTLS { err = app.server.ListenAndServeTLS( - expandHomeDir(app.options.TLSCrtFile), - expandHomeDir(app.options.TLSKeyFile), + ExpandHomeDir(app.options.TLSCrtFile), + ExpandHomeDir(app.options.TLSKeyFile), ) } else { err = app.server.ListenAndServe() diff --git a/main.go b/main.go index 40b0a36..af9e6e1 100644 --- a/main.go +++ b/main.go @@ -69,7 +69,7 @@ func main() { options := app.DefaultOptions configFile := c.String("config") - _, err := os.Stat(configFile) + _, err := os.Stat(app.ExpandHomeDir(configFile)) if configFile != "~/.gotty" || !os.IsNotExist(err) { if err := app.ApplyConfigFile(&options, configFile); err != nil { exit(err, 2) @@ -101,7 +101,9 @@ func main() { } func exit(err error, code int) { - fmt.Println(err) + if err != nil { + fmt.Println(err) + } os.Exit(code) }