The cli-parser Reference Manual

This is the cli-parser Reference Manual, version 0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 04:45:53 2024 GMT+0.

Table of Contents


1 Systems

The main system appears first, followed by any subsystem dependency.


1.1 cli-parser

A command-line argument parser. Mostly parses options of the same form that getopt parses

Author

Denis Bueno

License

Copyright (c) 2005

Version

0.1

Source

cli-parser.asd.

Child Component

cli-parser.lisp (file).


2 Files

Files are sorted by type and then listed depth-first from the systems components trees.


2.1 Lisp


2.1.1 cli-parser/cli-parser.asd

Source

cli-parser.asd.

Parent Component

cli-parser (system).

ASDF Systems

cli-parser.


2.1.2 cli-parser/cli-parser.lisp

Source

cli-parser.asd.

Parent Component

cli-parser (system).

Packages

cli-parser.

Public Interface
Internals

3 Packages

Packages are listed by definition order.


3.1 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.

Source

cli-parser.lisp.

Use List
  • common-lisp.
  • common-lisp-user.
Public Interface
Internals

4 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


4.1 Public Interface


4.1.1 Ordinary functions

Function: cli-formatted-options (option-list)
Package

cli-parser.

Source

cli-parser.lisp.

Function: cli-parse (args cli-opts)

See CLI-PARSE-HASH.

Package

cli-parser.

Source

cli-parser.lisp.

Function: 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)).

Package

cli-parser.

Source

cli-parser.lisp.

Function: 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.

Package

cli-parser.

Source

cli-parser.lisp.

Function: cli-usage (command-name options-list)

Print the command line usage

Package

cli-parser.

Source

cli-parser.lisp.


4.1.2 Generic functions

Generic Reader: cli-option-abbr (object)
Package

cli-parser.

Methods
Reader Method: cli-option-abbr ((cli-option cli-option))

automatically generated reader method

Source

cli-parser.lisp.

Target Slot

abbreviation.

Generic Writer: (setf cli-option-abbr) (object)
Package

cli-parser.

Methods
Writer Method: (setf cli-option-abbr) ((cli-option cli-option))

automatically generated writer method

Source

cli-parser.lisp.

Target Slot

abbreviation.

Generic Reader: cli-option-description (object)
Package

cli-parser.

Methods
Reader Method: cli-option-description ((cli-option cli-option))

automatically generated reader method

Source

cli-parser.lisp.

Target Slot

description.

Generic Writer: (setf cli-option-description) (object)
Package

cli-parser.

Methods
Writer Method: (setf cli-option-description) ((cli-option cli-option))

automatically generated writer method

Source

cli-parser.lisp.

Target Slot

description.

Generic Reader: cli-option-example (object)
Package

cli-parser.

Methods
Reader Method: cli-option-example ((cli-option cli-option))

automatically generated reader method

Source

cli-parser.lisp.

Target Slot

example.

Generic Writer: (setf cli-option-example) (object)
Package

cli-parser.

Methods
Writer Method: (setf cli-option-example) ((cli-option cli-option))

automatically generated writer method

Source

cli-parser.lisp.

Target Slot

example.

Generic Reader: cli-option-full (object)
Package

cli-parser.

Methods
Reader Method: cli-option-full ((cli-option cli-option))

automatically generated reader method

Source

cli-parser.lisp.

Target Slot

longname.

Generic Writer: (setf cli-option-full) (object)
Package

cli-parser.

Methods
Writer Method: (setf cli-option-full) ((cli-option cli-option))

automatically generated writer method

Source

cli-parser.lisp.

Target Slot

longname.

Generic Reader: cli-option-requires-arguments (object)
Package

cli-parser.

Methods
Reader Method: cli-option-requires-arguments ((cli-option cli-option))

automatically generated reader method

Source

cli-parser.lisp.

Target Slot

argumentsp.

Generic Writer: (setf cli-option-requires-arguments) (object)
Package

cli-parser.

Methods
Writer Method: (setf cli-option-requires-arguments) ((cli-option cli-option))

automatically generated writer method

Source

cli-parser.lisp.

Target Slot

argumentsp.


