Open lonnywong opened 2 years ago
Thanks for putting this comprehensive feature request together @lonnywong. I think it would be great to implement this.
Currently, go-arg allows "short" arguments that are more than one character long. However, to implement this I think only single-character short arguments should be considered for combining in this way. This means that it'll still be okay to have multi-character short arguments, but those arguments just can't be combined together.
I don't think we should allow things like -fbt5
or -ft7b
. That seems too complicated for now.
It may happen that somebody defines several single-character short arguments, and also a conflicting multiple-character short argument such as:
var args struct {
X bool `arg:'-x"`
Y bool `arg:'-y"`
Z bool `arg:'-z"`
XYZ bool `arg:'-xyz"`
}
In this case, if the user writes -xyz
on the command line then there will be an ambiguity. I think a reasonable solution would be to first check for an argument that exactly matches the string on the command line (in this case args.XYZ), and then if one doesn't exist then try looking for the individual characters (X, Y, and Z).
I will try to fine time to look into this.
Thanks. We could do the exactly matches first. If it doesn't match any arguments, then try the combined parsing. If -ft7b
doesn't match exactly, the f
matches one and it's boolean, then go on, the t
matches one and it's int, then the treats the left 7b
as int, e.g., -ft5
. If nothing left, treats the next argument as int, e.g., -ft 6
.
I have a solution, but probably not a good one.
https://github.com/trzsz/go-arg/blob/ac5a9f75703f3e4186ade7da860f1a675e8765b2/parse.go#L568-L594
Combined arguments are convenience to use. e.g.,
ps -ef
,rm -rf
.go-arg test code
python argparse test code
test cases