Skip to content

Commit

Permalink
Add a --config option to point to config files in custom locations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian MacLeod committed Jul 24, 2014
1 parent 77da81f commit 8243118
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
14 changes: 13 additions & 1 deletion go/cmd/zeus/zeus.go
Expand Up @@ -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":
Expand All @@ -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
Expand All @@ -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" {
Expand Down
4 changes: 2 additions & 2 deletions go/config/config.go
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
5 changes: 4 additions & 1 deletion man/src/zeus.ronn
Expand Up @@ -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

Expand Down Expand Up @@ -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]:
Expand Down

0 comments on commit 8243118

Please sign in to comment.