4.1.3 Standalone methods

Method: print-object ((o cli-option) stream)
Source

cli-parser.lisp.


4.1.4 Classes

Class: cli-option
Package

cli-parser.

Source

cli-parser.lisp.

Direct methods
Direct slots
Slot: abbreviation
Type

(or null string)

Initargs

:abbr

Readers

cli-option-abbr.

Writers

(setf cli-option-abbr).

Slot: longname
Type

string

Initargs

:full

Readers

cli-option-full.

Writers

(setf cli-option-full).

Slot: argumentsp
Type

(member nil t :optional)

Initargs

:requires-arguments

Readers

cli-option-requires-arguments.

Writers

(setf cli-option-requires-arguments).

Slot: description
Type

string

Initform

"default description."

Initargs

:description

Readers

cli-option-description.

Writers

(setf cli-option-description).

Slot: example
Type

string

Initargs

:example

Readers

cli-option-example.

Writers

(setf cli-option-example).


4.2 Internals


4.2.1 Special variables

Special Variable: *double-dash*

Long option prefix.

Package

cli-parser.

Source

cli-parser.lisp.

Special Variable: *for-example-text*

String used to display for example.

Package

cli-parser.

Source

cli-parser.lisp.

Special Variable: *option-value-sep*

String used to separate option values.

Package

cli-parser.

Source

cli-parser.lisp.

Special Variable: *single-dash*

Short option prefix.

Package

cli-parser.

Source

cli-parser.lisp.


4.2.2 Macros

Macro: pprint-clos-class (instance slots stream &key inter-slot-newline-style intra-slot-newline-style unbound-msg slot-value-callback)

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>>

Package

cli-parser.

Source

cli-parser.lisp.


4.2.3 Ordinary functions

Function: 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.

Package

cli-parser.

Source

cli-parser.lisp.

Function: abbr-opt-p (opt)

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

Package

cli-parser.

Source

cli-parser.lisp.

Function: cli-parse-assoc-aux (args results)

Helper for cli-parse.

Package

cli-parser.

Source

cli-parser.lisp.

Function: cli-parse-hash-aux (args cli-opts)
Package

cli-parser.

Source

cli-parser.lisp.

Function: 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" ...).

Package

cli-parser.

Source

cli-parser.lisp.

Function: coalesce-options-aux (args results)

Helper for coalesce-options.

Package

cli-parser.

Source

cli-parser.lisp.

Function: 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"

Package

cli-parser.

Source

cli-parser.lisp.

Function: formatted-option-string (option)
Package

cli-parser.

Source

cli-parser.lisp.

Function: full-opt-p (opt)

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

Package

cli-parser.

Source

cli-parser.lisp.

Function: 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.

Package

cli-parser.

Source

cli-parser.lisp.

Function: opt-p (opt)

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

Package

cli-parser.

Source

cli-parser.lisp.

Function: 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.

Package

cli-parser.

Source

cli-parser.lisp.

Function: 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.

Package

cli-parser.

Source

cli-parser.lisp.

Function: 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.

Package

cli-parser.

Source

cli-parser.lisp.

Function: 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.

Package

cli-parser.

Source

cli-parser.lisp.

Function: string-tokenize (str val-separators &key include-separators)

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.

Package

cli-parser.

Source

cli-parser.lisp.

Function: string-tokenize-aux (str val-separators vals include-separators)

Helper for string-tokenize.

Package

cli-parser.

Source

cli-parser.lisp.

Function: to-full-opt-name (argname cli-opts)

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

Package

cli-parser.

Source

cli-parser.lisp.

Function: to-full-opt-names (cl-args cli-opts)

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

Package

cli-parser.

Source

cli-parser.lisp.


Appendix A Indexes


A.1 Concepts


A.2 Functions

