Option Parsing: Boolean Options

Options as Flags

Most options require an option argument. Some options take an optional argument. Then there are the options that take no argument at all. These are the “flag” options - the option value is either set or unset.

Options with no arguments may only be defined on boolean properties. Consider this program, which defines two options (a and b) that do not take arguments, and a third option (c) which takes a required argument:

This is a deliberate departure from the behavior of GNU’s getopt. Short option runs with arguments are not readable and may cause compatibility problems when the options change.

Inverse Aliases

Some programs prefer the ability to specify an “on” and an “off” version for the same option. This can be easily done by having the boolean properties share a single backing value, with the “off” version inverting its value. These are very similar to aliases, except that they mean the opposite instead of the same.