Currently, short flag aliases only support -c 100 and -c=100 syntax. The concatenated form -c100 (no space or equals) fails with:
error: command "rewrap": flag provided but not defined: -c100
This is because short aliases are registered as regular flags in a flag.FlagSet via combineFlags(), and Go's flag.FlagSet.Parse() does not support the concatenated form.
Feasibility
This is doable with a small arg-rewriting pass in xflag.ParseToEnd. The FlagSet is already available there, so the approach would be:
- Scan args for patterns like
-X<value> where X is a known single-letter flag that expects a value
- Expand
-c100 into -c 100 before passing to flag.Parse()
- Use the
FlagSet to distinguish -c100 (short flag c with value 100) from -verbose (long flag named verbose) by checking if a single-char flag exists
- Skip boolean flags since they don't take values (and
-vn style combining is out of scope)
The scope is contained -- mostly changes to xflag/parse.go with maybe a small helper.
Currently, short flag aliases only support
-c 100and-c=100syntax. The concatenated form-c100(no space or equals) fails with:This is because short aliases are registered as regular flags in a
flag.FlagSetviacombineFlags(), and Go'sflag.FlagSet.Parse()does not support the concatenated form.Feasibility
This is doable with a small arg-rewriting pass in
xflag.ParseToEnd. TheFlagSetis already available there, so the approach would be:-X<value>whereXis a known single-letter flag that expects a value-c100into-c100before passing toflag.Parse()FlagSetto distinguish-c100(short flagcwith value100) from-verbose(long flag namedverbose) by checking if a single-char flag exists-vnstyle combining is out of scope)The scope is contained -- mostly changes to
xflag/parse.gowith maybe a small helper.