From 5345ad37a2c7c989db6fa9cc1ef58769cbdc27ff Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Fri, 21 Dec 2018 04:17:22 +0100 Subject: [PATCH] Move server flags to global config, see #50 --- internal/commands/flags.go | 36 ++++++++++++++++++++++++++++++++++++ internal/context/config.go | 24 ++++++++++++------------ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/internal/commands/flags.go b/internal/commands/flags.go index e557f559f..a25d9686b 100644 --- a/internal/commands/flags.go +++ b/internal/commands/flags.go @@ -63,4 +63,40 @@ var GlobalFlags = []cli.Flag{ Value: "root:@tcp(localhost:4000)/photoprism?parseTime=true", EnvVar: "PHOTOPRISM_DATABASE_DSN", }, + cli.IntFlag{ + Name: "http-port, p", + Usage: "HTTP server port", + Value: 80, + EnvVar: "PHOTOPRISM_HTTP_PORT", + }, + cli.StringFlag{ + Name: "http-host, i", + Usage: "HTTP server host", + Value: "", + EnvVar: "PHOTOPRISM_HTTP_HOST", + }, + cli.StringFlag{ + Name: "http-mode, m", + Usage: "debug, release or test", + Value: "", + EnvVar: "PHOTOPRISM_HTTP_MODE", + }, + cli.IntFlag{ + Name: "sql-port, s", + Usage: "SQL server port", + Value: 4000, + EnvVar: "PHOTOPRISM_SQL_PORT", + }, + cli.StringFlag{ + Name: "sql-host", + Usage: "SQL server host", + Value: "", + EnvVar: "PHOTOPRISM_SQL_HOST", + }, + cli.StringFlag{ + Name: "sql-path", + Usage: "SQL server storage path", + Value: "", + EnvVar: "PHOTOPRISM_SQL_PATH", + }, } diff --git a/internal/context/config.go b/internal/context/config.go index d13729638..efee04468 100644 --- a/internal/context/config.go +++ b/internal/context/config.go @@ -180,28 +180,28 @@ func (c *Config) SetValuesFromCliContext(ctx *cli.Context) error { c.databaseDsn = ctx.GlobalString("database-dsn") } - if ctx.IsSet("sql-host") || c.sqlServerHost == "" { - c.sqlServerHost = ctx.String("sql-host") + if ctx.GlobalIsSet("sql-host") || c.sqlServerHost == "" { + c.sqlServerHost = ctx.GlobalString("sql-host") } - if ctx.IsSet("sql-port") || c.sqlServerPort == 0 { - c.sqlServerPort = ctx.Uint("sql-port") + if ctx.GlobalIsSet("sql-port") || c.sqlServerPort == 0 { + c.sqlServerPort = ctx.GlobalUint("sql-port") } - if ctx.IsSet("sql-path") || c.sqlServerPath == "" { - c.sqlServerPath = ctx.String("sql-path") + if ctx.GlobalIsSet("sql-path") || c.sqlServerPath == "" { + c.sqlServerPath = ctx.GlobalString("sql-path") } - if ctx.IsSet("http-host") || c.httpServerHost == "" { - c.httpServerHost = ctx.String("http-host") + if ctx.GlobalIsSet("http-host") || c.httpServerHost == "" { + c.httpServerHost = ctx.GlobalString("http-host") } - if ctx.IsSet("http-port") || c.httpServerPort == 0 { - c.httpServerPort = ctx.Int("http-port") + if ctx.GlobalIsSet("http-port") || c.httpServerPort == 0 { + c.httpServerPort = ctx.GlobalInt("http-port") } - if ctx.IsSet("http-mode") || c.httpServerMode == "" { - c.httpServerMode = ctx.String("http-mode") + if ctx.GlobalIsSet("http-mode") || c.httpServerMode == "" { + c.httpServerMode = ctx.GlobalString("http-mode") } return nil