diff options
Diffstat (limited to '')
-rw-r--r-- | cmd/gonf/cmd_build.go | 2 | ||||
-rw-r--r-- | cmd/gonf/cmd_deploy.go | 2 | ||||
-rw-r--r-- | cmd/gonf/hostflag.go | 11 |
3 files changed, 10 insertions, 5 deletions
diff --git a/cmd/gonf/cmd_build.go b/cmd/gonf/cmd_build.go index 566edfd..0bc1fa0 100644 --- a/cmd/gonf/cmd_build.go +++ b/cmd/gonf/cmd_build.go @@ -24,7 +24,7 @@ where FLAG can be one or more of`, flag.ContinueOnError) f.SetOutput(stdout) f.Usage() } - hostDir, err := hostFlagToHostDir(hostFlag) + hostDir, err := hostFlagToHostDir(hostFlag, getenv) if err != nil { f.Usage() return err diff --git a/cmd/gonf/cmd_deploy.go b/cmd/gonf/cmd_deploy.go index 0d48b2b..2f0d68f 100644 --- a/cmd/gonf/cmd_deploy.go +++ b/cmd/gonf/cmd_deploy.go @@ -23,7 +23,7 @@ where FLAG can be one or more of`, flag.ContinueOnError) f.SetOutput(stdout) f.Usage() } - hostDir, err := hostFlagToHostDir(hostFlag) + hostDir, err := hostFlagToHostDir(hostFlag, getenv) if err != nil { f.Usage() return err diff --git a/cmd/gonf/hostflag.go b/cmd/gonf/hostflag.go index 2c2c877..e936f45 100644 --- a/cmd/gonf/hostflag.go +++ b/cmd/gonf/hostflag.go @@ -8,12 +8,17 @@ import ( ) func addHostFlag(f *flag.FlagSet) *string { - return f.String("host", "", "(REQUIRED) a valid $GONF_CONFIG/hosts/ subdirectory") + return f.String("host", "", "(REQUIRED) a valid $GONF_CONFIG/hosts/ subdirectory (overrides the GONF_HOST environment variable)") } -func hostFlagToHostDir(hostFlag *string) (string, error) { +func hostFlagToHostDir(hostFlag *string, + getenv func(string) string, +) (string, error) { if *hostFlag == "" { - return "", fmt.Errorf("required -host FLAG is missing") + *hostFlag = getenv("GONF_HOST") + if *hostFlag == "" { + return "", fmt.Errorf("the GONF_HOST environment variable is unset and the -host FLAG is missing. Please use one or the other") + } } hostDir := filepath.Join(configDir, "hosts", *hostFlag) if info, err := os.Stat(hostDir); err != nil { |