Allow "-" as a positional or flag argument.

See #70.

There are some more elaborate ideas in that issue, but I think this is
sufficient for now.
This commit is contained in:
Alec Thomas
2020-04-27 09:06:10 +10:00
parent 860aaac388
commit 407c8229a6
4 changed files with 39 additions and 19 deletions
+10 -7
View File
@@ -78,13 +78,16 @@ func (t TokenType) IsAny(types ...TokenType) bool {
// InferredType tries to infer the type of a token.
func (t Token) InferredType() TokenType {
if t.Type == UntypedToken {
if v, ok := t.Value.(string); ok {
if strings.HasPrefix(v, "--") {
return FlagToken
} else if strings.HasPrefix(v, "-") {
return ShortFlagToken
}
if t.Type != UntypedToken {
return t.Type
}
if v, ok := t.Value.(string); ok {
if strings.HasPrefix(v, "--") { // nolint: gocritic
return FlagToken
} else if v == "-" {
return PositionalArgumentToken
} else if strings.HasPrefix(v, "-") {
return ShortFlagToken
}
}
return t.Type