ignores short and long parameters
This commit is contained in:
parent
e25b4707a7
commit
0280e6e591
|
@ -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
|
||||
}
|
||||
|
|
5
parse.go
5
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
|
||||
|
|
Loading…
Reference in New Issue