diff options
| author | Pablo Diaz <[email protected]> | 2022-05-20 17:35:02 +0200 |
|---|---|---|
| committer | Ilja Neumann <[email protected]> | 2023-06-03 02:39:42 +0200 |
| commit | 0280e6e5911d4198f69eae9c876722fdf6149b89 (patch) | |
| tree | 2d97782aae35ffdab788b8cacfcfaa1fd4b056d2 | |
| parent | e25b4707a7d6c63ff6910c1e1bcb416cb8debfb2 (diff) | |
ignores short and long parameters
| -rw-r--r-- | example_test.go | 16 | ||||
| -rw-r--r-- | 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 +} @@ -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 |
