summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2024-04-10 23:36:31 +0200
committerJulien Dessaux2024-04-11 00:00:00 +0200
commit19f5ed4e0c4c7183504975fe799003986095f48d (patch)
tree928ed7b4dc76d100761b8f229db6d9eeb147e9db
parentfeat(users): implemented basic user creation promise (diff)
downloadgonf-19f5ed4e0c4c7183504975fe799003986095f48d.tar.gz
gonf-19f5ed4e0c4c7183504975fe799003986095f48d.tar.bz2
gonf-19f5ed4e0c4c7183504975fe799003986095f48d.zip
feat(gonf): implement config directory flag and env variable
Diffstat (limited to '')
-rw-r--r--cmd/gonf/main.go20
1 files changed, 16 insertions, 4 deletions
diff --git a/cmd/gonf/main.go b/cmd/gonf/main.go
index 882636a..1e28368 100644
--- a/cmd/gonf/main.go
+++ b/cmd/gonf/main.go
@@ -12,13 +12,14 @@ import (
var (
batchMode bool
+ configDir string
helpMode bool
)
func main() {
if err := run(context.Background(),
os.Args,
- //os.Getenv,
+ os.Getenv,
//os.Getwd,
//os.Stdin,
os.Stdout,
@@ -31,7 +32,7 @@ func main() {
func run(ctx context.Context,
args []string,
- //getenv func(string) string,
+ getenv func(string) string,
//getwd func() (string, error),
//stdin io.Reader,
stdout, stderr io.Writer,
@@ -46,6 +47,7 @@ where COMMAND is one of:
where FLAG can be one or more of`, flag.ContinueOnError)
f.BoolVar(&batchMode, "batch", false, "skips all questions and confirmations, using the default (safe) choices each time")
f.BoolVar(&helpMode, "help", false, "show contextual help")
+ f.StringVar(&configDir, "config", "", "(REQUIRED for most commands) path to a gonf configurations repository (overrides the GONF_CONFIG environment variable)")
f.SetOutput(stderr)
f.Parse(args[1:])
@@ -61,8 +63,18 @@ where FLAG can be one or more of`, flag.ContinueOnError)
case "version":
cmdVersion()
default:
- f.Usage()
- return fmt.Errorf("Invalid command: %s", cmd)
+ if configDir == "" {
+ configDir = getenv("GONF_CONFIG")
+ if configDir == "" {
+ f.Usage()
+ return errors.New("The GONF_CONFIG environment variable is unset and the -config FLAG is missing. Please use one or the other.")
+ }
+ }
+ switch cmd {
+ default:
+ f.Usage()
+ return fmt.Errorf("Invalid command: %s", cmd)
+ }
}
return nil
}