3 ms·
Oh nice, a golang opt parser that doesn't flout age-old Unix traditions.
by jnbiche 12y ago
Oh nice, a golang opt parser that doesn't flout age-old Unix traditions.
- CamperBob2 12y agoI'm curious, what's the significance of the use of --optname instead of -optname in a lot of *nix CLI apps?
- stormbrew 12y agoIt disambiguates multiple short flags from a long flag. Ie. if the program happened to have short flags l, o, n, g, and l could also be the whole word long, which would -long mean?
- ChristianBundy 12y agoFor example, single hyphens are stackable. For example, this: http://explainshell.com/explain?cmd=tar+-z+-c+-f http://explainshell.com/explain?cmd=tar+-z+-c+-f Is the same as: http://explainshell.com/explain?cmd=tar+-zcf http://explainshell.com/explain?cmd=tar+-zcf But trying to stack double-dashed arguments would be stupid: http://explainshell.com/explain?cmd=tar+--helpversion http://explainshell.com/explain?cmd=tar+--helpversion
- spb 12y ago> For example, this: http://explainshell.com/explain?cmd=tar+-z+-c+-f http://explainshell.com/explain?cmd=tar+-z+-c+-f > Is the same as: http://explainshell.com/explain?cmd=tar+-zcf http://explainshell.com/explain?cmd=tar+-zcf Which is also the same as http://explainshell.com/explain?cmd=tar+zcf http://explainshell.com/explain?cmd=tar+zcf because of the unique way tar treats argv[1].
- ta0967 12y agoas mentioned by others, the double hyphen makes all the difference, since `foo -flags` is the same as `foo -f -l -a -g -s`. if you allow single-dash long options you'll lose the appeal of short options. my favorite example is `grep -FIHnrie sth smw`: short option bundling is a massive usability enabler. let me turn the question around: you imply that you wouldn't miss bundling of short options. what tools do you use most? how come you'd not find `-a -b -c -d -e` inferior to `-abcde`?
- CamperBob2 12y agoI come from the DOS/Windows side, where it's relatively uncommon for CLI programs to support bundled options. When it's done, it usually is disambiguated by context -- for instance, -Oxyz to enable compiler optimizations x, y, and z. That's always worked OK for the programs I've dealt with, but obviously the *nix world has a culture of more elaborate and advanced command line tool usage. So it just didn't occur to me that this is what the -- business was for. I wasn't objecting to it, just wondering why it was done that way.
- arthurbrown 12y agoI think getopt provides a better middle ground between flag and docopt. Flag package syntax with short and long flag support http://godoc.org/code.google.com/p/getopt http://godoc.org/code.google.com/p/getopt