The whereiseveryone.command-line-args Reference Manual

This is the whereiseveryone.command-line-args Reference Manual, version 0.1.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 08:05:46 2024 GMT+0.

Table of Contents


1 Introduction


2 Systems

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


2.1 whereiseveryone.command-line-args

Automatically create a command-line-argument parser for a given Common Lisp function definition.

Author

Jorge & Charles

Contact

Home Page

https://git.sr.ht/~whereiseveryone/command-line-args

Source Control

https://git.sr.ht/~whereiseveryone/command-line-args

License

AGPL v3 or any later version

Long Description

Command-Line-Args provides a main macro (‘command’) that wraps a ‘defun’ form and creates a new function that parses the command line arguments. It has support for command-line options, positoinal, and variadic arguments. It also generates a basic help message. The interface is meant to be easy and non-intrusive.

Version

0.1.1

Dependencies
  • alexandria (system).
  • serapeum (system).
  • str (system).
  • charje.documentation (system).
  • trivia (system).
Source

whereiseveryone.command-line-args.asd.

Child Components

3 Files

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


3.1 Lisp


3.1.1 whereiseveryone.command-line-args/whereiseveryone.command-line-args.asd

Source

whereiseveryone.command-line-args.asd.

Parent Component

whereiseveryone.command-line-args (system).

ASDF Systems

whereiseveryone.command-line-args.


3.1.3 whereiseveryone.command-line-args/conditions.lisp

Dependency

package.lisp (file).

Source

whereiseveryone.command-line-args.asd.

Parent Component

whereiseveryone.command-line-args (system).

Public Interface
Internals

3.1.4 whereiseveryone.command-line-args/command-line-args.lisp

Dependency

conditions.lisp (file).

Source

whereiseveryone.command-line-args.asd.

Parent Component

whereiseveryone.command-line-args (system).

Public Interface
Internals

4 Packages

Packages are listed by definition order.


4.1 whereiseveryone.command-line-args

Source

package.lisp.

Use List

common-lisp.

Public Interface
Internals

4.2 whereiseveryone.command-line-args.user

Source

package.lisp.

Use List

common-lisp.


5 Definitions

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


5.1 Public Interface


5.1.1 Macros

Macro: command (defun)

Define a function that parses the command line arguments for and then calls the funciton defined by DEFUN.

DEFUN: A typical ‘defun’ form. It is evaluated to define the function as usual.

The new function generated will be the same as the function defined by the DEFUN with a -command suffix. Feel free to use this for the entry-point of your executable or script.

‘&key’ parameters become command line options. These are parsed first, before required parameters. Each option will have a long form and a short form (if it is not already taken by another parameter). The long form is the whole name of the parameter preceded by 2 hyphens. The short form is the first letter of the parameter preceded by a single hyphen. In either case the option and the actual argument are separated by a space on the command line. The short flag customized by using a ‘flag’ declaration as follows:

(command
(defun custom-short-flag (&key some-option)
(declare (flag #o some-option))
...)

That will make it so that the -o option argument is the ‘some-option’ argument.

Most keyword parameters will take an argument. Using ‘parse-boolean’ as a parser for a parameter makes it not take an argument. If the command line option is not present the value will be ‘nil’, else if it is present it will be the number of time the command line option appeared.

For a variadic parameter, do not use ‘&rest’. Instead declare the parser like so:

(command
(defun variadic-function (variadic-param)
(declare (parser (list parse-integer) variadic-param))
...))

That will a variable number of integer from the command line arguments. Note only the last positional argument can be variadic. To have a variadic parameter without any special parser (just plain strings) use the following parser:

(declare (parser (list identity) variadic-parameter)).

Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Macro: subcommand-case (subcommand &body subcommands)

Use for a command to dispatch onto another command by the first argument. If SUBCOMMAND matches any of the symbol-names (lowercased) of the CASES, call the related command.

SUBCOMMAND: The user provided variable which selects which subcommand to execute. It should be the one and only positional argument for comamnds where ‘subcommand-case’ is used. It should be raw user input and not mutated or cleaned up at all.

SUBCOMMANDS: A list of function names all of which should be defined inside of a ‘command’.

You may be tempted to just use your own ‘cond’, but using using ‘subcommand-case’ will ensure that documentation is generated for your subcommands.

When SUBCOMMAND does not match any of SUBCOMMANDS, an ‘invalid-subcommand’ is signaled. You can handle this condition to customize the behavior of a mismatched subcommand.

Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.


5.1.2 Ordinary functions

Function: parse-boolean (arg)

Parse ARG as a shell Boolean. Only return ‘t’ for non empty strings.

ARG: The thing to be parsed. Parsing will not be attempted for non-strings.

Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.


5.1.3 Generic functions

Generic Reader: combined-flag (condition)
Package

whereiseveryone.command-line-args.

Methods
Reader Method: combined-flag ((condition invalid-combined-short-flag))
Source

conditions.lisp.

Target Slot

combined-flag.

Generic Reader: flag (condition)
Package

whereiseveryone.command-line-args.

Methods
Reader Method: flag ((condition invalid-flag))
Source

conditions.lisp.

Target Slot

flag.

Generic Reader: maximum-number-of-args (condition)
Package

whereiseveryone.command-line-args.

Methods
Reader Method: maximum-number-of-args ((condition wrong-number-of-args))
Source

conditions.lisp.

Target Slot

maximum-number-of-args.

Generic Reader: minimum-number-of-args (condition)
Package

whereiseveryone.command-line-args.

Methods
Reader Method: minimum-number-of-args ((condition wrong-number-of-args))
Source

conditions.lisp.

Target Slot

minimum-number-of-args.

Generic Reader: number-of-args-supplied (condition)
Package

whereiseveryone.command-line-args.

Methods
Reader Method: number-of-args-supplied ((condition wrong-number-of-args))
Source

conditions.lisp.

Target Slot

number-of-args-supplied.

Generic Reader: parser (condition)
Package

whereiseveryone.command-line-args.

Methods
Reader Method: parser ((condition invalid-variadic-parser))
Source

conditions.lisp.

Target Slot

bad-parser.

Generic Reader: subcommand (condition)
Package

whereiseveryone.command-line-args.

Methods
Reader Method: subcommand ((condition invalid-subcommand))
Source

conditions.lisp.

Target Slot

subcommand.


5.1.4 Conditions

Condition: command-line-condition

The parent conditio for the ‘whereiseveryone.command-line-args’ system.

Package

whereiseveryone.command-line-args.

Source

conditions.lisp.

Direct superclasses

condition.

Direct subclasses
Condition: invalid-combined-short-flag

This is when the user of the command line provides an invalid flag that in the form of a combined short flag: (-abcd) where a, b, c, and d are all different arguments and one of them is not valid for this command.

Package

whereiseveryone.command-line-args.

Source

conditions.lisp.

Direct superclasses

invalid-flag.

Direct methods

combined-flag.

Direct slots
Slot: combined-flag

The combined short flag the contains the invalid flag.

Initargs

:combined-flag

Readers

combined-flag.

Writers

This slot is read-only.

Condition: invalid-flag

This is when a user of the command line tried to provide a command line option that this command has not been defined to handle.

Package

whereiseveryone.command-line-args.

Source

conditions.lisp.

Direct superclasses
Direct subclasses

invalid-combined-short-flag.

Direct methods

flag.

Direct slots
Slot: flag

The flag that the user of the command line provided.

Initargs

:flag

Readers

flag.

Writers

This slot is read-only.

Condition: invalid-subcommand

This is when the user of the command line provides a subcommand that doesn’t match any of the subcommands.

Package

whereiseveryone.command-line-args.

Source

conditions.lisp.

Direct superclasses
Direct methods

subcommand.

Direct slots
Slot: subcommand

The user supplied subcommand that does not match any of the subcommands that this command is designed to handle.

Initargs

:subcommand

Readers

subcommand.

Writers

This slot is read-only.

Condition: invalid-variadic-parser

This is when the programmer declares variadic parser for a parameter which cannot be variadic due to its position in the lambda-list.

Package

whereiseveryone.command-line-args.

Source

conditions.lisp.

Direct superclasses
Direct methods
Direct slots
Slot: parameter

The parameter that was declared as variadic but cannot be for whatever reason.

Initargs

:param

Readers

param.

Writers

This slot is read-only.

Slot: bad-parser

The declared parser for ‘parameter’.

Initargs

:parser

Readers

parser.

Writers

This slot is read-only.

Condition: keyword-argument-too-short

This is when the programmer defines a function with a keyword parameter whos argument is too short. Very short keyword arguments get confusing when it comes to short options versus long options.

Package

whereiseveryone.command-line-args.

Source

conditions.lisp.

Direct superclasses
Direct methods

arg.

Direct slots
Slot: arg

The keyword argument defined as part of the lambda-list.

Initargs

:supplied

Readers

arg.

Writers

This slot is read-only.

Condition: rest-used-for-variadic

This is when ‘&rest’ is used in the ‘command’ macro. There is no sane way to map the Common Lisp concept of ‘&rest’ to the shell concept of variadic arguments. This is because the Common Lisp ‘&rest’ includes the keyword arguments.

Package

whereiseveryone.command-line-args.

Source

conditions.lisp.

Direct superclasses
Direct methods
Direct slots
Slot: parameter-name

The name of the ‘&rest’ parameter.

Initargs

:parameter-name

Readers

parameter-name.

Writers

This slot is read-only.

Slot: parser-name

The parser declared for the ‘&rest’ parameter.

Initargs

:parser-name

Readers

parser-name.

Writers

This slot is read-only.

Condition: wrong-number-of-args

This is when the user of the command line provided too few or too many arguments for this command to handle.

Package

whereiseveryone.command-line-args.

Source

conditions.lisp.

Direct superclasses
Direct methods
Direct slots
Slot: number-of-args-supplied

The number of arguments supplied by the user of the command line tool at run time.

Initargs

:supplied

Readers

number-of-args-supplied.

Writers

This slot is read-only.

Slot: minimum-number-of-args

The minimum number of positional arguments that this command can take.

Initargs

:min

Readers

minimum-number-of-args.

Writers

This slot is read-only.

Slot: maximum-number-of-args

The maximum number of positional arguments that this command can take. ‘nil’ indicates that there is no maximum and the command can take any number of positional arguments greater or equal to the ‘minimum-number-of-args’.

Initform

(quote nil)

Initargs

:max

Readers

maximum-number-of-args.

Writers

This slot is read-only.


5.2 Internals


5.2.1 Special variables

Special Variable: *command-line-args*
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Special Variable: *command-line-invocation*
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.


5.2.2 Macros

Macro: increment-boolean-counter (param)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.


5.2.3 Ordinary functions

Function: check-variadic-parameter-parser (parsers required-params optional-params keyword-params)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: combined-short-flags-p (flag)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: commandify (s)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: flag-match-p (short-form long-form flag)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: flagp (thing)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: generate-argument-parser (command-line-args parsers parameter-name)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: generate-check-argument-lengths (variadicp command-line-args required-params optional-params)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: generate-help (flag-overrides docstring subcommand-cases required-params required-variadic optional-params optional-variadic keyword-params)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: generate-keyword-args-parser (command-line-args parsers flag-overrides keyword-params)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: help-time-p (command-line-args)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: last-parameter (required-params optional-params)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: parse-flag-declarations (declarations)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: parse-optional-args-let-bindings (command-line-args parsers optional-params)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: parse-parser-declarations (declarations)

Parse all the custom parser declarations.

DECLARATIONS: A list of all the declare forms.
Returns a hash table where the keys are the names of the function parameters and the values are the names of the parser functions.

Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: parse-required-args-let-bindings (command-line-args parsers required-params)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: print-paragraph (string &optional out)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: short-form-flag (flag-mapping arg-keyword parameter)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.

Function: subcommand-cases (code)
Package

whereiseveryone.command-line-args.

Source

command-line-args.lisp.


5.2.4 Generic functions

Generic Reader: arg (condition)
Package

whereiseveryone.command-line-args.

Methods
Reader Method: arg ((condition keyword-argument-too-short))
Source

conditions.lisp.

Target Slot

arg.

Generic Reader: param (condition)
Package

whereiseveryone.command-line-args.

Methods
Reader Method: param ((condition invalid-variadic-parser))
Source

conditions.lisp.

Target Slot

parameter.

Generic Reader: parameter-name (condition)
Package

whereiseveryone.command-line-args.

Methods
Reader Method: parameter-name ((condition rest-used-for-variadic))
Source

conditions.lisp.

Target Slot

parameter-name.

Generic Reader: parser-name (condition)
Package

whereiseveryone.command-line-args.

Methods
Reader Method: parser-name ((condition rest-used-for-variadic))
Source

conditions.lisp.

Target Slot

parser-name.


Appendix A Indexes


A.1 Concepts


A.2 Functions

Jump to:   A   C   F   G   H   I   L   M   N   P   S  
Index Entry  Section

A
arg: Private generic functions
arg: Private generic functions

C
check-variadic-parameter-parser: Private ordinary functions
combined-flag: Public generic functions
combined-flag: Public generic functions
combined-short-flags-p: Private ordinary functions
command: Public macros
commandify: Private ordinary functions

F
flag: Public generic functions
flag: Public generic functions
flag-match-p: Private ordinary functions
flagp: Private ordinary functions
Function, check-variadic-parameter-parser: Private ordinary functions
Function, combined-short-flags-p: Private ordinary functions
Function, commandify: Private ordinary functions
Function, flag-match-p: Private ordinary functions
Function, flagp: Private ordinary functions
Function, generate-argument-parser: Private ordinary functions
Function, generate-check-argument-lengths: Private ordinary functions
Function, generate-help: Private ordinary functions
Function, generate-keyword-args-parser: Private ordinary functions
Function, help-time-p: Private ordinary functions
Function, last-parameter: Private ordinary functions
Function, parse-boolean: Public ordinary functions
Function, parse-flag-declarations: Private ordinary functions
Function, parse-optional-args-let-bindings: Private ordinary functions
Function, parse-parser-declarations: Private ordinary functions
Function, parse-required-args-let-bindings: Private ordinary functions
Function, print-paragraph: Private ordinary functions
Function, short-form-flag: Private ordinary functions
Function, subcommand-cases: Private ordinary functions

G
generate-argument-parser: Private ordinary functions
generate-check-argument-lengths: Private ordinary functions
generate-help: Private ordinary functions
generate-keyword-args-parser: Private ordinary functions
Generic Function, arg: Private generic functions
Generic Function, combined-flag: Public generic functions
Generic Function, flag: Public generic functions
Generic Function, maximum-number-of-args: Public generic functions
Generic Function, minimum-number-of-args: Public generic functions
Generic Function, number-of-args-supplied: Public generic functions
Generic Function, param: Private generic functions
Generic Function, parameter-name: Private generic functions
Generic Function, parser: Public generic functions
Generic Function, parser-name: Private generic functions
Generic Function, subcommand: Public generic functions

H
help-time-p: Private ordinary functions

I
increment-boolean-counter: Private macros

L
last-parameter: Private ordinary functions

M
Macro, command: Public macros
Macro, increment-boolean-counter: Private macros
Macro, subcommand-case: Public macros
maximum-number-of-args: Public generic functions
maximum-number-of-args: Public generic functions
Method, arg: Private generic functions
Method, combined-flag: Public generic functions
Method, flag: Public generic functions
Method, maximum-number-of-args: Public generic functions
Method, minimum-number-of-args: Public generic functions
Method, number-of-args-supplied: Public generic functions
Method, param: Private generic functions
Method, parameter-name: Private generic functions
Method, parser: Public generic functions
Method, parser-name: Private generic functions
Method, subcommand: Public generic functions
minimum-number-of-args: Public generic functions
minimum-number-of-args: Public generic functions

N
number-of-args-supplied: Public generic functions
number-of-args-supplied: Public generic functions

P
param: Private generic functions
param: Private generic functions
parameter-name: Private generic functions
parameter-name: Private generic functions
parse-boolean: Public ordinary functions
parse-flag-declarations: Private ordinary functions
parse-optional-args-let-bindings: Private ordinary functions
parse-parser-declarations: Private ordinary functions
parse-required-args-let-bindings: Private ordinary functions
parser: Public generic functions
parser: Public generic functions
parser-name: Private generic functions
parser-name: Private generic functions
print-paragraph: Private ordinary functions

S
short-form-flag: Private ordinary functions
subcommand: Public generic functions
subcommand: Public generic functions
subcommand-case: Public macros
subcommand-cases: Private ordinary functions


A.4 Data types

Jump to:   C   F   I   K   P   R   S   W  
Index Entry  Section

C
command-line-args.lisp: The whereiseveryone․command-line-args/command-line-args․lisp file
command-line-condition: Public conditions
Condition, command-line-condition: Public conditions
Condition, invalid-combined-short-flag: Public conditions
Condition, invalid-flag: Public conditions
Condition, invalid-subcommand: Public conditions
Condition, invalid-variadic-parser: Public conditions
Condition, keyword-argument-too-short: Public conditions
Condition, rest-used-for-variadic: Public conditions
Condition, wrong-number-of-args: Public conditions
conditions.lisp: The whereiseveryone․command-line-args/conditions․lisp file

F
File, command-line-args.lisp: The whereiseveryone․command-line-args/command-line-args․lisp file
File, conditions.lisp: The whereiseveryone․command-line-args/conditions․lisp file
File, package.lisp: The whereiseveryone․command-line-args/package․lisp file
File, whereiseveryone.command-line-args.asd: The whereiseveryone․command-line-args/whereiseveryone․command-line-args․asd file

I
invalid-combined-short-flag: Public conditions
invalid-flag: Public conditions
invalid-subcommand: Public conditions
invalid-variadic-parser: Public conditions

K
keyword-argument-too-short: Public conditions

P
Package, whereiseveryone.command-line-args: The whereiseveryone․command-line-args package
Package, whereiseveryone.command-line-args.user: The whereiseveryone․command-line-args․user package
package.lisp: The whereiseveryone․command-line-args/package․lisp file

R
rest-used-for-variadic: Public conditions

S
System, whereiseveryone.command-line-args: The whereiseveryone․command-line-args system

W
whereiseveryone.command-line-args: The whereiseveryone․command-line-args system
whereiseveryone.command-line-args: The whereiseveryone․command-line-args package
whereiseveryone.command-line-args.asd: The whereiseveryone․command-line-args/whereiseveryone․command-line-args․asd file
whereiseveryone.command-line-args.user: The whereiseveryone․command-line-args․user package
wrong-number-of-args: Public conditions