What is the standard practice for making rm -rf "file", rm -fr "file", and rm "file" -rf all work as valid commands?
A lot of people disagree on that, so there seems to be no standard practice, unless you're targetting a specific audience (i.e. when writing a linux-specific command-line tool, check out what "standard" utilities do).
In any case, most libraries end up given you the following options:
- Switches: these isolated flags in that no argument is expected after the switch. Unix tools such as
tar
and rm
often allow you to specify multiple flags together just as in your example's -rf
flags.
- Options: these are specified like switches but expect some value after the switch.
gcc
, for instance, expects the output file's name after -o
. Because they expect options, they may obviously not be specified simultaneously.
- Short VS long names: switches and options typically have two names a single dash, single letter or double-dash descriptive name (compare
-o
and --output-file
) although some options, such as help or verbosity control, often have only a long name.
- Multiple trailing arguments: if the tool allows to process simultaneous files at once, these are all specified at the end of the sequence only. Allowing these to be interleaved with other options and flags would lead to a nightmare. A
--
option to indicate "end of options" is also convenient in case some of those trailing arguments may contain dashes.
A lot of tools allow switches and options to be interleaved, but multiple trailing arguments are always at the end.
Of course, you will find commonly used tools that don't respect these conventions, such as Microsoft's cl.exe
and link.exe
. More recent tools seem to converge towards these though, including Microsoft's candle.exe
and light.exe
for WIX.
If you want to make sure you respect these guidelines (and save a lot of time), use a "standard" library, such as UNIX's getopt()
or boost's program options.
Edit: existing libraries often generate the --help
option for you using the short descriptions you give when you specify the switches and options you are expecting.