4 ms·
I'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 fil
by curryhoward 6y ago
I'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.