Since Clon
lets you retrieve options on demand (at any time), it
makes sense to be able to request the value of a specific option
explicitely. For instance, you might want to try the ‘--help’
option first, without looking at the rest of the command-line because the
application will in fact quit immediately after having displayed the
help string.
Retrieve the value of a specific option. The following :KEYs are currently available.
:short-name
:long-name
¶Use one of these 2 keys to specify the name of the option you wish to retrieve.
:option
¶Alternatively, you can use a reference to an option object (see Constructors).
This function return two values: the option’s value and the value’s source (see Value Sources in The Clon End-User Manual).
The value’s source may have the following forms:
(:cmdline NAME)
¶This is for options found on the command-line. NAME is the name used
on the command-line. It can be the option’s long or short name, or a
completed long name if the option’s name was abbreviated. A completed
name displays the omitted parts in parentheses ("he(lp)"
for
instance).
(:fallback NAME)
¶The same but when the fallback value is used, that is, when an option is not provided with its (optional) argument.
(:default NAME)
¶The same, but when the default value is used (because there is no fallback).
(:environment VAR)
¶This is for options not found on the command-line but for which there is an associated environment variable set in the application’s environment. VAR is the name of the corresponding environment variable.
:default
¶This is for options not found anywhere, but for which a default value was provided.
Note that because flags don’t take any argument, getopt
returns a
virtual value of t
when they are found or a corresponding
environment variable exists in the environment. For the same reason, a
flag’s value source may ony be (:cmdline NAME)
or
(:environment VAR)
.
When an option is not found anywhere and there is no default value,
getopt
just returns nil (no second value). Also, note that when
your option accepts nil
as a value, you need to handle the
second retrun value to make the difference between an option not found,
and an actual value of nil
.