summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2024-06-07 22:42:57 +0200
committerJulien Dessaux2024-06-07 22:42:57 +0200
commit1a4192b5c94a2145f8ac6504f30643d9a838bff0 (patch)
tree6fc830ad0a42f2167b2a7aa9a110e0b3dd4d06c0
parentchore(gonf): removed opinionated static checkers (diff)
downloadgonf-1a4192b5c94a2145f8ac6504f30643d9a838bff0.tar.gz
gonf-1a4192b5c94a2145f8ac6504f30643d9a838bff0.tar.bz2
gonf-1a4192b5c94a2145f8ac6504f30643d9a838bff0.zip
feat(gonf): support a GONF_HOST environment variable
-rw-r--r--cmd/gonf/cmd_build.go2
-rw-r--r--cmd/gonf/cmd_deploy.go2
-rw-r--r--cmd/gonf/hostflag.go11
-rw-r--r--pkg/values.go4
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 {