Well, the Utility Sintax Guideline can answer your question about the order of the options, and it's relationship with other options:
Guideline 11:
The order of different options relative to one another
should not matter, unless the options are documented as
mutually-exclusive and such an option is documented to override any
incompatible options preceding it. If an option that has
option-arguments is repeated, the option and option-argument
combinations should be interpreted in the order specified on the
command line.
The only place where ordering those is important is on documentation:
- Options are usually listed in alphabetical order unless this would make the utility description more confusing. There are no implied
relationships between the options based upon the order in which they
appear, unless otherwise stated in the OPTIONS section, or unless the
exception in Guideline 11 of Utility Syntax Guidelines applies. If an
option that does not have option-arguments is repeated, the results
are undefined, unless otherwise stated.
However, if you have a command where an argument does not need an option, and another that does, you can group with only one -
symbol, since the argument with options comes after the one who doesn't:
Guideline 5:
One or more options without option-arguments, followed by
at most one option that takes an option-argument, should be accepted
when grouped behind one '-' delimiter.
Since POSIX is a standard, it's up to the programmers of a technology to make it compliant or not, and how to handle option_arguments. You could make a non-POSIX argparse Python program with the following code:
>>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='-+')
>>> parser.add_argument('+f')
>>> parser.add_argument('++bar')
This way, your program arguments will start with +
, not being POSIX when confronted with Guideline 4:
Guideline 4:
All options should be preceded by the '-' delimiter character.
And about ordering, is just a matter of using the .parse_args()
function to decide where your arguments will be pinned to a position. To argparse lib, there is no operand. Everything is an argument. An operand here is just an argument without the -
character, and again, is up to the programmer decide if the software being made will be POSIX compilant or not.
If implemented on the right way, argparse is itself POSIX compliant. Suggested reading:
- argparse – Command line option and argument parsing
Related Stuff:
ls foo bar
andls bar foo
are equivalent. What aboutcp foo bar
andcp bar foo
— what do you think? – Scott - Слава Україні Apr 01 '15 at 13:46