From 0280e6e5911d4198f69eae9c876722fdf6149b89 Mon Sep 17 00:00:00 2001 From: Pablo Diaz Date: Fri, 20 May 2022 17:35:02 +0200 Subject: [PATCH] ignores short and long parameters --- example_test.go | 16 ++++++++++++++++ parse.go | 5 ----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/example_test.go b/example_test.go index 5272393..acfacad 100644 --- a/example_test.go +++ b/example_test.go @@ -496,3 +496,19 @@ func Example_allSupportedTypes() { // output: } + +func Example_envVarOnly() { + os.Args = split("./example") + _ = os.Setenv("NUM_WORKERS", "my_key") + + defer os.Unsetenv("NUM_WORKERS") + + var args struct { + AuthKey string `arg:"-,--,env:NUM_WORKERS"` + } + + MustParse(&args) + + fmt.Println(args.AuthKey) + // output: my_key +} diff --git a/parse.go b/parse.go index be77924..e5df067 100644 --- a/parse.go +++ b/parse.go @@ -360,11 +360,6 @@ func cmdFromStruct(name string, dest path, t reflect.Type) (*command, error) { case strings.HasPrefix(key, "--"): spec.long = key[2:] case strings.HasPrefix(key, "-"): - if len(key) != 2 { - errs = append(errs, fmt.Sprintf("%s.%s: short arguments must be one character only", - t.Name(), field.Name)) - return false - } spec.short = key[1:] case key == "required": spec.required = true