Skip to content

Commit

Permalink
Adjust config file / CLI arguments are merged.
Browse files Browse the repository at this point in the history
Previously, default values for command line arguments were overwriting
the config file settings. This results from the decision to have the
command line arguments take priority over the config file to
facilitate testing and debugging.
  • Loading branch information
kisom committed Jul 15, 2016
1 parent 79eda1e commit e2669c7
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions redoctober.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ var (
vaultPath string
)

const (
defaultAddr = "localhost:8080"
defaultMetricsHost = "localhost"
defaultMetricsPort = "8081"
)

func init() {
// cli contains the configuration set by the command line
// options, and cfg is the actual Red October config.
Expand All @@ -251,15 +257,15 @@ func init() {
}

flag.StringVar(&confFile, "f", "", "path to config file")
flag.StringVar(&cli.Server.Addr, "addr", "localhost:8080", "Server and port separated by :")
flag.StringVar(&cli.Server.Addr, "addr", defaultAddr, "Server and port separated by :")
flag.StringVar(&cli.Server.CAPath, "ca", "", "Path of TLS CA for client authentication (optional)")
flag.StringVar(&cli.Server.CertPaths, "certs", "", "Path(s) of TLS certificate in PEM format, comma-separated")
flag.StringVar(&cli.HipChat.Host, "hchost", "", "Hipchat Url Base (ex: hipchat.com)")
flag.StringVar(&cli.HipChat.APIKey, "hckey", "", "Hipchat API Key")
flag.StringVar(&cli.HipChat.Room, "hcroom", "", "Hipchat Room Id")
flag.StringVar(&cli.Server.KeyPaths, "keys", "", "Path(s) of TLS private key in PEM format, comma-separated, must me in the same order as the certs")
flag.StringVar(&cli.Metrics.Host, "metrics-host", "localhost", "The `host` the metrics endpoint should listen on.")
flag.StringVar(&cli.Metrics.Port, "metrics-port", "8081", "The `port` the metrics endpoint should listen on.")
flag.StringVar(&cli.Metrics.Host, "metrics-host", defaultMetricsHost, "The `host` the metrics endpoint should listen on.")
flag.StringVar(&cli.Metrics.Port, "metrics-port", defaultMetricsPort, "The `port` the metrics endpoint should listen on.")
flag.StringVar(&cli.UI.Root, "rohost", "", "RedOctober Url Base (ex: localhost:8080)")
flag.StringVar(&cli.UI.Static, "static", "", "Path to override built-in index.html")
flag.BoolVar(&cli.Server.Systemd, "systemdfds", false, "Use systemd socket activation to listen on a file. Useful for binding privileged sockets.")
Expand All @@ -277,6 +283,18 @@ func main() {
if err != nil {
log.Fatal(err)
}

if cli.Server.Addr == defaultAddr && cfg.Server.Addr != "" {
cli.Server.Addr = ""
}

if cli.Metrics.Host == defaultMetricsHost && cfg.Metrics.Host != "" {
cli.Metrics.Host = ""
}

if cli.Metrics.Port == defaultMetricsPort && cfg.Metrics.Port != "" {
cli.Metrics.Port = ""
}
}
cfg.Merge(cli)

Expand Down

0 comments on commit e2669c7

Please sign in to comment.