From 8243118c81b02293ed8875d3ca2d18ef82460aa6 Mon Sep 17 00:00:00 2001 From: Ian MacLeod Date: Wed, 23 Jul 2014 17:10:58 -0700 Subject: [PATCH] Add a --config option to point to config files in custom locations. --- go/cmd/zeus/zeus.go | 14 +++++++++++++- go/config/config.go | 4 ++-- man/src/zeus.ronn | 5 ++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/go/cmd/zeus/zeus.go b/go/cmd/zeus/zeus.go index 6c08cbf8..1917a34e 100644 --- a/go/cmd/zeus/zeus.go +++ b/go/cmd/zeus/zeus.go @@ -32,7 +32,7 @@ func main() { slog.TraceLogger = slog.NewTraceLogger(tracefile) Args = Args[1:] } else { - fmt.Printf("Could not open trace file %s", Args[1]) + fmt.Printf("Could not open trace file %s\n", Args[1]) return } case "--file-change-delay": @@ -46,6 +46,14 @@ func main() { } else { execManPage("zeus") } + case "--config": + _, err := os.Stat(Args[1]) + if err != nil { + fmt.Printf("Config file doesn't exist: %s (%e)\n", Args[1], err) + return + } + config.ConfigFile = Args[1] + Args = Args[1:] case "--version": printVersion() return @@ -55,6 +63,10 @@ func main() { execManPage("zeus") } + // Don't confuse the master by sending *full* args to it; just those that are + // not zeus-specific. + config.Args = Args + if generalHelpRequested(Args) { execManPage("zeus") } else if Args[0] == "help" { diff --git a/go/config/config.go b/go/config/config.go index b8544b56..ae530a3c 100644 --- a/go/config/config.go +++ b/go/config/config.go @@ -13,7 +13,7 @@ import ( var Args = os.Args[1:] -const configFile string = "zeus.json" +var ConfigFile string = "zeus.json" type config struct { Command string @@ -89,7 +89,7 @@ func readConfigFileOrDefault(configFile string) ([]byte, error) { func parseConfig() (c config) { var conf config - contents, err := readConfigFileOrDefault(configFile) + contents, err := readConfigFileOrDefault(ConfigFile) if err != nil { zerror.ErrorConfigFileInvalidJson() } diff --git a/man/src/zeus.ronn b/man/src/zeus.ronn index 74e82400..bc6648bb 100644 --- a/man/src/zeus.ronn +++ b/man/src/zeus.ronn @@ -3,7 +3,7 @@ zeus(1) -- boot rails in under a second ## SYNOPSIS -`zeus` [--no-color] [--log FILE] [--file-change-delay TIME] COMMAND [ARGS] +`zeus` [--no-color] [--log FILE] [--file-change-delay TIME] [--config PATH] COMMAND [ARGS] ## DESCRIPTION @@ -56,6 +56,9 @@ See `https://github.com/burke/zeus/blob/master/docs/overview.md` and restart processes only after this deadline expires. The argument must be parseable by time.ParseDuration. The default delay is 300ms. +* `--config` path: + Read from the given JSON config file. + ## BUILTIN COMMANDS * [zeus start(1)][zeus-start]: