tag: add passthrough for positional arguments
This new tag tells the parser to stop processing flags after the positional argument is encountered. This is particularly useful for subcommands that forward their arguments to an external program, and makes it possible to implement commands like `kubectl exec` or `docker run`. Fixes #80.
This commit is contained in:
committed by
Alec Thomas
parent
49417fe966
commit
d4dd709445
@@ -34,6 +34,7 @@ type Tag struct {
|
||||
Embed bool
|
||||
Aliases []string
|
||||
Negatable bool
|
||||
Passthrough bool
|
||||
|
||||
// Storage for all tag keys for arbitrary lookups.
|
||||
items map[string][]string
|
||||
@@ -184,6 +185,11 @@ func parseTag(fv reflect.Value, ft reflect.StructField) *Tag {
|
||||
t.PlaceHolder = strings.ToUpper(dashedString(fv.Type().Name()))
|
||||
}
|
||||
t.Enum = t.Get("enum")
|
||||
passthrough := t.Has("passthrough")
|
||||
if passthrough && !t.Arg {
|
||||
fail("passthrough only makes sense for positional arguments")
|
||||
}
|
||||
t.Passthrough = passthrough
|
||||
return t
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user