3.1.2.3 Switches

For those of you who are not satisfied with short and long forms, Clon provides a specific option type for Boolean values, along with an additional call syntax. These options are called switches.

Just like any other kind of valued option, a switch can have a short and/or a long name, and its argument may be mandatory or optional. However, the possible arguments for a switch are restricted to true or false. In fact, you can freely use ‘yes’, ‘on’, ‘true’, ‘yup’, ‘yeah’ and ‘no’, ‘off’, ‘false’, ‘nope’, ‘nah’ respectively.2

In addition to the standard short and long forms, a switch can be provided in negated form, that is, by appending its short name behind a ‘+’ character. This form never takes any argument and always means false (turn the switch off, if you prefer).

Although an application might do something different, the intended usage for switches is to take an optional argument that defaults to true. A typical example would look like this in a standard help string (but see Output):

  -(+)d, --debug[=yes/no]    Whether to enable debugging.

Given such an option, you can turn debugging on by saying just ‘-d’ or ‘--debug’ (but you can also provide an explicit argument like this: ‘-dyes’ or that: ‘--debug=yes’). Similarly, to turn debugging off, use ‘+d’ or ‘--debug=no’.

One last word about switches: Clon lets application developers create new options based on (but not limited to) switches. These options typically accept Boolean arguments as well as some other value(s). As soon as an option is switch-based (and has a short name), the negated form becomes automatically available, and this should be advertised in the application’s help string.


Footnotes

(2)

If you want more, a very modest additional fee will be charged.