chickadee » args » args:make-option

(args:make-option (OPTION-NAME ...) ARG-DATA DOCSTRING [BODY])syntax

Make an args:option record, suitable for passing to args:parse.

OPTION-NAME ... is a sequence of short or long option names. They must be literal symbols; single-character symbols become short options, and longer symbols become long options. So (args:make-option (c cookie) ...) specifies a short option -c and long option --cookie. Under the hood, (c cookie) becomes '(#\c "cookie"), as expected by SRFI 37's OPTION.

ARG-DATA is either a pair (ARG-TYPE ARG-NAME) or a plain keyword ARG-TYPE. ARG-TYPE is a keyword that specifies whether the option takes an argument:

#:requiredArgument is required
#:optionalArgument is optional
#:noneNo argument (actually, any other value than #:required or #:optional is interpreted as #:none)

ARG-NAME, if provided, is a string specifying the name of the argument. This name is used in the help text produced by args:usage.

DOCSTRING is the help text.

BODY is an optional sequence of statements executed when this option is encountered. BODY is an option-processor as defined in SRFI 37, and has access to the variables OPT (the current #<option>), NAME (the option name) and ARG (argument value).

Behind the scenes, BODY is wrapped in code which adds the current option NAME and its argument ARG to the final options alist. So, simply leave BODY blank and options will be collected for you.

When the option takes no argument (is of type #:none) then ARG is #t, turning it into a boolean. On the other hand, when the option takes an optional argument that is omitted, then ARG is #f; so to set a default of foo, one may say in the body:

(set! arg (or arg "foo"))