Constructor initializes the command line to be parsed. All information for parsing must be supplied to this constructor.
Multiple short options can be combined as long as only the last one can takes an argument. For example, if optstring is defined as
|argc ||The number of argv elements to parse. |
|argv ||Command line tokens, such as would be passed to |
|optstring ||Nul-terminated string containing the legitimate short option characters. A single colon ":" following an option character means the option requires an argument. A double colon "::" following an option character means the argument is optional. The argument is taken from the rest of the current argv element, or from the following argv element (only valid for required arguments; optional arguments must always reside in the same argv element). The argument value, if any is returned by the |
opt_arg() method. optstring can be extended by adding long options with corresponding short options via the
long_option() method. If the short option already appears in optstring, the argument characteristics must match, otherwise it is added. See
long_option() for more information. If 'W', followed by a semi-colon ';' appears in optstring, then any time a 'W' appears on the command line, the following argument is treated as a long option. For example, if the command line contains "program -W foo", "foo" is treated as a long option, that is, as if "program --foo" had been passed. The following characters can appear in optstring before any option characters, with the described effect:
- '+' changes the ordering to REQUIRE_ORDER.
- '-' changes the ordering to RETURN_IN_ORDER.
- ':' changes the return value from
operator() and get_opt() from '?' to ':' when an option requires an argument but none is specified.
|skip_args ||Optional (default 1). The specified number of initial elements in argv are skipped before parsing begins. Thus, the default prevents argv (usually the command name) from being parsed. argc includes all argv elements, including any skipped elements. |
|report_errors ||Optional, if non-zero then parsing errors cause an error message to be displayed from the |
operator() method before it returns. The error message is suppressed if this argument is 0. This setting also controls whether or not an error message is displayed in
long_option() encounters an error.
|ordering ||Optional (default is |
PERMUTE_ARGS); determines how the argv elements are processed. This argument is overridden by two factors:
POSIXLY_CORRECT environment variable. If this environment variable is set, the ordering is changed to
- Leading characters in optstring (see above). Any leading ordering characters override both the ordering argument and any effect of the
POSIXLY_CORRECT environment variable.
|long_only ||Optional. If non-zero, then long options can be specified using a single '-' on the command line. If the token is not a long option, it is processed as usual, that is, as a short option or set of short options.|
"abc::" then the command line "program -abcxxx" short options a, b, and c are found with "xxx" as the argument for c. However, if the command line is specified as "program -acb" only options a and c are found with "b" as the argument for c. Also, for options with optional arguments, that is, those followed by "::", the argument must be in the same argv element, so "program -abc xxx" will only find "xxx" as the argument for c if optstring is specified as