Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the utility-arguments Reference Manual, version 0.161029, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Aug 15 06:07:18 2022 GMT+0.
Next: Systems, Previous: The utility-arguments Reference Manual, Up: The utility-arguments Reference Manual [Contents][Index]
Utility Arguments is a Common Lisp software that handles command-line arguments. The adopted argument syntax is described in the POSIX and the GNU conventions.
Real notion of a usage, which allows Utility Arguments to automatically select a suitable usage for operands and options.
Robust in parsing command-line arguments. Utility Arguments doesn't trip on spaces in option specifications, and options are not required to appear before operands.
Lispy feel. Lambda lists describe the operands and options a usage binds — this idea was taken from Command Line Arguments.
No auto-generated documentation for operands, options, and usages; because it would be hard to produce a style which pleases all eyes.
Utility Arguments is hosted on Gitlab.com. The master branch points to the most recent release.
The easiest way to install Utility Arguments is through Quicklisp.
Alternatively, either download a tarball from the project's website or
clone the Git repository. Put the source code where ASDF can find it.
The system utility-arguments
can then be loaded and compiled.
Utility arguments are formatted strings that conform to the POSIX and the GNU argument syntax conventions. To summarize it here: Option specifications start with one or two hyphens followed by alphanumeric characters. Everything that is not an option specification is an operand. A double hyphen terminates options, i.e., everything to the right of it is considered an operand.
Commonly, the utility arguments will be the arguments received on the
command-line. To retrieve the command-line arguments in a portable
way, use the function uiop:command-line-arguments
.
A usage, which is defined with the macro defusage
, can be thought of
as a Lisp function applicable to a set of utility arguments. Its
positional and keyword parameters receive the values of operands and
options. Type parsing can be requested through objects handed over to
the function apply-usage
; otherwise, a string trimmed of white space
at both ends is passed as value.
Usages are applied to utility arguments with the function
apply-usage
. Among other arguments, it receives two lists of
operand and option objects that complement the parameters on usage
lambda lists in providing additional type and syntactic information.
A usage is applicable to a set of utility arguments if there is a correlated parameter for each operand and option, and if all parameters are satisfied on the usage lambda list.
Symbols exported from the package utility-arguments
comprise the API
and are documented by their docstrings. The examples below cover the
majority of the API.
In this example we create the outline for a hypothetical encryption utility to demonstrate how to use Utility Arguments.
We devise usages to encrypt and decrypt files. The usages are
implemented with the macro defusage
. Positional parameters on the
first lambda list describe operands, and keyword parameters on the
second lambda list describe options. Parameters receive the values of
operands and options.
(defusage encrypt ((infile &optional outfile)
(&key encrypt (algorithm 'aes) (keysize 256)))
(declare (ignore encrypt))
;; code...
)
(defusage decrypt ((infile &optional outfile)
(&key decrypt algorithm keysize))
(declare (ignore decrypt))
;; code...
)
For the encryption usage we made algorithm
and keysize
optional
options by specifying an init-form for the keyword parameters.
We have no real use for the encrypt
and decrypt
parameters inside
the body of the usages; however, they are essential for the usages to
be distinguishable from each other.
We create operand objects that complement the positional parameters on the usage lambda lists. Correlation is established by option key and parameter name. For type we pass a function object instead of a Lisp type specifier, which gives us full control over the received argument.
(defun probe-infile (string designator)
(when (not (uiop:probe-file* string))
(warn "File ~s specified for ~a does not exist." string designator))
string)
(defun probe-outfile (string designator)
(when (uiop:probe-file* string)
(warn "File ~s specified for ~a does already exist." string designator))
string)
(defparameter *operands*
(list (make-operand :key 'infile :type #'probe-infile)
(make-operand :key 'outfile :type #'probe-outfile)))
We create option objects that complement the keyword parameters on the usage lambda lists. Correlation is established by option key and parameter name. Different kind of options are available. We specify key, short and long designators, and for options that receive an argument a Lisp type specifier. For type parsing, the Lisp reader is used.
(defparameter *options*
(list (make-option-flag
:key :encrypt :short #\e :long "encrypt")
(make-option-flag
:key :decrypt :short #\d :long "decrypt")
(make-option-with-argument
:key :algorithm :short #\a :long "algorithm" :type '(or (eql aes) (eql des)))
(make-option-with-argument
:key :keysize :short #\s :long "keysize" :type '(integer 128))))
We apply the usages to utility arguments with the function
apply-usage
. The next two examples succeed.
(apply-usage '(encrypt decrypt) *operands* *options*
(list "--encrypt" "secret.txt" "secret.enc"))
(apply-usage '(encrypt decrypt) *operands* *options*
(list "--decrypt" "secret.enc" "-aAES" "--keysize=256"))
This example signals a utility-argument-error
condition, because we
didn't make any provisions for an option --help
.
(apply-usage '(encrypt decrypt) *operands* *options*
(list "--help"))
This example signals a usage-error
condition, because we did not
devise such usage. We need at least an input-file operand for this to
succeed.
(apply-usage '(encrypt decrypt) *operands* *options*
(list "--encrypt"))
The reason defusage
takes two lambda lists instead of one is to
allow for a rest parameter to be specified for operands and options
each, like in the next example.
(defusage foo ((&rest ints)
(&rest options &key x &allow-other-keys))
;; code...
)
To successfully apply the usage, we need to provide the option x
.
Additionally any other option and integer operands are accepted.
(apply-usage '(foo)
(list (make-operand :key 'ints :type ' (integer * 0)))
(list (make-option-flag :key :x :short #\x)
(make-option-flag :key :y :short #\y))
(list "-xy" "--" "-3" "-7"))
Next: Files, Previous: Introduction, Up: The utility-arguments Reference Manual [Contents][Index]
The main system appears first, followed by any subsystem dependency.
Utility to handle command-line arguments.
Frank A. U.
ICS
0.161029
alexandria (system).
Next: Packages, Previous: Systems, Up: The utility-arguments Reference Manual [Contents][Index]
Files are sorted by type and then listed depth-first from the systems components trees.
Next: utility-arguments/packages.lisp, Previous: Lisp, Up: Lisp [Contents][Index]
utility-arguments (system).
Next: utility-arguments/utils.lisp, Previous: utility-arguments/utility-arguments.asd, Up: Lisp [Contents][Index]
utility-arguments (system).
Next: utility-arguments/error.lisp, Previous: utility-arguments/packages.lisp, Up: Lisp [Contents][Index]
packages.lisp (file).
utility-arguments (system).
Next: utility-arguments/option.lisp, Previous: utility-arguments/utils.lisp, Up: Lisp [Contents][Index]
utils.lisp (file).
utility-arguments (system).
Next: utility-arguments/parser.lisp, Previous: utility-arguments/error.lisp, Up: Lisp [Contents][Index]
error.lisp (file).
utility-arguments (system).
Next: utility-arguments/operand.lisp, Previous: utility-arguments/option.lisp, Up: Lisp [Contents][Index]
option.lisp (file).
utility-arguments (system).
*separator* (special variable).
Next: utility-arguments/usage.lisp, Previous: utility-arguments/parser.lisp, Up: Lisp [Contents][Index]
parser.lisp (file).
utility-arguments (system).
Previous: utility-arguments/operand.lisp, Up: Lisp [Contents][Index]
operand.lisp (file).
utility-arguments (system).
Next: Definitions, Previous: Files, Up: The utility-arguments Reference Manual [Contents][Index]
Packages are listed by definition order.
Next: Indexes, Previous: Packages, Up: The utility-arguments Reference Manual [Contents][Index]
Definitions are sorted by export status, category, package, and then by lexicographic order.
Next: Internals, Previous: Definitions, Up: Definitions [Contents][Index]
Next: Macros, Previous: Public Interface, Up: Public Interface [Contents][Index]
Character that separates the arguments in a sequence. Setting it to nil, disables separation.
Next: Ordinary functions, Previous: Special variables, Up: Public Interface [Contents][Index]
Define a new usage for operands and options.
NAME is a symbol and denotes the name of the usage.
OPERAND-LAMBDA-LIST describes operands. It resembles a lambda list
with required, optional, or rest parameter specifiers as the only
elements allowed. The parameters receive the operands’ values.
OPTION-LAMBDA-LIST describes options. It resembles a lambda list with
keyword and rest parameter specifiers as the only elements allowed.
The parameters receive the options’ values.
Optional and keyword parameter that specify an init-form make it
optional in this usage.
The forms of BODY are executed when the usage is applied.
Next: Generic functions, Previous: Macros, Up: Public Interface [Contents][Index]
Apply a usage to utility arguments.
USAGES is a list of symbols naming usages defined with defusage.
The lists OPERANDS and OPTIONS hold objects that complement the
parameters on usage lambda lists in providing additional type and
syntactic information. Correlation is established by object key and
parameter name.
UTILITY-ARGUMENTS is a list of strings that is parsed into operands
and options. The operand and options are matched against the usage
lambda lists to find a suitable usage which is then applied to the
operand’s and option’s values.
An error condition of utility-argument-error, no-such-usage, or usage-conflict may be signaled.
Find operand identifiable by KEY.
KEY is a symbol. OPERANDS is a list of operand objects.
Make a new operand.
KEY is a symbol that correlates the operand with a positional
parameter on a usage lambda list.
The parameter TYPE is documented in make-option-with-argument.
Make a new option flag.
Its number of appearances on a utility argument list is the assumed
value.
The parameters KEY, SHORT, and LONG are documented in make-option-with-argument.
Make a new option that receives one argument.
KEY is a symbol that correlates the option with a keyword parameter on
a usage lambda list.
SHORT is a case-sensitive character. LONG is a case-insensitive but
case-preserving string. Both designators are equivalent and request
the option on a utility argument list. At least one of the two must
be specified.
TYPE is a Lisp type specifier the object must conform to the Lisp
reader builds from the received argument. The built object becomes
the assumed value.
TYPE is a function of two string arguments: the first of which is the received argument for the option, and the second the designator that requested the option. The object returned becomes the assumed value.
TYPE is nil, the received argument is the assumed value.
Make a new option that optionally receives one argument.
If the option doesn’t receive an argument, nil is assumed.
The parameters KEY, SHORT, LONG, and TYPE are documented in make-option-with-argument.
Make a new option that optionally receives a sequence of arguments.
If the option doesn’t receive an argument, nil is assumed. See also
make-option-with-sequence.
The parameters KEY, SHORT, LONG, and TYPE are documented in make-option-with-argument.
Make a new option that receives a sequence of arguments.
Multiple arguments in a sequence are separated from each other by the
separator registered with *separator*.
Received arguments are subject to type parsing as described in
make-option-with-argument. The assumed values are collected into a
list by order of utility arguments.
The parameters KEY, SHORT, LONG, and TYPE are documented in make-option-with-argument.
Next: Standalone methods, Previous: Ordinary functions, Up: Public Interface [Contents][Index]
Find option identifiable by ITEM.
ITEM is either a symbol, character, or a string. OPTIONS is a list of option objects.
Next: Conditions, Previous: Generic functions, Up: Public Interface [Contents][Index]
Previous: Standalone methods, Up: Public Interface [Contents][Index]
Condition signaled if no suitable usage was found.
:utility-arguments
This slot is read-only.
Condition signaled if more than one suitable usage was found.
:usages
This slot is read-only.
Condition signaled for usage related errors.
error.
Condition signaled for utility argument related errors, such as bad syntax, unknown options, or type errors.
error.
:text
This slot is read-only.
Previous: Public Interface, Up: Definitions [Contents][Index]
Next: Generic functions, Previous: Internals, Up: Internals [Contents][Index]
Next: Classes, Previous: Ordinary functions, Up: Internals [Contents][Index]
text.
Previous: Generic functions, Up: Internals [Contents][Index]
Previous: Definitions, Up: The utility-arguments Reference Manual [Contents][Index]
Jump to: | A B C D E F G I L M N O P S T U |
---|
Jump to: | A B C D E F G I L M N O P S T U |
---|
Next: Data types, Previous: Functions, Up: Indexes [Contents][Index]
Jump to: | *
K L S T U |
---|
Jump to: | *
K L S T U |
---|
Jump to: | C E F N O P S U |
---|
Jump to: | C E F N O P S U |
---|