Common Lisp Package: CLI-PARSER

Used for command-line-interface parsing, in the same tradition as getopt, but, a bit more convenient. The three main functions are: * CLI-PARSE * CLI-PARSE-HASH * CLI-PARSE-ASSOC CLI-PARSE actually just calls CLI-PARSE-HASH, which will parse a list of command-line arguments against a list of CLI-OPTION objects. CLI-PARSE-ASSOC, instead of returning a hash table of results like CLI-PARSE-HASH does, returns an assoc list of results. The idea is that you create a bunch of cli-option instances (via MAKE-CLI-OPTION) which represent all of the valid options the user may pass in to your program. The actual options passed in (as a list of strings, one for each option) along with the list of valid options are passed to cli-parse, which will give you a table of mappings, from the option to the setting specified by the user.

README:

FUNCTION

Public

CLI-PARSE (ARGS CLI-OPTS)

See CLI-PARSE-HASH.

CLI-PARSE-ASSOC (ARGS CLI-OPTS)

Parses command-line arguments much in the same format as the cl-args that getopt() parses. That is, if you call any program with: './prgm --opt1=value1 value2 -n', and you give "--opt1=value1", "value2" and "-n" to cli-parse-assoc, it returns and assoc-list of the form (("opt1" ("value1" "value2")) ("n" nil)).

CLI-PARSE-HASH (ARGS CLI-OPTS)

Parses command-line arguments in the same form as specified for CLI-PARSE-ASSOC, but returns a hash-table of the results, instead of an assoc list.

CLI-USAGE (COMMAND-NAME OPTIONS-LIST)

Print the command line usage

Undocumented

CLI-FORMATTED-OPTIONS (OPTION-LIST)

Private

ABBR->FULL-OPT-NAME (OPT CLI-OPTS)

Converts an abbreviated option (i.e. "o") to its corresponding full option name. Returns the argument if no conversion is performed.

ABBR-OPT-P (OPT)

Test whether opt is a short option of the form "-o[=val]"

CLI-PARSE-ASSOC-AUX (ARGS RESULTS)

Helper for cli-parse.

COALESCE-OPTIONS (ARGS)

Will convert a list of the form ("--option-name=val1[,]" "val2[,]" " ... "valn" ...) to a list of the form ("--option-name=val1 val2 val3" ...).

COALESCE-OPTIONS-AUX (ARGS RESULTS)

Helper for coalesce-options.

END-OPT-NAME (OPT)

Returns the index of the end of the option-name. For example, end-opt-name would return 6 for the option "--opt1=val1"

FULL-OPT-P (OPT)

Test whether opt is a long option of the form "--opt[=val]"

OPT-NAME (OPT)

Extract the name of an option: for example "opt1" is the name from "--opt1=val1". Will return the argument if it is neither.

OPT-P (OPT)

Evaluates to true if opt is an abbreviated or a full option.

OPT-VALUES (OPT)

Extract the values of an option: for example "val1" is the value from "--opt1=val1". If no values are specified, this function returns nil.

ST-CLOSEST-VAL (STR VAL-SEPARATORS)

Returns the character in the string which both matches any of the val-separators and minimizes the distance between it and the index 0 of the string. If there is no match, returns the length of the string.

ST-FIRST-VAL (STR VAL-SEPARATORS)

Returns the first token by parsing str. Analagous to car, but for the string tokenizer, instead of for lists.

ST-REST-OF (STR VAL-SEPARATORS)

Returns the rest of the string, not including the first token. Analagous to cdr, but for the string tokenizer, instead of for lists.

STRING-TOKENIZE (STR VAL-SEPARATORS &KEY (INCLUDE-SEPARATORS NIL))

Breaks up a given string into string components by splitting the string every time an element of val-separator is encountered. Returns a list of strings, which are all the tokens. If include-separators is non-nil, the separators themselves will be included in the parse.

STRING-TOKENIZE-AUX (STR VAL-SEPARATORS VALS INCLUDE-SEPARATORS)

Helper for string-tokenize.

TO-FULL-OPT-NAME (ARGNAME CLI-OPTS)

Convert an option name to the full one, if necessary. Change "o" to "outfile", for example.

TO-FULL-OPT-NAMES (CL-ARGS CLI-OPTS)

Converts any abbreviated option list of command-line options to the full option name.

Undocumented

CLI-PARSE-HASH-AUX (ARGS CLI-OPTS)

FORMATTED-OPTION-STRING (OPTION)

MACRO

Private

PPRINT-CLOS-CLASS (INSTANCE SLOTS STREAM &KEY (INTER-SLOT-NEWLINE-STYLE LINEAR) (INTRA-SLOT-NEWLINE-STYLE FILL) (UNBOUND-MSG <unbound>) (SLOT-VALUE-CALLBACK '(LAMBDA (A1 A2) (DECLARE (IGNORE A1)) A2)))

Pretty print the SLOTS of a CLOS class INSTANCE, to STREAM. INTER-SLOT-NEWLINE-STYLE and INTRA-SLOT-NEWLINE-STYLE may be any value appropriate appropriate as the first argument to PPRINT-NEWLINE. A newline of INTER-SLOT-NEWLINE-STYLE will be printed between each of the slot-name/slot-value pairs of each slot in SLOTS. A newline of INTRA-SLOT-NEWLINE-STYLE will be printed between the slot-name and the slot-value of each slot in SLOTS. UNBOUND-MSG should be a string which will be printed as the slot-value for any slot in INSTANCE which is unbound. SLOT-VALUE-CALLBACK should be a function of two arguments, the slot-name and the slot-value, which should return an object which will be printed in place of the slot-value for slot-name. Example: > (defclass foo () (a b)) #<STANDARD-CLASS FOO> > (defmethod cl:print-object ((f foo) stream) (pprint-clos-class f (a b) stream)) #<STANDARD-METHOD PRINT-OBJECT (FOO T) {4865E569}> > (make-instance 'foo) #<FOO :A <unbound> :B <unbound>> > (setf (slot-value * 'a) 'bar) BAR > ** #<FOO :A BAR :B <unbound>>

SLOT-ACCESSOR

Public

Undocumented

CLI-OPTION-ABBR (OBJECT)

SETFCLI-OPTION-ABBR (NEW-VALUE OBJECT)

CLI-OPTION-DESCRIPTION (OBJECT)

SETFCLI-OPTION-DESCRIPTION (NEW-VALUE OBJECT)

CLI-OPTION-EXAMPLE (OBJECT)

SETFCLI-OPTION-EXAMPLE (NEW-VALUE OBJECT)

CLI-OPTION-FULL (OBJECT)

SETFCLI-OPTION-FULL (NEW-VALUE OBJECT)

CLI-OPTION-REQUIRES-ARGUMENTS (OBJECT)

SETFCLI-OPTION-REQUIRES-ARGUMENTS (NEW-VALUE OBJECT)

VARIABLE

Private

*DOUBLE-DASH*

Long option prefix.

*FOR-EXAMPLE-TEXT*

String used to display for example.

*OPTION-VALUE-SEP*

String used to separate option values.

*SINGLE-DASH*

Short option prefix.

CLASS

Public

Undocumented

CLI-OPTION