aboutsummaryrefslogtreecommitdiffhomepage
path: root/cli
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2019-06-02 18:20:59 -0700
committerGravatar fguillot <fred@miniflux.net>2019-06-02 18:28:29 -0700
commitf7b7b63e3f30b4d855a26d550ddf726116c65846 (patch)
tree96c396d8905b6465ccc94d3f3bc6fd833d4332cb /cli
parentbb720c87c191efe36a328d95a918f75df51d4976 (diff)
Add optional config file parser in addition to environment variables
Diffstat (limited to 'cli')
-rw-r--r--cli/cli.go25
1 files changed, 24 insertions, 1 deletions
diff --git a/cli/cli.go b/cli/cli.go
index ae94aba..eba1ee3 100644
--- a/cli/cli.go
+++ b/cli/cli.go
@@ -24,11 +24,14 @@ const (
flagResetPasswordHelp = "Reset user password"
flagResetFeedErrorsHelp = "Clear all feed errors for all users"
flagDebugModeHelp = "Show debug logs"
+ flagConfigFileHelp = "Load configuration file"
+ flagConfigDumpHelp = "Print parsed configuration values"
)
// Parse parses command line arguments.
func Parse() {
var (
+ err error
flagInfo bool
flagVersion bool
flagMigrate bool
@@ -37,6 +40,8 @@ func Parse() {
flagResetPassword bool
flagResetFeedErrors bool
flagDebugMode bool
+ flagConfigFile string
+ flagConfigDump bool
)
flag.BoolVar(&flagInfo, "info", false, flagInfoHelp)
@@ -49,12 +54,30 @@ func Parse() {
flag.BoolVar(&flagResetPassword, "reset-password", false, flagResetPasswordHelp)
flag.BoolVar(&flagResetFeedErrors, "reset-feed-errors", false, flagResetFeedErrorsHelp)
flag.BoolVar(&flagDebugMode, "debug", false, flagDebugModeHelp)
+ flag.StringVar(&flagConfigFile, "config-file", "", flagConfigFileHelp)
+ flag.StringVar(&flagConfigFile, "c", "", flagConfigFileHelp)
+ flag.BoolVar(&flagConfigDump, "config-dump", false, flagConfigDumpHelp)
flag.Parse()
- if err := config.ParseConfig(); err != nil {
+ cfg := config.NewParser()
+
+ if flagConfigFile != "" {
+ config.Opts, err = cfg.ParseFile(flagConfigFile)
+ if err != nil {
+ logger.Fatal("%v", err)
+ }
+ }
+
+ config.Opts, err = cfg.ParseEnvironmentVariables()
+ if err != nil {
logger.Fatal("%v", err)
}
+ if flagConfigDump {
+ fmt.Print(config.Opts)
+ return
+ }
+
if flagDebugMode || config.Opts.HasDebugMode() {
logger.EnableDebug()
}