Managing command line options

Managing command line options –
how to add options to the parser and use them.

Some background

Options are used to provide extra information to tune or customize the
execution of a program. In case it wasn't clear, options are usually
optional. A program should be able to run just fine with no options
whatsoever. Pick a random program from the Unix or GNU toolsets. Can it
run without any options at all and still make sense? The main exceptions
are find, tar, and dd--all of which are mutant oddballs that have been
rightly criticized for their non-standard syntax and confusing
interfaces.

Lots of people want their programs to have "required options". Think
about it. If it's required, then it's not optional! If there is a piece
of information that your program absolutely requires in order to run
successfully, that's what arguments are for.

As an example of good command-line interface design, consider the humble
cp utility, for copying files. It doesn't make much sense to try to copy
files without supplying a destination and at least one source. Hence, cp
fails if you run it with no arguments. However, it has a flexible, useful
syntax that does not require any options at all:

$ cp SOURCE DEST
$ cp SOURCE ... DEST-DIR

You can get pretty far with just that. Most cp implementations provide a
bunch of options to tweak exactly how the files are copied: you can
preserve mode and modification time, avoid following symlinks, ask before
clobbering existing files, etc. But none of this distracts from the core
mission of cp, which is to copy either one file to another, or several
files to another directory.

Help

This action tells the parser to display the help message if it
encounters the option in the command line, most of the time you won't
need this since it is handled by
Console_CommandLine
internally.

Version

This action tells the parser to display the program version if it
encounters the option in the command line, as for Help action, chances
are that you won't need this since it is handled by
Console_CommandLine
internally.

Password

This action allows the user to either type the password on the
commandline or to be prompted for it (will not echo on unix systems),
some examples: