3 ms·
Counterexamples where this is good for legibility. tar -xf archive.tar.gz tar -czf archive.tar.gz dir/
by Spivak 6y ago
Counterexamples 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.