Package COM.INFORMATIMAGO.COMMON-LISP.UNIX.OPTION


This package processes command line options.

Example:

        (defvar *force-execution* nil)

        (define-option ("-f" "--force" "force") ()
           "Force execution"
           (setf *force-execution* t))

        (defun main (arguments)
            (parse-options arguments)
            (when *force-execution* (do-it))
            (ext:exit ex-ok))

        (main ext:*args*)

License:

    AGPL3
    
    Copyright Pascal J. Bourguignon 2012 - 2012
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
    
    You should have received a copy of the GNU Affero General Public License
    along with this program.
    If not, see <http://www.gnu.org/licenses/>

*bash-completion-hook*
variable
A function (lambda (index words) ...)
that will print the completion and return true, or do nothing and return nil.
Initial value: NIL
*debug-options*
variable
Errors break into the debugger.
Initial value: NIL
*documentation-text*
variable
Some general documentation text issued by the --help command.
Initial value:
*program-name*
variable
Name of the program.
If available we use the actual command line program name,
otherwise we fallback to *PROGRAM-NAME*.
Initial value: unnamed
(call-option-function option arguments undefined-argument case-sensitive)
generic-function
DO:                  Call the option function with the ARGUMENTS.
RETURN:              The remaining list of arguments.
UNDEFINED-ARGUMENT:  A function taking an option key and the remaining
                     list of arguments, called if an undefined
                     argument is found in ARGUMENTS.  It should return
                     the new remaining list of arguments.
(define-option names parameters &body body)
macro
DO:         Define a new option for the scirpt.
NAMES:      A list designator of option names (strings
            such as "-a" "--always").
PARAMETERS: A list of option parameters.  The names of
            these parameters must be descriptive as they
            are used to build the usage help text.
BODY:       The code implementing this option.
RETURN:     The lisp-name of the option (this is a symbol
            named for the first option name).
ex--base
constant
base value for error messages
Initial value: 64
ex--max
constant
maximum listed value
Initial value: 78
ex-cantcreat
constant
can't create (user) output file
A (user specified) output file cannot be created.
Initial value: 73
ex-config
constant
configuration error
Initial value: 78
ex-dataerr
constant
data format error
The input data was incorrect in some way.
This should only be used for user's data & not
system files.
Initial value: 65
ex-ioerr
constant
input/output error
An error occurred while doing I/O on some file.
Initial value: 74
ex-nohost
constant
host name unknown
The host specified did not exist.  This is used
in mail addresses or network requests.
Initial value: 68
ex-noinput
constant
cannot open input
An input file (not a system file) did not
exist or was not readable.  This could also include
errors like "No message" to a mailer (if it cared
to catch it).
Initial value: 66
ex-noperm
constant
permission denied
You did not have sufficient permission to
perform the operation.  This is not intended for
file system problems, which should use NOINPUT or
CANTCREAT, but rather for higher level permissions.
Initial value: 77
ex-nouser
constant
addressee unknown
The user specified did not exist.  This might
be used for mail addresses or remote logins.
Initial value: 67
ex-ok
constant
successful termination
Initial value: 0
ex-oserr
constant
system error (e.g., can't fork)
An operating system error has been detected.
This is intended to be used for such things as "cannot
fork", "cannot create pipe", or the like.  It includes
things like getuid returning a user that does not
exist in the passwd file.
Initial value: 71
ex-osfile
constant
critical OS file missing
Some system file (e.g., /etc/passwd, /etc/utmp,
etc.) does not exist, cannot be opened, or has some
sort of error (e.g., syntax error).
Initial value: 72
ex-protocol
constant
remote error in protocol
the remote system returned something that
was "not possible" during a protocol exchange.
Initial value: 76
ex-software
constant
internal software error
An internal software error has been detected.
This should be limited to non-operating system related
errors as possible.
Initial value: 70
ex-tempfail
constant
temp failure; user is invited to retry
temporary failure, indicating something that
is not really an error.  In sendmail, this means
that a mailer (e.g.) could not create a connection,
and the request should be reattempted later.
Initial value: 75
ex-unavailable
constant
service unavailable
A service is unavailable.  This can occur
if a support program or file does not exist.  This
can also be used as a catchall message when something
you wanted to do doesn't work, but you don't know
why.
Initial value: 69
ex-usage
constant
command line usage error
The command was used incorrectly, e.g., with
the wrong number of arguments, a bad flag, a bad
syntax in a parameter, or whatever.
Initial value: 64
(option-arguments option)
function
A lambda-list of option arguments.
(option-documentation option)
function
The documentation of the option (a string).
(option-function option)
function
The option function.
(option-keys option)
function
A list of option keys.
(option-list)
function
RETURN: The list of options defined.
(parse-options arguments &optional default undefined-argument case-sensitive)
function
DO:                 Parse the options in the ARGUMENTS list.
DEFAULT:            Thunk called if ARGUMENTS is empty.
UNDEFINED-ARGUMENT: Thunk called if an undefined option is present in
                    the ARGUMENTS.
RETURN:             NIL on success, status code when early exit is requested.
parse-options-finish
condition
Condition signaled to finish the parsing of options early.
Class precedence list: PARSE-OPTIONS-FINISH CONDITION STANDARD-OBJECT T
Class init args: STATUS-CODE
(parse-options-finish status-code)
function
Signals the PARSE-OPTIONS-FINISH condition, which terminates option parsing early.
(pname)
function
This function can be used to set *program-name* in
the main script  (setf script:*program-name* (script:pname))
(redirecting-stdout-to-stderr &body body)
macro
Execute BODY with the *standard-output*, *error-output*, and
*trace-output* redirected.  If an error occurs in BODY, then all the
redirected output is sent to *error-output*.