Khepera III Toolbox/The Toolbox/Modules/commandline

The commandline module parses command line values and provides a simple interface for accessing the values. The module expects the command line arguments to consist of
 * options with exactly one value (key-value pairs), e.g. -s 10000 or --speed 10000
 * options without value (just keys), e.g. -h or --help
 * an argument list, holding all values that were provided without a key

As an example, the command line would result in one key (--white-floor), one key-value pair (--speed 15000) and three arguments (10, 12, <tt>10</tt>).

Description
commandline_register_option registers an option with a specific type. By default (for all options that are not explicitly registered), an option is of type <tt> cCommandLine_Option_Value</tt> and "eats" the next command line argument. E.g. the command line: would be parsed as one key-value pair (<tt>--white-floor 15</tt>) by default. If <tt>--white-floor</tt> is registered as <tt>cCommandLine_Option</tt>, however, the same line will be parsed as one option (<tt>--white-floor</tt>) and one argument (<tt>15</tt>).

Once all necessary options have been registered, commandline_parse can be called to parse the command line. Subsequently, the function commandline_option_value and its _int and _float versions can be used to access option value, while commandline_option_provided returns whether the option has occurred on the command line or not. To access the arguments, commandline_argument and its _int and _float versions are available. The index must be smaller than the number returned by commandline_argument_count.

Option Hooks
Alternatively, a program can register a hook with an option: The hook function will be called each time the corresponding option appears on the command line. Note that the function will be invoked more than once if the user provides the same option multiple times.