ignores short and long parameters

This commit is contained in:
Pablo Diaz 2022-05-20 17:35:02 +02:00 committed by Ilja Neumann
parent e25b4707a7
commit 0280e6e591
2 changed files with 16 additions and 5 deletions

View File

@ -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
}

View File

@ -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