3 ms·
Very opinionated, and IMO without enough justification. The assertions around short options with arguments - conjoining with other short options, for example -
by barrkel 6y ago
Very opinionated, and IMO without enough justification.
The assertions around short options with arguments - conjoining with other short options, for example - are actively harmful to legibility in scripts, since there's no lexical distinction between the argument and extra short options. I don't recommend using that syntax when alternatives are available and I deliberately don't support it when implementing ad-hoc argument parsing (typically when commands are executed as parsing proceeds).
- Spivak 6y agoCounterexamples where this is good for legibility. tar -xf archive.tar.gz tar -czf archive.tar.gz dir/
- cellularmitosis 6y ago> tar -czf dir/ You forgot the output filename. The thing I like about tar is that you only need to learn two options: 'c' and 'x': tar c somedir | gzip > somedir.tar.gz cat somedir.tar.gz | gunzip | tar x
- Spivak 6y agoThank you! Fixed!
- curryhoward 6y agoI'm guessing the comment was talking about examples like this: program -abcdefg.txt Just from reading this, you can't tell where the flags end and the filename begins unless you have all the flags and their arities memorized.
- DangitBobby 6y agoWorse than that, it adds an unstable convention to an otherwise stable interface. What if there used to be a, b flags and then they add a c flag? Who knows what your command does now. It's just bad all around.
- Spivak 6y agoIt’s not unstable or ambiguous at all. -abcdefg.txt In your hypothetical -b takes an argument which means it consumes all the characters following it. Anything following b is never interpreted as a flag. There is no danger of -c changing the parsing. Even if b takes an optional argument it still consumes all characters following it.
- DangitBobby 6y agoAh, you are right.
- Spivak 6y agoThat’s always true even before you talk about option combining. python scr.py -a -v Interpreting this command correctly requires you to know that python passes everything after the first positional argument to the script. ansible play.yml -v Where ansible itself consumes the -v argument. It gets even worse with subcommands. sudo -k command -a subcommand -v Options parsing is nice because the arity of options is always 0 or 1.
- arp242 6y ago> short options with arguments - conjoining with other short options, for example - are actively harmful to legibility in scripts Agreed, which is why you shouldn't do that :-) They're a lot easier to type though. I consider short and long arguments as solving different problems: the short are short so it's easy for interactive usage (especially for common options), and the long ones are for scripting (or discoverability, especially with things like zsh's completion). So I usually use "curl -s" on the commandline, and "curl --silent" when writing scripts.