Jump to:   (  
A   C   E   F   G   M   O   P   S   T  
Index Entry  Section

(
(setf cli-option-abbr): Public generic functions
(setf cli-option-abbr): Public generic functions
(setf cli-option-description): Public generic functions
(setf cli-option-description): Public generic functions
(setf cli-option-example): Public generic functions
(setf cli-option-example): Public generic functions
(setf cli-option-full): Public generic functions
(setf cli-option-full): Public generic functions
(setf cli-option-requires-arguments): Public generic functions
(setf cli-option-requires-arguments): Public generic functions

A
abbr->full-opt-name: Private ordinary functions
abbr-opt-p: Private ordinary functions

C
cli-formatted-options: Public ordinary functions
cli-option-abbr: Public generic functions
cli-option-abbr: Public generic functions
cli-option-description: Public generic functions
cli-option-description: Public generic functions
cli-option-example: Public generic functions
cli-option-example: Public generic functions
cli-option-full: Public generic functions
cli-option-full: Public generic functions
cli-option-requires-arguments: Public generic functions
cli-option-requires-arguments: Public generic functions
cli-parse: Public ordinary functions
cli-parse-assoc: Public ordinary functions
cli-parse-assoc-aux: Private ordinary functions
cli-parse-hash: Public ordinary functions
cli-parse-hash-aux: Private ordinary functions
cli-usage: Public ordinary functions
coalesce-options: Private ordinary functions
coalesce-options-aux: Private ordinary functions

E
end-opt-name: Private ordinary functions

F
formatted-option-string: Private ordinary functions
full-opt-p: Private ordinary functions
Function, abbr->full-opt-name: Private ordinary functions
Function, abbr-opt-p: Private ordinary functions
Function, cli-formatted-options: Public ordinary functions
Function, cli-parse: Public ordinary functions
Function, cli-parse-assoc: Public ordinary functions
Function, cli-parse-assoc-aux: Private ordinary functions
Function, cli-parse-hash: Public ordinary functions
Function, cli-parse-hash-aux: Private ordinary functions
Function, cli-usage: Public ordinary functions
Function, coalesce-options: Private ordinary functions
Function, coalesce-options-aux: Private ordinary functions
Function, end-opt-name: Private ordinary functions
Function, formatted-option-string: Private ordinary functions
Function, full-opt-p: Private ordinary functions
Function, opt-name: Private ordinary functions
Function, opt-p: Private ordinary functions
Function, opt-values: Private ordinary functions
Function, st-closest-val: Private ordinary functions
Function, st-first-val: Private ordinary functions
Function, st-rest-of: Private ordinary functions
Function, string-tokenize: Private ordinary functions
Function, string-tokenize-aux: Private ordinary functions
Function, to-full-opt-name: Private ordinary functions
Function, to-full-opt-names: Private ordinary functions

G
Generic Function, (setf cli-option-abbr): Public generic functions
Generic Function, (setf cli-option-description): Public generic functions
Generic Function, (setf cli-option-example): Public generic functions
Generic Function, (setf cli-option-full): Public generic functions
Generic Function, (setf cli-option-requires-arguments): Public generic functions
Generic Function, cli-option-abbr: Public generic functions
Generic Function, cli-option-description: Public generic functions
Generic Function, cli-option-example: Public generic functions
Generic Function, cli-option-full: Public generic functions
Generic Function, cli-option-requires-arguments: Public generic functions

M
Macro, pprint-clos-class: Private macros
Method, (setf cli-option-abbr): Public generic functions
Method, (setf cli-option-description): Public generic functions
Method, (setf cli-option-example): Public generic functions
Method, (setf cli-option-full): Public generic functions
Method, (setf cli-option-requires-arguments): Public generic functions
Method, cli-option-abbr: Public generic functions
Method, cli-option-description: Public generic functions
Method, cli-option-example: Public generic functions
Method, cli-option-full: Public generic functions
Method, cli-option-requires-arguments: Public generic functions
Method, print-object: Public standalone methods

O
opt-name: Private ordinary functions
opt-p: Private ordinary functions
opt-values: Private ordinary functions

P
pprint-clos-class: Private macros
print-object: Public standalone methods

S
st-closest-val: Private ordinary functions
st-first-val: Private ordinary functions
st-rest-of: Private ordinary functions
string-tokenize: Private ordinary functions
string-tokenize-aux: Private ordinary functions

T
to-full-opt-name: Private ordinary functions
to-full-opt-names: Private ordinary functions