chickadee » args » args:parse

args:parse ARGS OPTIONS-LIST #!optional OPTIONALSprocedure

Parse ARGS, a list of command-line arguments given as strings, and return two values: an alist of option names (symbols) and their values, and a list of operands (non-option arguments).

Operands are returned in order, but options are returned in reverse order. Duplicate options are retained in the options alist, so this lets assq find the last occurrence of any duplicate option on the command line. A (name . value) pair is added for each alias of every option found, so any alias is a valid lookup key.

OPTIONS-LIST is a list of accepted options, each created by args:make-option.

OPTIONALS is an optional sequence of keywords and values:

#:operand-proc PROCcalls PROC for each operand, with arguments OPERAND OPTIONS OPERANDS. PROC must return the next seeds, (values OPTIONS OPERANDS).
#:unrecognized-proc PROCcalls PROC for each unrecognized option, with arguments OPTION NAME ARG OPTIONS OPERANDS

The default operand-proc is a no-op, and the default unrecognized-proc issues an error message and calls the help option's processor. See the args-fold documentation for usage information and an explanation of the procedure arguments; OPTIONS and OPERANDS are seed values.