diff options
-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 | ||||
-rw-r--r-- | pkg/values.go | 4 |
4 files changed, 12 insertions, 7 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 { diff --git a/pkg/values.go b/pkg/values.go index c85de01..d18b499 100644 --- a/pkg/values.go +++ b/pkg/values.go @@ -65,13 +65,13 @@ type IntValue struct { } func (i IntValue) Bytes() []byte { - return []byte(fmt.Sprint(i.value)) + return []byte(strconv.Itoa(i.value)) } func (i IntValue) Int() (int, error) { return i.value, nil } func (i IntValue) String() string { - return fmt.Sprint(i.value) + return strconv.Itoa(i.value) } type StringsListValue struct { |