The clingon Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

The clingon Reference Manual

This is the clingon Reference Manual, version 0.3.5, generated automatically by Declt version 4.0 beta 2 "William Riker" on Thu Sep 15 04:23:41 2022 GMT+0.

Table of Contents


1 Introduction

* clingon

=clingon= is a command-line options parser system for Common Lisp.

A summary of the features supported by =clingon= is provided below.

- Native support for sub-commands
- Support for command aliases
- Short and long option names support
- Related options may be grouped into categories
- Short options may be collapsed as a single argument, e.g. =-xyz=
- Long options support both notations - =--long-opt arg= and
  =--long-opt=arg=.
- Automatic generation of help/usage information for commands and
  sub-commands
- Out of the box support for =--version= and =--help= flags
- Support for various kinds of options like /string/, /integer/,
  /boolean/, /switches/, /enums/, /list/, /counter/, /filepath/, etc.
- Sub-commands can lookup global options and flags defined in parent
  commands
- Support for options, which may be required
- Options can be initialized via environment variables
- Single interface for creating options using =CLINGON:MAKE-OPTION=
- Generate documentation for your command-line app
- Support for =pre-hook= and =post-hook= actions for commands, which
  allows invoking functions before and after the respective handler of
  the command is executed
- Support for Bash and Zsh shell completions
- =clingon= is extensible, so if you don't find something you need you
  can extend it by developing a new option kind, or even new mechanism
  for initializing options, e.g. by looking up an external key/value
  store.

Scroll to the demo section in order to see some examples of =clingon=
in action.

Other Common Lisp option parser systems, which you might consider
checking out.

- [[https://github.com/libre-man/unix-opts][unix-opts]]
- [[https://github.com/sjl/adopt/][adopt]]
- [[https://github.com/didierverna/clon][clon]]

* Quick Example

Here's a really quick example of a simple CLI application, which
greets people.

#+begin_src lisp
(in-package :cl-user)
(defpackage :clingon.example.greet
  (:use :cl)
  (:import-from :clingon)
  (:export
   :main))
(in-package :clingon.example.greet)

(defun greet/options ()
  "Returns the options for the `greet' command"
  (list
   (clingon:make-option
    :string
    :description "Person to greet"
    :short-name #\u
    :long-name "user"
    :initial-value "stranger"
    :env-vars '("USER")
    :key :user)))

(defun greet/handler (cmd)
  "Handler for the `greet' command"
  (let ((who (clingon:getopt cmd :user)))
    (format t "Hello, ~A!~%" who)))

(defun greet/command ()
  "A command to greet someone"
  (clingon:make-command
   :name "greet"
   :description "greets people"
   :version "0.1.0"
   :authors '("John Doe  (ql:register-local-projects)
#+end_src

** Building the Demo App

You can build the demo app using SBCL with the following command.

#+begin_src shell
LISP=sbcl make demo
#+end_src

Build the demo app using Clozure CL:

#+begin_src shell
LISP=ccl make demo
#+end_src

In order to build the demo app using ECL you need to follow these
instructions, which are ECL-specific. See [[https://common-lisp.net/project/ecl/static/manual/System-building.html#Compiling-with-ASDF][Compiling with ASDF from the
ECL manual]] for more details. First, load the =:clingon.demo= system.

#+begin_src lisp
(ql:quickload :clingon.demo)
#+end_src

And now build the binary with ECL:

#+begin_src lisp
(asdf:make-build :clingon.demo
                 :type :program
                 :move-here #P"./"
                 :epilogue-code '(clingon.demo:main))
#+end_src

This will create a new executable =clingon-demo=, which you can now
execute.

Optionally, you can also enable the bash completions support.

#+begin_src shell
APP=clingon-demo source extras/completions.bash
#+end_src

In order to activate the Zsh completions, install the completions
script in your =~/.zsh-completions= directory (or anywhere else you
prefer) and update your =~/.zshrc= file, so that the completions are
loaded.

Make sure that you have these lines in your =~/.zshrc= file.

#+begin_src shell
  fpath=(~/.zsh-completions $fpath)
  autoload -U compinit
  compinit
#+end_src

The following command will generate the Zsh completions script.

#+begin_src shell
  ./clingon-demo zsh-completion > ~/.zsh-completions/_clingon-demo
#+end_src

Use the =--help= flag to see some usage information about the demo
application.

#+begin_src shell
./clingon-demo --help
#+end_src

* Requirements

- [[https://www.quicklisp.org/beta/][Quicklisp]]

* Installation

The =clingon= system is not yet part of Quicklisp, so for now
you need to install it in your local Quicklisp projects.

Clone the repo in your [[https://www.quicklisp.org/beta/faq.html][Quicklisp local-projects]] directory.

#+begin_src lisp
(ql:register-local-projects)
#+end_src

Then load the system.

#+begin_src lisp
(ql:quickload :clingon)
#+end_src

* Step By Step Guide

In this section we will implement a simple CLI application, and
explain at each step what and why we do the things we do.

Once you are done with it, you should have a pretty good understanding
of the =clingon= system and be able to further extend the sample
application on your own.

We will be developing the application interactively and in the
REPL. Finally we will create an ASDF system for our CLI app, so we can
build it and ship it.

The code we develop as part of this section will reside in a file
named =intro.lisp=. Anything we write will be sent to the Lisp REPL, so
we can compile it and get quick feedback about the things we've done
so far.

You can find the complete code we'll develop in this section in the
=clingon/examples/intro= directory.

** Start the REPL

Start up your REPL session and let's load the =clingon= system.

#+begin_src lisp
CL-USER> (ql:quickload :clingon)
To load "clingon":
  Load 1 ASDF system:
    clingon
; Loading "clingon"

(:CLINGON)
#+end_src

** Create a new package

First, we will define a new package for our application and switch to
it.

#+begin_src lisp
(in-package :cl-user)
(defpackage :clingon.intro
  (:use :cl)
  (:import-from :clingon)
  (:export :main))
(in-package :clingon.intro)
#+end_src

We have our package, so now we can proceed to the next section and
create our first command.

** Creating a new command

The first thing we'll do is to create a new command. Commands are
created using the =CLINGON:MAKE-COMMAND= function.

Each command has a name, description, any options that
the command accepts, any sub-commands the command knows about, etc.

The command in =clingon= is represented by the =CLINGON:COMMAND=
class, which contains many other slots as well, which you can lookup.

#+begin_src lisp
(defun top-level/command ()
  "Creates and returns the top-level command"
  (clingon:make-command
   :name "clingon-intro"
   :description "my first clingon cli app"
   :version "0.1.0"
   :license "BSD 2-Clause"
   :authors '("John Doe ")))
#+end_src

This is how our simple command looks like. For now it doesn't do much,
and in fact it won't execute anything, but we will fix that as we go.

What is important to note, is that we are using a convention here
to make things easier to understand and organize our code base.

Functions that return new commands will be named =/command=.  A
similar approach is taken when we define options for a given command,
e.g. =/options= and for sub-commands we use
=/sub-commands=. Handlers will use the =/handler=
notation.

This makes things easier later on, when we introduce new sub-commands,
and when we need to wire things up we can refer to our commands using
the established naming convention. Of course, it's up to you to decide
which approach to take, so feel free to adjust the layout of the code
to your personal preferences. In this guide we will use the afore
mentioned approach.

Commands can be linked together in order to form a tree of commands
and sub-commands. We will talk about that one in more details in the
later sections of this guide.

** Adding options

Next, we will add a couple of options. Similar to the previous section
we will define a new function, which simply returns a list of valid
options. Defining it in the following way would make it easier to
re-use these options later on, in case you have another command, which
uses the exact same set of options.

=clingon= exposes a single interface for creating options via the
=CLINGON:MAKE-OPTION= generic function. This unified interface will
allow developers to create and ship new option kinds, and still have
their users leverage a common interface for the options via the
=CLINGON:MAKE-OPTION= interface.

#+begin_src lisp
(defun top-level/options ()
  "Creates and returns the options for the top-level command"
  (list
   (clingon:make-option
    :counter
    :description "verbosity level"
    :short-name #\v
    :long-name "verbose"
    :key :verbose)
   (clingon:make-option
    :string
    :description "user to greet"
    :short-name #\u
    :long-name "user"
    :initial-value "stranger"
    :env-vars '("USER")
    :key :user)))
#+end_src

Let's break things down a bit and explain what we just did.

We've defined two options -- one of =:COUNTER= kind and another one,
which is of =:STRING= kind. Each option specifies a short and long
name, along with a description of what the option is meant for.

Another important thing we did is to specify a =:KEY= for our options.
This is the key which we will later use in order to get the value
associated with our option, when we use =CLINGON:GETOPT=.

And we have also defined that our =--user= option can be initialized
via environment variables. We can specify multiple environment variables,
if we need to, and the first one that resolves to something will be used
as the initial value for the option.

If none of the environment variables are defined, the option will be
initialized with the value specified by the =:INITIAL-VALUE= initarg.

Before we move to the next section of this guide we will update the
definition of our =TOP-LEVEL/COMMAND= function, so that we include our
options.

#+begin_src lisp
(defun top-level/command ()
  "Creates and returns the top-level command"
  (clingon:make-command
   :name "clingon-intro"
   ...
   :usage "[-v] [-u ]"      ;; <- new code
   :options (top-level/options))) ;; <- new code
#+end_src

** Defining a handler

A /handler/ in =clingon= is a function, which accepts an instance of
=CLINGON:COMMAND= and is responsible for performing some work.

The single argument a handler receives will be used to inspect the
values of parsed options and any free arguments that were provided on the
command-line.

A command may or may not specify a handler. Some commands may be used
purely as /namespaces/ for other sub-commands, and it might make no
sense to have a handler for such commands. In other situations you may
still want to provide a handler for the parent commands.

Let's define the handler for our /top-level/ command.

#+begin_src lisp
(defun top-level/handler (cmd)
  "The top-level handler"
  (let ((args (clingon:command-arguments cmd))
        (user (clingon:getopt cmd :user))
        (verbose (clingon:getopt cmd :verbose)))
    (format t "Hello, ~A!~%" user)
    (format t "The current verbosity level is set to ~A~%" verbose)
    (format t "You have provided ~A arguments~%" (length args))
    (format t "Bye.~%")))
#+end_src

We are introducing a couple of new functions, which we haven't
described before.

We are using =CLINGON:COMMAND-ARGUMENTS=, which will give us the free
arguments we've provided to our command, when we invoke it on the
command-line.

We also use the =CLINGON:GETOPT= function to lookup the values
associated with our options. Remember the =:KEY= initarg we've used in
=CLINGON:MAKE-OPTION= when defining our options?

And we will again update our =TOP-LEVEL/COMMAND= definition, this time
with our handler included.

#+begin_src lisp
(defun top-level/command ()
  "Creates and returns the top-level command"
  (clingon:make-command
   :name "clingon-intro"
   ...
   :handler #'top-level/handler)) ;; <- new code
#+end_src

At this point we are basically done with our simple application. But
before we move to the point where build our binary and start playing
with it on the command-line we can test things out on the REPL, just
to make sure everything works as expected.

** Testing things out on the REPL

Create a new instance of our command and bind it to some variable.

#+begin_src lisp
INTRO> (defparameter *app* (top-level/command))
*APP*
#+end_src

Inspecting the returned instance would give you something like this.

#+begin_src lisp
#
--------------------
Class: #
--------------------
 Group slots by inheritance [ ]
 Sort slots alphabetically  [X]

All Slots:
[ ]  ARGS-TO-PARSE    = NIL
[ ]  ARGUMENTS        = NIL
[ ]  AUTHORS          = ("John Doe ")
[ ]  CONTEXT          = #
[ ]  DESCRIPTION      = "my first clingon cli app"
[ ]  EXAMPLES         = NIL
[ ]  HANDLER          = #
[ ]  LICENSE          = "BSD 2-Clause"
[ ]  LONG-DESCRIPTION = NIL
[ ]  NAME             = "clingon-intro"
[ ]  OPTIONS          = (# # # # #)
[ ]  PARENT           = NIL
[ ]  SUB-COMMANDS     = NIL
[ ]  USAGE            = "[-v] [-u ]"
[ ]  VERSION          = "0.1.0"

[set value]  [make unbound]
#+end_src

You might also notice that besides the options we've defined ourselves,
there are few additional options, that we haven't defined at all.

These options are automatically added by =clingon= itself for each new
command and provide flags for =--help=, =--version= and
=--bash-completions= for you automatically, so you don't have to deal
with them manually.

Before we dive into testing out our application, first we will check
that we have a correct help information for our command.

#+begin_src lisp
INTRO> (clingon:print-usage *app* t)
NAME:
  clingon-intro - my first clingon cli app

USAGE:
  clingon-intro [-v] [-u ]

OPTIONS:
      --help              display usage information and exit
      --version           display version and exit
  -u, --user       user to greet [default: stranger] [env: $USER]
  -v, --verbose           verbosity level [default: 0]

AUTHORS:
  John Doe 

LICENSE:
  BSD 2-Clause

NIL
#+end_src

This help information will make it easier for our users, when they
need to use it. And that is automatically handled for you, so you
don't have to manually maintain an up-to-date usage information, each
time you introduce a new option.

Time to test out our application on the REPL. In order to test things
out you can use the =CLINGON:PARSE-COMMAND-LINE= function by passing
it an instance of your command, along with any arguments that need to
be parsed. Let's try it out without any command-line arguments.

#+begin_src lisp
INTRO> (clingon:parse-command-line *app* nil)
#
#+end_src

The =CLINGON:PARSE-COMMAND-LINE= function will (as the name suggests)
parse the given arguments against the options associated with our
command. Finally it will return an instance of =CLINGON:COMMAND=.

In our simple CLI application, that would be the same instance as our
=*APP*=, but things look differently when we have sub-commands.

When we start adding new sub-commands, the result of
=CLINGON:PARSE-COMMAND-LINE= will be different based on the arguments
it needs to parse. That means that if our input matches a sub-command
you will receive an instance of the sub-command that matched the given
arguments.

Internally the =clingon= system maintains a tree data structure,
describing the relationships between commands. This allows a command
to be related to some other command, and this is how the command and
sub-commands support is implemented in =clingon=.

Each command in =clingon= is associated with a /context/.  The
/context/ or /environment/ provides the options and their values with
respect to the command itself. This means that a parent command and a
sub-command may have exactly the same set of options defined, but they
will reside in different contexts. Depending on how you use it,
sub-commands may /shadow/ a parent command option, but it also means
that a sub-command can refer to an option defined in a global command.

The /context/ of a command in =clingon= is available via the
=CLINGON:COMMAND-CONTEXT= accessor. We will use the context in order
to lookup our options and the values associated with them.

The function that operates on command's context and retrieves
values from it is called =CLINGON:GETOPT=.

Let's see what we've got for our options.

#+begin_src lisp
INTRO> (let ((c (clingon:parse-command-line *app* nil)))
         (clingon:getopt c :user))
"dnaeon"
T
#+end_src

The =CLINGON:GETOPT= function returns multiple values -- first one
specifies the value of the option, if it had any. And the second one
indicates whether or not that option has been set at all on the
command-line.

If you need to simply test things out and tell whether an option has
been set at all you can use the =CLINGON:OPT-IS-SET-P= function
instead.

Let's try it out with a different input.

#+begin_src lisp
INTRO> (let ((c (clingon:parse-command-line *app* (list "-vvv" "--user" "foo"))))
         (format t "Verbose is ~A~%" (clingon:getopt c :verbose))
         (format t "User is ~A~%" (clingon:getopt c :user)))
Verbose is 3
User is foo
#+end_src

Something else, which is important to mention here. The default
precedence list for options is:

- The value provided by the =:INITIAL-VALUE= initarg
- The value of the first environment variable, which successfully resolved,
  provided by the =:ENV-VARS= initarg
- The value provided on the command-line when invoking the application.

Play with it using different command-line arguments. If you specify
invalid or unknown options =clingon= will signal a condition and
provide you a few recovery options. For example, if you specify an
invalid flag like this:

#+begin_src lisp
INTRO> (clingon:parse-command-line *app* (list "--invalid-flag"))
#+end_src

We will be dropped into the debugger and be provided with restarts we
can choose from, e.g.

#+begin_src lisp
Unknown option --invalid-flag of kind LONG
   [Condition of type CLINGON.CONDITIONS:UNKNOWN-OPTION]

Restarts:
 0: [DISCARD-OPTION] Discard the unknown option
 1: [TREAT-AS-ARGUMENT] Treat the unknown option as a free argument
 2: [SUPPLY-NEW-VALUE] Supply a new value to be parsed
 3: [RETRY] Retry SLY mREPL evaluation request.
 4: [ABORT] Return to sly-db level 1.
 5: [RETRY] Retry SLY mREPL evaluation request.
 --more--
...
#+end_src

This is similar to the way other Common Lisp options parsing systems
behave such as [[https://github.com/sjl/adopt][adopt]] and [[https://github.com/libre-man/unix-opts][unix-opts]].

Also worth mentioning again here is that =CLINGON:PARSE-COMMAND-LINE= is
meant to be used within the REPL, and not called directly by handlers.

** Adding a sub-command

Sub-commands are no different than regular commands, and in fact are
created exactly the way we did it for our /top-level/ command.

#+begin_src lisp
(defun shout/handler (cmd)
  "The handler for the `shout' command"
  (let ((args (mapcar #'string-upcase (clingon:command-arguments cmd)))
        (user (clingon:getopt cmd :user))) ;; <- a global option
    (format t "HEY, ~A!~%" user)
    (format t "~A!~%" (clingon:join-list args #\Space))))

(defun shout/command ()
  "Returns a command which SHOUTS back anything we write on the command-line"
  (clingon:make-command
   :name "shout"
   :description "shouts back anything you write"
   :usage "[options] [arguments ...]"
   :handler #'shout/handler))
#+end_src

And now, we will wire up our sub-command making it part of the
/top-level/ command we have so far.

#+begin_src lisp
(defun top-level/command ()
  "Creates and returns the top-level command"
  (clingon:make-command
   :name "clingon-intro"
   ...
   :sub-commands (list (shout/command)))) ;; <- new code
#+end_src

You should also notice here that within the =SHOUT/HANDLER= we are
actually referencing an option, which is defined somewhere else.  This
option is actually defined on our top-level command, but thanks's to
the automatic management of relationships that =clingon= provides we
can now refer to global options as well.

Let's move on to the final section of this guide, where we will create
a system definition for our application and build it.

** Packaging it up

One final piece which remains to be added to our code is to provide an
entrypoint for our application, so let's do it now.

#+begin_src lisp
(defun main ()
  (let ((app (top-level/command)))
    (clingon:run app)))
#+end_src

This is the entrypoint which will be used when we invoke our
application on the command-line, which we'll set in our ASDF
definition.

And here's a simple system definition for the application we've
developed so far.

#+begin_src lisp
(defpackage :clingon-intro-system
  (:use :cl :asdf))
(in-package :clingon-intro-system)

(defsystem "clingon.intro"
  :name "clingon.intro"
  :long-name "clingon.intro"
  :description "An introduction to the clingon system"
  :version "0.1.0"
  :author "John Doe "
  :license "BSD 2-Clause"
  :depends-on (:clingon)
  :components ((:module "intro"
                :pathname #P"examples/intro/"
                :components ((:file "intro"))))
  :build-operation "program-op"
  :build-pathname "clingon-intro"
  :entry-point "clingon.intro:main")
#+end_src

Now we can build our application and start using it on the
command-line.

#+begin_src shell
sbcl --eval '(ql:quickload :clingon.intro)' \
     --eval '(asdf:make :clingon.intro)' \
     --eval '(quit)'
#+end_src

This will produce a new binary called =clingon-intro= in the directory
of the =clingon.intro= system.

** Testing it out on the command-line

Time to check things up on the command-line.

#+begin_src shell
$ ./clingon-intro --help
NAME:
  clingon-intro - my first clingon cli app

USAGE:
  clingon-intro [-v] [-u ]

OPTIONS:
      --help              display usage information and exit
      --version           display version and exit
  -u, --user       user to greet [default: stranger] [env: $USER]
  -v, --verbose           verbosity level [default: 0]

COMMANDS:
  shout  shouts back anything you write

AUTHORS:
  John Doe 

LICENSE:
  BSD 2-Clause
#+end_src

Let's try out our commands.

#+begin_src shell
$ ./clingon-intro -vvv --user Lisper
Hello, Lisper!
The current verbosity level is set to 3
You have provided 0 arguments
Bye.
#+end_src

And let's try our sub-command as well.

#+begin_src shell
$ ./clingon-intro --user stranger shout why are yelling at me?
HEY, stranger!
WHY ARE YELLING AT ME?!
#+end_src

You can find the full code we've developed in this guide in the
[[https://github.com/dnaeon/clingon/tree/master/examples][clingon/examples]] directory of the repo.

* Exiting

When a command needs to exit with a given status code you can use the
=CLINGON:EXIT= function.

* Handling SIGINT (CTRL-C) signals

=clingon= by default will provide a handler for =SIGINT= signals,
which when detected will cause the application to immediately exit
with status code =130=.

If your commands need to provide some cleanup logic as part of their
job, e.g. close out all open files, TCP session, etc., you could wrap
your =clingon= command handlers in [[http://www.lispworks.com/documentation/HyperSpec/Body/s_unwind.htm][UNWIND-PROTECT]] to make sure that
your cleanup tasks are always executed.

However, using [[http://www.lispworks.com/documentation/HyperSpec/Body/s_unwind.htm][UNWIND-PROTECT]] may not be appropriate in all cases,
since the cleanup forms will always be executed, which may or may not
be what you need.

For example if you are developing a =clingon= application, which
populates a database in a transaction you would want to use
[[http://www.lispworks.com/documentation/HyperSpec/Body/s_unwind.htm][UNWIND-PROTECT]], but only for releasing the database connection itself.

If the application is interrupted while it inserts or updates records,
what you want to do is to rollback the transaction as well, so your
database is left in a consistent state.

In those situations you would want to use the [[https://github.com/compufox/with-user-abort][WITH-USER-ABORT]] system,
so that your =clingon= command can detect the =SIGINT= signal and act
upon it, e.g. taking care of rolling back the transaction.

* Generating Documentation

=clingon= can generate documentation for your application by using the
=CLINGON:PRINT-DOCUMENTATION= generic function.

Currently the documentation generator supports only the /Markdown/
format, but other formats can be developed as separate extensions to
=clingon=.

Here's how you can generate the Markdown documentation for the
=clingon-demo= application from the REPL.

#+begin_src lisp
CL-USER> (ql:quickload :clingon.demo)
CL-USER> (in-package :clingon.demo)
DEMO> (with-open-file (out #P"clingon-demo.md" :direction :output)
        (clingon:print-documentation :markdown (top-level/command) out))
#+end_src

You can also create a simple command, which can be added to your
=clingon= apps and have it generate the documentation for you, e.g.

#+begin_src lisp
(defun print-doc/command ()
  "Returns a command which will print the app's documentation"
  (clingon:make-command
   :name "print-doc"
   :description "print the documentation"
   :usage ""
   :handler (lambda (cmd)
              ;; Print the documentation starting from the parent
              ;; command, so we can traverse all sub-commands in the
              ;; tree.
              (clingon:print-documentation :markdown (clingon:command-parent cmd) t))))
#+end_src

Above command can be wired up anywhere in your application.

Make sure to also check the =clingon-demo= app, which provides a
=print-doc= sub-command, which operates on the /top-level/ command and
generates the documentation for all sub-commands.

You can also find the generated documentation for the =clingon-demo=
app in the =docs/= directory of the =clingon= repo.

* Command Hooks

=clingon= allows you to associate =pre= and =post= hooks with a
command.

The =pre= and =post= hooks are functions which will be invoked before
and after the respective command handler is executed. They are useful
in cases when you need to set up or tear things down before executing
the command's handler.

An example of a =pre-hook= might be to configure the logging level of
your application based on the value of a global flag. A =post-hook=
might be responsible for shutting down any active connections, etc.

The =pre-hook= and =post-hook= functions accept a single argument,
which is an instance of =CLINGON:COMMAND=. That way the hooks can
examine the command's context and lookup any flags or options.

Hooks are also hierachical in the sense that they will be executed
based on the command's lineage.

Consider the following example, where we have a CLI app with three
commands.

#+begin_src text
  main -> foo -> bar
#+end_src

In above example the =bar= command is a sub-command of =foo=, which in
turn is a sub-command of =main=. Also, consider that we have added
pre- and post-hooks to each command.

If a user executed the following on the command-line:

#+begin_src shell
  $ main foo bar
#+end_src

Based on the above command-line =clingon= would do the following:

- Execute any =pre-hook= functions starting from the least-specific up to the
  most-specific node from the commands' lineage
- Execute the command's handler
- Execute any =post-hook= functions starting from the most-specific down to the
  least-specific node from the command's lineage

In above example that would be:

#+begin_src text
  > main (pre-hook)
  >> foo (pre-hook)
  >>> bar (pre-hook)
  >>>> bar (handler)
  >>> bar (post-hook)
  >> foo (post-hook)
  > main (post-hook)
#+end_src

Associating hooks with commands is done during instantiation of a
command. The following example creates a new command with a =pre-hook=
and =post-hook=.

#+begin_src lisp
  (defun foo/pre-hook (cmd)
    "The pre-hook for `foo' command"
    (declare (ignore cmd))
    (format t "foo pre-hook has been invoked~&"))

  (defun foo/post-hook (cmd)
    "The post-hook for `foo' command"
    (declare (ignore cmd))
    (format t "foo post-hook has been invoked~&"))

  (defun foo/handler (cmd)
    (declare (ignore cmd))
    (format t "foo handler has been invoked~&"))

  (defun foo/command ()
    "Returns the `foo' command"
    (clingon:make-command
     :name "foo"
     :description "the foo command"
     :authors '("John Doe ")
     :handler #'foo/handler
     :pre-hook #'foo/pre-hook
     :post-hook #'foo/post-hook
     :options nil
     :sub-commands nil))
#+end_src

If we have executed above command we would see the following output.

#+begin_src shell
  foo pre-hook has been invoked
  foo handler has been invoked
  foo post-hook has been invoked
#+end_src

* Options

The =clingon= system supports various kinds of options, each of which
is meant to serve a specific purpose.

Each builtin option can be initialized via environment variables, and
new mechanisms for initializing options can be developed, if needed.

Options are created via the single =CLINGON:MAKE-OPTION= interface.

The supported option kinds include:

- =counter=
- =integer=
- =string=
- =boolean=
- =boolean/true=
- =boolean/false=
- =choice=
- =enum=
- =list=
- =list/integer=
- =filepath=
- =list/filepath=
- etc.

** Counters Options

A =counter= is an option kind, which increments every time it is set
on the command-line.

A good example for =counter= options is to provide a flag, which
increases the verbosity level, depending on the number of times the
flag was provided, similar to the way =ssh(1)= does it, e.g.

#+begin_src shell
ssh -vvv user@host
#+end_src

Here's an example of creating a =counter= option.

#+begin_src lisp
(clingon:make-option
 :counter
 :short-name #\v
 :long-name "verbose"
 :description "how noisy we want to be"
 :key :verbose)
#+end_src

The default =step= for counters is set to =1=, but you can change
that, if needed.

#+begin_src lisp
(clingon:make-option
 :counter
 :short-name #\v
 :long-name "verbose"
 :description "how noisy we want to be"
 :step 42
 :key :verbose)
#+end_src

** Boolean Options

The following boolean option kinds are supported by =clingon=.

The =:boolean= kind is an option which expects an argument, which
represents a boolean value.

Arguments =true= and =1= map to =T= in Lisp, anything else is
considered a falsey value and maps to =NIL=.

#+begin_src lisp
(clingon:make-option
 :boolean
 :description "my boolean"
 :short-name #\b
 :long-name "my-boolean"
 :key :boolean)
#+end_src

This creates an option =-b, --my-boolean =, which can be
provided on the command-line, where == should be =true= or =1=
for truthy values, and anything else maps to =NIL=.

The =:boolean/true= option kind creates a flag, which always returns
=T=.

The =:boolean/false= option kind creates a flag, which always returns
=NIL=.

The =:flag= option kind is an alias for =:boolean/true=.

** Integer Options

Here's an example of creating an option, which expects an integer
argument.

#+begin_src lisp
(clingon:make-option
 :integer
 :description "my integer opt"
 :short-name #\i
 :long-name "int"
 :key :my-int
 :initial-value 42)
#+end_src

** Choice Options

=choice= options are useful when you have to limit the arguments
provided on the command-line to a specific set of values.

For example:

#+begin_src lisp
(clingon:make-option
 :choice
 :description "log level"
 :short-name #\l
 :long-name "log-level"
 :key :choice
 :items '("info" "warn" "error" "debug"))
#+end_src

With this option defined, you can now set the logging level only to
=info=, =warn=, =error= or =debug=, e.g.

#+begin_src shell
-l, --log-level [info|warn|error|debug]
#+end_src

** Enum Options

Enum options are similar to the =choice= options, but instead of
returning the value itself they can be mapped to something else.

For example:

#+begin_src lisp
(clingon:make-option
 :enum
 :description "enum option"
 :short-name #\e
 :long-name "my-enum"
 :key :enum
 :items '(("one" . 1)
          ("two" . 2)
          ("three" . 3)))
#+end_src

If a user specifies =--my-enum=one= on the command-line the option
will be have the value =1= associated with it, when being looked up
via =CLINGON:GETOPT=.

The values you associate with the enum variant, can be any object.

This is one of the options being used by the /clingon-demo/
application, which maps user input to Lisp functions, in order to
perform some basic math operations.

#+begin_src lisp
(clingon:make-option
 :enum
 :description "operation to perform"
 :short-name #\o
 :long-name "operation"
 :required t
 :items `(("add" . ,#'+)
          ("sub" . ,#'-)
          ("mul" . ,#'*)
          ("div" . ,#'/))
 :key :math/operation)
#+end_src

** List / Accumulator Options

The =:list= option kind accumulates each argument it is given on the
command-line into a list.

For example:

#+begin_src lisp
(clingon:make-option
 :list
 :description "files to process"
 :short-name #\f
 :long-name "file"
 :key :files)
#+end_src

If you invoke an application, which uses a similar option like the one
above using the following command-line arguments:

#+begin_src shell
$ my-app --file foo --file bar --file baz
#+end_src

When you retrieve the value associated with your option, you will get a
list of all the files specified on the command-line, e.g.

#+begin_src lisp
(clingon:getopt cmd :files) ;; => '("foo" "bar" "baz")
#+end_src

A similar option exists for integer values using the =:list/integer=
option, e.g.

#+begin_src lisp
(clingon:make-option
 :list/integer
 :description "list of integers"
 :short-name #\l
 :long-name "int"
 :key :integers)
#+end_src

** Switch Options

=:SWITCH= options are a variation of =:BOOLEAN= options with an
associated list of known states that can turn a switch /on/ or
/off/.

Here is an example of a =:SWITCH= option.

#+begin_src lisp
(clingon:make-option
 :switch
 :description "my switch option"
 :short-name #\s
 :long-name "state"
 :key :switch)
#+end_src

The default states for a switch to be considered as /on/ are:

- /on/, /yes/, /true/, /enable/ and /1/

The default states considered to turn the switch /off/ are:

- /off/, /no/, /false/, /disable/ and /0/

You can customize the list of /on/ and /off/ states by specifying them
using the =:ON-STATES= and =:OFF-STATES= initargs, e.g.

#+begin_src lisp
(clingon:make-option
 :switch
 :description "engine switch option"
 :short-name #\s
 :long-name "state"
 :on-states '("start")
 :off-states '("stop")
 :key :engine)
#+end_src

These sample command-line arguments will turn a switch on and off.

#+begin_src shell
my-app --engine=start --engine=stop
#+end_src

The final value of the =:engine= option will be =NIL= in the above
example.

* Generic Functions Operating on Options

If the existing options provided by =clingon= are not enough for you,
and you need something a bit more specific for your use case, then you
can always implement a new option kind.

The following generic functions operate on options and are exported by
the =clingon= system.

- =CLINGON:INITILIAZE-OPTION=
- =CLINGON:FINALIZE-OPTION=
- =CLINGON:DERIVE-OPTION-VALUE=
- =CLINGON:OPTION-USAGE-DETAILS=
- =CLINGON:OPTION-DESCRIPTION-DETAILS=
- =CLINGON:MAKE-OPTION=

New option kinds should inherit from the =CLINGON:OPTION= class, which
implements all of the above generic functions. If you need to
customize the behaviour of your new option, you can still override the
default implementations.

** CLINGON:INITIALIZE-OPTION

The =CLINGON:INITIALIZE-OPTION= as the name suggests is being used to
initialize an option.

The default implementation of this generic function supports
initialization from environment variables, but implementors
can choose to support other initialization methods, e.g.
be able to initialize an option from a key/value store like
/Redis/, /Consul/ or /etcd/ for example.

** CLINGON:FINALIZE-OPTION

The =CLINGON:FINALIZE-OPTION= generic function is called after
all command-line arguments have been processed and values for them
have been derived already.

=CLINGON:FINALIZE-OPTION= is meant to /finalize/ the option's value,
e.g. transform it to another object, if needed.

For example the =:BOOLEAN= option kind transforms user-provided input
like =true=, =false=, =1= and =0= into their respective Lisp counterparts
like =T= and =NIL=.

Another example where you might want to customize the behaviour of
=CLINGON:FINALIZE-OPTION= is to convert a string option provided on
the command-line, which represents a database connection string into
an actual session object for the database.

The default implementation of this generic function simply returns the
already set value, e.g. calls =#'IDENTITY= on the last derived value.

** CLINGON:DERIVE-OPTION-VALUE

The =CLINGON:DERIVE-OPTION-VALUE= is called whenever an option is
provided on the command-line.

If that option accepts an argument, it will be passed the respective
value from the command-line, otherwise it will be called with a =NIL=
argument.

Responsibility of the option is to derive a value from the given input
and return it to the caller. The returned value will be set by the
parser and later on it will be used to produce a final value, by
calling the =CLINGON:FINALIZE-OPTION= generic function.

Different kinds of options implement this one different -- for example
the =:LIST= option kind accumulates each given argument, while others
ignore any previously derived values and return the last provided
argument.

The =:ENUM= option kind for example will derive a value from a
pre-defined list of allowed values.

If an option fails to derive a value (e.g. invalid value has been
provided) the implementation of this generic function should signal a
=CLINGON:OPTION-DERIVE-ERROR= condition, so that =clingon= can provide
appropriate restarts.

** CLINGON:OPTION-USAGE-DETAILS

This generic function is used to provide a pretty-printed usage format
for the given option. It will be used when printing usage information
on the command-line for the respective commands.

** CLINGON:OPTION-DESCRIPTION-DETAILS

This generic function is meant to enrich the description of the option
by providing as much details as possible for the given option, e.g.
listing the available values that an option can accept.

** CLINGON:MAKE-OPTION

The =CLINGON:MAKE-OPTION= generic function is the primary way for
creating new options. Implementors of new option kinds should simply
provide an implementation of this generic function, along with the
respective option kind.

Additional option kinds may be implemented as separate sub-systems,
but still follow the same principle by providing a single and
consistent interface for option creation.

* Developing New Options

This section contains short guides explaining how to develop new
options for =clingon=.

** Developing an Email Option

The option which we'll develop in this section will be used for
specifying email addresses.

Start up your Lisp REPL session and do let's some work. Load the
=:clingon= and =:cl-ppcre= systems, since we will need them.

#+begin_src lisp
CL-USER> (ql:quickload :clingon)
CL-USER> (ql:quickload :cl-ppcre)
#+end_src

We will first create a new package for our extension and import the
symbols we will need from the =:clingon= and =:cl-ppcre= systems.

#+begin_src lisp
(defpackage :clingon.extensions/option-email
  (:use :cl)
  (:import-from
   :cl-ppcre
   :scan)
  (:import-from
   :clingon
   :option
   :initialize-option
   :derive-option-value
   :make-option
   :option-value
   :option-derive-error)
  (:export
   :option-email))
(in-package :clingon.extensions/option-email)
#+end_src

Then lets define the class, which will represent an email address
option.

#+begin_src lisp
(defclass option-email (option)
  ((pattern
    :initarg :pattern
    :initform "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"
    :reader option-email-pattern
    :documentation "Pattern used to match for valid email addresses"))
  (:default-initargs
   :parameter "EMAIL")
  (:documentation "An option used to represent an email address"))
#+end_src

Now we will implement =CLINGON:INITIALIZE-OPTION= for our new
option. We will keep the default initialization logic as-is, but also
add an additional step to validate the email address, if we have any
initial value at all.

#+begin_src lisp
(defmethod initialize-option ((option option-email) &key)
  "Initializes our new email address option"
  ;; Make sure to invoke our parent initialization method first, so
  ;; various things like setting up initial value from environment
  ;; variables can still be applied.
  (call-next-method)

  ;; If we don't have any value set, there's nothing else to
  ;; initialize further here.
  (unless (option-value option)
    (return-from initialize-option))

  ;; If we get to this point, that means we've got some initial value,
  ;; which is either set as a default, or via environment
  ;; variables. Next thing we need to do is make sure we've got a good
  ;; initial value, so let's derive a value from it.
  (let ((current (option-value option)))
    (setf (option-value option)
          (derive-option-value option current))))
#+end_src

Next we will implement =CLINGON:DERIVE-OPTION-VALUE= for our new
option kind.

#+begin_src lisp
(defmethod derive-option-value ((option option-email) arg &key)
  "Derives a new value based on the given argument.
   If the given ARG represents a valid email address according to the
   pattern we know of we consider this as a valid email address."
  (unless (scan (option-email-pattern option) arg)
    (error 'option-derive-error :reason (format nil "~A is not a valid email address" arg)))
  arg)
#+end_src

Finally, lets register our new option as a valid kind by implemeting
the =CLINGON:MAKE-OPTION= generic function.

#+begin_src lisp
(defmethod make-option ((kind (eql :email)) &rest rest)
  (apply #'make-instance 'option-email rest))
#+end_src

We can test things out now. Go back to your REPL and try these
expressions out. First we make a new instance of our new option.

#+begin_src lisp
(defparameter *opt*
  (make-option :email :short-name #\e :description "email opt" :key :email))
#+end_src

And now, lets validate a couple of good email addresses.

#+begin_src lisp
EXTENSIONS/OPTION-EMAIL> (derive-option-value *opt* "test@example.com")
"test@example.com"
EXTENSIONS/OPTION-EMAIL> (derive-option-value *opt* "foo@bar.com")
"foo@bar.com"
#+end_src

If we try deriving a value from a bad email address we will have a
condition of type =CLINGON:OPTION-DERIVE-ERROR= signalled.

#+begin_src lisp
EXTENSIONS/OPTION-EMAIL> (derive-option-value opt "bad-email-address-here")
; Debugger entered on #
...
bad-email-address-here is not a valid email address
   [Condition of type OPTION-DERIVE-ERROR]
#+end_src

Good, we can catch invalid email addresses as well. Whenever an option
fails to derive a new value from a given argument, and we signal
=CLINGON:OPTION-DERIVE-ERROR= condition we can recover by providing
new values or discarding them completely, thanks to the Common Lisp
Condition System.

Last thing to do is actually package this up as an extension system
and register it in Quicklisp. That way everyone else can benefit from
the newly developed option.

* Shell Completions

=clingon= provides support for Bash and Zsh shell completions.

** Bash Completions

In order to enable the Bash completions for your =clingon= app,
follow these instructions.

#+begin_src shell
APP=app-name source extras/completions.bash
#+end_src

Make sure to set =APP= to your correct application name.

The [[https://github.com/dnaeon/clingon/blob/master/extras/completions.bash][completions.bash]] script will dynamically provide completions by
invoking the =clingon= app with the =--bash-completions= flag. This
builtin flag when provided on the command-line will return completions
for the sub-commands and the available flags.

** Zsh Completions

When developing your CLI app with =clingon= you can provide an
additional command, which will take care of generating the Zsh
completion script for your users.

The following code can be used in your app and added as a sub-command
to your top-level command.

#+begin_src lisp
  (defun zsh-completion/command ()
    "Returns a command for generating the Zsh completion script"
    (clingon:make-command
     :name "zsh-completion"
     :description "generate the Zsh completion script"
     :usage ""
     :handler (lambda (cmd)
                ;; Use the parent command when generating the completions,
                ;; so that we can traverse all sub-commands in the tree.
                (let ((parent (clingon:command-parent cmd)))
                  (clingon:print-documentation :zsh-completions parent t)))))
#+end_src

You can also check out the =clingon-demo= app for a fully working CLI
app with Zsh completions support.

[[./images/clingon-zsh-completions.gif]]

* Ideas For Future Improvements

** Additional Documentation Generators

As of now =clingon= supports generating documentation only in /Markdown/
format.

Would be nice to have additional documentation generators, e.g.
/man pages/, /HTML/, etc.

** Performance Notes

=clingon= has been developed and tested on a GNU/Linux system using
SBCL.

Performance of the resulting binaries with SBCL seem to be good,
although I have noticed better performance when the binaries have been
produced with Clozure CL. And by better I mean better in terms of
binary size and speed (startup + run time).

Although you can enable compression on the image when using SBCL you
have to pay the extra price for the startup time.

Here are some additional details. Build the =clingon-demo= app with
SBCL.

#+begin_src shell
$ LISP=sbcl make demo
sbcl --eval '(ql:quickload :clingon.demo)' \
        --eval '(asdf:make :clingon.demo)' \
                --eval '(quit)'
This is SBCL 2.1.7, an implementation of ANSI Common Lisp.
More information about SBCL is available at .

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
To load "clingon.demo":
  Load 1 ASDF system:
    clingon.demo
; Loading "clingon.demo"
[package clingon.utils]...........................
[package clingon.conditions]......................
[package clingon.options].........................
[package clingon.command].........................
[package clingon].................................
[package clingon.demo]
[undoing binding stack and other enclosing state... done]
[performing final GC... done]
[defragmenting immobile space... (fin,inst,fdefn,code,sym)=1118+969+19070+19610+26536... done]
[saving current Lisp image into /home/dnaeon/Projects/lisp/clingon/clingon-demo:
writing 0 bytes from the read-only space at 0x50000000
writing 736 bytes from the static space at 0x50100000
writing 31391744 bytes from the dynamic space at 0x1000000000
writing 2072576 bytes from the immobile space at 0x50200000
writing 12341248 bytes from the immobile space at 0x52a00000
done]
#+end_src

Now, build it using Clozure CL.

#+begin_src shell
$ LISP=ccl make demo
ccl --eval '(ql:quickload :clingon.demo)' \
        --eval '(asdf:make :clingon.demo)' \
                --eval '(quit)'
To load "clingon.demo":
  Load 1 ASDF system:
    clingon.demo
; Loading "clingon.demo"
[package clingon.utils]...........................
[package clingon.conditions]......................
[package clingon.options].........................
[package clingon.command].........................
[package clingon].................................
[package clingon.demo].
#+end_src

In terms of file size the binaries produced by Clozure CL are smaller.

#+begin_src shell
$ ls -lh clingon-demo*
-rwxr-xr-x 1 dnaeon dnaeon 33M Aug 20 12:56 clingon-demo.ccl
-rwxr-xr-x 1 dnaeon dnaeon 45M Aug 20 12:55 clingon-demo.sbcl
#+end_src

Generating the Markdown documentation for the demo app when using the
SBCL executable looks like this.

#+begin_src shell
$ time ./clingon-demo.sbcl print-doc > /dev/null

real    0m0.098s
user    0m0.071s
sys     0m0.027s
#+end_src

And when doing the same thing with the executable produced by Clozure
CL we see these results.

#+begin_src shell
$ time ./clingon-demo.ccl print-doc > /dev/null

real    0m0.017s
user    0m0.010s
sys     0m0.007s
#+end_src

* Tests

The =clingon= tests are provided as part of the =:clingon.test= system.

In order to run the tests you can evaluate the following expressions.

#+begin_src lisp
CL-USER> (ql:quickload :clingon.test)
CL-USER> (asdf:test-system :clingon.test)
#+end_src

Or you can run the tests using the =run-tests.sh= script instead, e.g.

#+begin_src shell
LISP=sbcl ./run-tests.sh
#+end_src

Here's how to run the tests against SBCL, CCL and ECL for example.

#+begin_src shell
for lisp in sbcl ccl ecl; do
    echo "Running tests using ${lisp} ..."
    LISP=${lisp} make test > ${lisp}-tests.out
done
#+end_src

* Docker Images

A few Docker images are available.

Build and run the tests in a container.

#+begin_src shell
docker build -t clingon.test:latest -f Dockerfile.tests .
docker run --rm clingon.test:latest
#+end_src

Build and run the =clingon-intro= application.

#+begin_src shell
docker build -t clingon.intro:latest -f Dockerfile.intro .
docker run --rm clingon.intro:latest
#+end_src

Build and run the =clingon.demo= application.

#+begin_src lisp
docker build -t clingon.demo:latest -f Dockerfile.demo .
docker run --rm clingon.demo:latest
#+end_src

* Contributing

=clingon= is hosted on [[https://github.com/dnaeon/clingon][Github]]. Please contribute by reporting issues,
suggesting features or by sending patches using pull requests.

* License

This project is Open Source and licensed under the [[http://opensource.org/licenses/BSD-2-Clause][BSD License]].

* Authors

- Marin Atanasov Nikolov 



2 Systems

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


Previous: , Up: Systems   [Contents][Index]

2.1 clingon

Command-line options parser system for Common Lisp

Long Name

clingon

Maintainer

Marin Atanasov Nikolov <dnaeon@gmail.com>

Author

Marin Atanasov Nikolov <dnaeon@gmail.com>

Home Page

https://github.com/dnaeon/clingon

Source Control

https://github.com/dnaeon/clingon

Bug Tracker

https://github.com/dnaeon/clingon

License

BSD 2-Clause

Long Description

* clingon

=clingon= is a command-line options parser system for Common Lisp.

A summary of the features supported by =clingon= is provided below.

- Native support for sub-commands
- Support for command aliases
- Short and long option names support
- Related options may be grouped into categories
- Short options may be collapsed as a single argument, e.g. =-xyz=
- Long options support both notations - =–long-opt arg= and
=–long-opt=arg=.
- Automatic generation of help/usage information for commands and
sub-commands
- Out of the box support for =–version= and =–help= flags
- Support for various kinds of options like /string/, /integer/,
/boolean/, /switches/, /enums/, /list/, /counter/, /filepath/, etc.
- Sub-commands can lookup global options and flags defined in parent
commands
- Support for options, which may be required
- Options can be initialized via environment variables
- Single interface for creating options using =CLINGON:MAKE-OPTION=
- Generate documentation for your command-line app
- Support for =pre-hook= and =post-hook= actions for commands, which
allows invoking functions before and after the respective handler of
the command is executed
- Support for Bash and Zsh shell completions
- =clingon= is extensible, so if you don’t find something you need you
can extend it by developing a new option kind, or even new mechanism
for initializing options, e.g. by looking up an external key/value
store.

Scroll to the demo section in order to see some examples of =clingon=
in action.

Other Common Lisp option parser systems, which you might consider
checking out.

- [[https://github.com/libre-man/unix-opts][unix-opts]]
- [[https://github.com/sjl/adopt/][adopt]]
- [[https://github.com/didierverna/clon][clon]]

* Quick Example

Here’s a really quick example of a simple CLI application, which
greets people.

#+begin_src lisp
(in-package :cl-user)
(defpackage :clingon.example.greet
(:use :cl)
(:import-from :clingon)
(:export
:main))
(in-package :clingon.example.greet)

(defun greet/options ()
"Returns the options for the ‘greet’ command"
(list
(clingon:make-option
:string
:description "Person to greet"
:short-name #\u
:long-name "user"
:initial-value "stranger"
:env-vars ’("USER")
:key :user)))

(defun greet/handler (cmd)
"Handler for the ‘greet’ command"
(let ((who (clingon:getopt cmd :user)))
(format t "Hello, ~A!~%" who)))

(defun greet/command ()
"A command to greet someone"
(clingon:make-command
:name "greet"
:description "greets people"
:version "0.1.0"
:authors ’("John Doe <john.doe@example.org")
:license "BSD 2-Clause"
:options (greet/options)
:handler #’greet/handler))

(defun main ()
"The main entrypoint of our CLI program"
(let ((app (greet/command)))
(clingon:run app)))
#+end_src

This small example shows a lot of details about how apps are
structured with =clingon=.

You can see there’s a =main= function, which will be the entrypoint
for our ASDF system. Then you can find the =greet/command= function,
which creates and returns a new command.

The =greet/options= functions returns the options associated with our
sample command.

And we also have the =greet/handler= function, which is the function
that will be invoked when users run our command-line app.

This way of organizing command, options and handlers makes it easy to
re-use common options, or even handlers, and wire up any sub-commands
anyway you prefer.

You can find additional examples included in the test suite for
=clingon=.

* Demo

You can also build and run the =clingon= demo application, which
includes the =greet= command introduced in the previous section, along
with other examples.

[[./images/clingon-demo.gif]]

Clone the [[https://github.com/dnaeon/clingon][clingon]] repo in your [[https://www.quicklisp.org/beta/faq.html][Quicklisp local-projects]] directory.

#+begin_src shell
git clone https://github.com/dnaeon/clingon
#+end_src

Register it to your local Quicklisp projects.

#+begin_src lisp
CL-USER> (ql:register-local-projects)
#+end_src

** Building the Demo App

You can build the demo app using SBCL with the following command.

#+begin_src shell
LISP=sbcl make demo
#+end_src

Build the demo app using Clozure CL:

#+begin_src shell
LISP=ccl make demo
#+end_src

In order to build the demo app using ECL you need to follow these
instructions, which are ECL-specific. See [[https://common-lisp.net/project/ecl/static/manual/System-building.html#Compiling-with-ASDF][Compiling with ASDF from the
ECL manual]] for more details. First, load the =:clingon.demo= system.

#+begin_src lisp
(ql:quickload :clingon.demo)
#+end_src

And now build the binary with ECL:

#+begin_src lisp
(asdf:make-build :clingon.demo
:type :program
:move-here #P"./"
:epilogue-code ’(clingon.demo:main))
#+end_src

This will create a new executable =clingon-demo=, which you can now
execute.

Optionally, you can also enable the bash completions support.

#+begin_src shell
APP=clingon-demo source extras/completions.bash
#+end_src

In order to activate the Zsh completions, install the completions
script in your =~/.zsh-completions= directory (or anywhere else you
prefer) and update your =~/.zshrc= file, so that the completions are
loaded.

Make sure that you have these lines in your =~/.zshrc= file.

#+begin_src shell
fpath=(~/.zsh-completions $fpath)
autoload -U compinit
compinit
#+end_src

The following command will generate the Zsh completions script.

#+begin_src shell
./clingon-demo zsh-completion > ~/.zsh-completions/_clingon-demo
#+end_src

Use the =–help= flag to see some usage information about the demo
application.

#+begin_src shell
./clingon-demo –help
#+end_src

* Requirements

- [[https://www.quicklisp.org/beta/][Quicklisp]]

* Installation

The =clingon= system is not yet part of Quicklisp, so for now
you need to install it in your local Quicklisp projects.

Clone the repo in your [[https://www.quicklisp.org/beta/faq.html][Quicklisp local-projects]] directory.

#+begin_src lisp
(ql:register-local-projects)
#+end_src

Then load the system.

#+begin_src lisp
(ql:quickload :clingon)
#+end_src

* Step By Step Guide

In this section we will implement a simple CLI application, and
explain at each step what and why we do the things we do.

Once you are done with it, you should have a pretty good understanding
of the =clingon= system and be able to further extend the sample
application on your own.

We will be developing the application interactively and in the
REPL. Finally we will create an ASDF system for our CLI app, so we can
build it and ship it.

The code we develop as part of this section will reside in a file
named =intro.lisp=. Anything we write will be sent to the Lisp REPL, so
we can compile it and get quick feedback about the things we’ve done
so far.

You can find the complete code we’ll develop in this section in the
=clingon/examples/intro= directory.

** Start the REPL

Start up your REPL session and let’s load the =clingon= system.

#+begin_src lisp
CL-USER> (ql:quickload :clingon)
To load "clingon":
Load 1 ASDF system:
clingon
; Loading "clingon"

(:CLINGON)
#+end_src

** Create a new package

First, we will define a new package for our application and switch to
it.

#+begin_src lisp
(in-package :cl-user)
(defpackage :clingon.intro
(:use :cl)
(:import-from :clingon)
(:export :main))
(in-package :clingon.intro)
#+end_src

We have our package, so now we can proceed to the next section and
create our first command.

** Creating a new command

The first thing we’ll do is to create a new command. Commands are
created using the =CLINGON:MAKE-COMMAND= function.

Each command has a name, description, any options that
the command accepts, any sub-commands the command knows about, etc.

The command in =clingon= is represented by the =CLINGON:COMMAND=
class, which contains many other slots as well, which you can lookup.

#+begin_src lisp
(defun top-level/command ()
"Creates and returns the top-level command"
(clingon:make-command
:name "clingon-intro"
:description "my first clingon cli app"
:version "0.1.0"
:license "BSD 2-Clause"
:authors ’("John Doe <john.doe@example.com>")))
#+end_src

This is how our simple command looks like. For now it doesn’t do much,
and in fact it won’t execute anything, but we will fix that as we go.

What is important to note, is that we are using a convention here
to make things easier to understand and organize our code base.

Functions that return new commands will be named =<name>/command=. A
similar approach is taken when we define options for a given command,
e.g. =<name>/options= and for sub-commands we use
=<name>/sub-commands=. Handlers will use the =<name>/handler=
notation.

This makes things easier later on, when we introduce new sub-commands,
and when we need to wire things up we can refer to our commands using
the established naming convention. Of course, it’s up to you to decide
which approach to take, so feel free to adjust the layout of the code
to your personal preferences. In this guide we will use the afore
mentioned approach.

Commands can be linked together in order to form a tree of commands
and sub-commands. We will talk about that one in more details in the
later sections of this guide.

** Adding options

Next, we will add a couple of options. Similar to the previous section
we will define a new function, which simply returns a list of valid
options. Defining it in the following way would make it easier to
re-use these options later on, in case you have another command, which
uses the exact same set of options.

=clingon= exposes a single interface for creating options via the
=CLINGON:MAKE-OPTION= generic function. This unified interface will
allow developers to create and ship new option kinds, and still have
their users leverage a common interface for the options via the
=CLINGON:MAKE-OPTION= interface.

#+begin_src lisp
(defun top-level/options ()
"Creates and returns the options for the top-level command"
(list
(clingon:make-option
:counter
:description "verbosity level"
:short-name #\v
:long-name "verbose"
:key :verbose)
(clingon:make-option
:string
:description "user to greet"
:short-name #\u
:long-name "user"
:initial-value "stranger"
:env-vars ’("USER")
:key :user)))
#+end_src

Let’s break things down a bit and explain what we just did.

We’ve defined two options – one of =:COUNTER= kind and another one,
which is of =:STRING= kind. Each option specifies a short and long
name, along with a description of what the option is meant for.

Another important thing we did is to specify a =:KEY= for our options.
This is the key which we will later use in order to get the value
associated with our option, when we use =CLINGON:GETOPT=.

And we have also defined that our =–user= option can be initialized
via environment variables. We can specify multiple environment variables,
if we need to, and the first one that resolves to something will be used
as the initial value for the option.

If none of the environment variables are defined, the option will be
initialized with the value specified by the =:INITIAL-VALUE= initarg.

Before we move to the next section of this guide we will update the
definition of our =TOP-LEVEL/COMMAND= function, so that we include our
options.

#+begin_src lisp
(defun top-level/command ()
"Creates and returns the top-level command"
(clingon:make-command
:name "clingon-intro"
...
:usage "[-v] [-u <USER>]" ;; <- new code
:options (top-level/options))) ;; <- new code
#+end_src

** Defining a handler

A /handler/ in =clingon= is a function, which accepts an instance of
=CLINGON:COMMAND= and is responsible for performing some work.

The single argument a handler receives will be used to inspect the
values of parsed options and any free arguments that were provided on the
command-line.

A command may or may not specify a handler. Some commands may be used
purely as /namespaces/ for other sub-commands, and it might make no
sense to have a handler for such commands. In other situations you may
still want to provide a handler for the parent commands.

Let’s define the handler for our /top-level/ command.

#+begin_src lisp
(defun top-level/handler (cmd)
"The top-level handler"
(let ((args (clingon:command-arguments cmd))
(user (clingon:getopt cmd :user))
(verbose (clingon:getopt cmd :verbose)))
(format t "Hello, ~A!~%" user)
(format t "The current verbosity level is set to ~A~%" verbose)
(format t "You have provided ~A arguments~%" (length args))
(format t "Bye.~%")))
#+end_src

We are introducing a couple of new functions, which we haven’t
described before.

We are using =CLINGON:COMMAND-ARGUMENTS=, which will give us the free
arguments we’ve provided to our command, when we invoke it on the
command-line.

We also use the =CLINGON:GETOPT= function to lookup the values
associated with our options. Remember the =:KEY= initarg we’ve used in
=CLINGON:MAKE-OPTION= when defining our options?

And we will again update our =TOP-LEVEL/COMMAND= definition, this time
with our handler included.

#+begin_src lisp
(defun top-level/command ()
"Creates and returns the top-level command"
(clingon:make-command
:name "clingon-intro"
...
:handler #’top-level/handler)) ;; <- new code
#+end_src

At this point we are basically done with our simple application. But
before we move to the point where build our binary and start playing
with it on the command-line we can test things out on the REPL, just
to make sure everything works as expected.

** Testing things out on the REPL

Create a new instance of our command and bind it to some variable.

#+begin_src lisp
INTRO> (defparameter *app* (top-level/command))
*APP*
#+end_src

Inspecting the returned instance would give you something like this.

#+begin_src lisp
#<CLINGON.COMMAND:COMMAND {1004648293}>
——————–
Class: #<STANDARD-CLASS CLINGON.COMMAND:COMMAND>
——————–
Group slots by inheritance [ ]
Sort slots alphabetically [X]

All Slots:
[ ] ARGS-TO-PARSE = NIL
[ ] ARGUMENTS = NIL
[ ] AUTHORS = ("John Doe <john.doe@example.com>")
[ ] CONTEXT = #<HASH-TABLE :TEST EQUAL :COUNT 0 {1004648433}>
[ ] DESCRIPTION = "my first clingon cli app"
[ ] EXAMPLES = NIL
[ ] HANDLER = #<FUNCTION TOP-LEVEL/HANDLER>
[ ] LICENSE = "BSD 2-Clause"
[ ] LONG-DESCRIPTION = NIL
[ ] NAME = "clingon-intro"
[ ] OPTIONS = (#<CLINGON.OPTIONS:OPTION-BOOLEAN-TRUE short=NIL long=bash-completions> #<CLINGON.OPTIONS:OPTION-BOOLEAN-TRUE short=NIL long=version> #<CLINGON.OPTIONS:OPTION-BOOLEAN-TRUE short=NIL long=help> #<CLINGON.OPTIONS:OPTION-COUNTER short=v long=verbose> #<CLINGON.OPTIONS::OPTION-STRING short=u long=user>) [ ] PARENT = NIL
[ ] SUB-COMMANDS = NIL
[ ] USAGE = "[-v] [-u <USER>]"
[ ] VERSION = "0.1.0"

[set value] [make unbound]
#+end_src

You might also notice that besides the options we’ve defined ourselves,
there are few additional options, that we haven’t defined at all.

These options are automatically added by =clingon= itself for each new
command and provide flags for =–help=, =–version= and
=–bash-completions= for you automatically, so you don’t have to deal
with them manually.

Before we dive into testing out our application, first we will check
that we have a correct help information for our command.

#+begin_src lisp
INTRO> (clingon:print-usage *app* t)
NAME:
clingon-intro - my first clingon cli app

USAGE:
clingon-intro [-v] [-u <USER>]

OPTIONS:
–help display usage information and exit
–version display version and exit
-u, –user <VALUE> user to greet [default: stranger] [env: $USER]
-v, –verbose verbosity level [default: 0]

AUTHORS:
John Doe <john.doe@example.com>

LICENSE:
BSD 2-Clause

NIL
#+end_src

This help information will make it easier for our users, when they
need to use it. And that is automatically handled for you, so you
don’t have to manually maintain an up-to-date usage information, each
time you introduce a new option.

Time to test out our application on the REPL. In order to test things
out you can use the =CLINGON:PARSE-COMMAND-LINE= function by passing
it an instance of your command, along with any arguments that need to
be parsed. Let’s try it out without any command-line arguments.

#+begin_src lisp
INTRO> (clingon:parse-command-line *app* nil)
#<CLINGON.COMMAND:COMMAND name=clingon-intro options=5 sub-commands=0>
#+end_src

The =CLINGON:PARSE-COMMAND-LINE= function will (as the name suggests)
parse the given arguments against the options associated with our
command. Finally it will return an instance of =CLINGON:COMMAND=.

In our simple CLI application, that would be the same instance as our
=*APP*=, but things look differently when we have sub-commands.

When we start adding new sub-commands, the result of
=CLINGON:PARSE-COMMAND-LINE= will be different based on the arguments
it needs to parse. That means that if our input matches a sub-command
you will receive an instance of the sub-command that matched the given
arguments.

Internally the =clingon= system maintains a tree data structure,
describing the relationships between commands. This allows a command
to be related to some other command, and this is how the command and
sub-commands support is implemented in =clingon=.

Each command in =clingon= is associated with a /context/. The
/context/ or /environment/ provides the options and their values with
respect to the command itself. This means that a parent command and a
sub-command may have exactly the same set of options defined, but they
will reside in different contexts. Depending on how you use it,
sub-commands may /shadow/ a parent command option, but it also means
that a sub-command can refer to an option defined in a global command.

The /context/ of a command in =clingon= is available via the
=CLINGON:COMMAND-CONTEXT= accessor. We will use the context in order
to lookup our options and the values associated with them.

The function that operates on command’s context and retrieves
values from it is called =CLINGON:GETOPT=.

Let’s see what we’ve got for our options.

#+begin_src lisp
INTRO> (let ((c (clingon:parse-command-line *app* nil)))
(clingon:getopt c :user))
"dnaeon"
T
#+end_src

The =CLINGON:GETOPT= function returns multiple values – first one
specifies the value of the option, if it had any. And the second one
indicates whether or not that option has been set at all on the
command-line.

If you need to simply test things out and tell whether an option has
been set at all you can use the =CLINGON:OPT-IS-SET-P= function
instead.

Let’s try it out with a different input.

#+begin_src lisp
INTRO> (let ((c (clingon:parse-command-line *app* (list "-vvv" "–user" "foo"))))
(format t "Verbose is ~A~%" (clingon:getopt c :verbose))
(format t "User is ~A~%" (clingon:getopt c :user)))
Verbose is 3
User is foo
#+end_src

Something else, which is important to mention here. The default
precedence list for options is:

- The value provided by the =:INITIAL-VALUE= initarg
- The value of the first environment variable, which successfully resolved,
provided by the =:ENV-VARS= initarg
- The value provided on the command-line when invoking the application.

Play with it using different command-line arguments. If you specify
invalid or unknown options =clingon= will signal a condition and
provide you a few recovery options. For example, if you specify an
invalid flag like this:

#+begin_src lisp
INTRO> (clingon:parse-command-line *app* (list "–invalid-flag"))
#+end_src

We will be dropped into the debugger and be provided with restarts we
can choose from, e.g.

#+begin_src lisp
Unknown option –invalid-flag of kind LONG
[Condition of type CLINGON.CONDITIONS:UNKNOWN-OPTION]

Restarts:
0: [DISCARD-OPTION] Discard the unknown option
1: [TREAT-AS-ARGUMENT] Treat the unknown option as a free argument
2: [SUPPLY-NEW-VALUE] Supply a new value to be parsed
3: [RETRY] Retry SLY mREPL evaluation request.
4: [ABORT] Return to sly-db level 1.
5: [RETRY] Retry SLY mREPL evaluation request.
–more–
...
#+end_src

This is similar to the way other Common Lisp options parsing systems
behave such as [[https://github.com/sjl/adopt][adopt]] and [[https://github.com/libre-man/unix-opts][unix-opts]].

Also worth mentioning again here is that =CLINGON:PARSE-COMMAND-LINE= is
meant to be used within the REPL, and not called directly by handlers.

** Adding a sub-command

Sub-commands are no different than regular commands, and in fact are
created exactly the way we did it for our /top-level/ command.

#+begin_src lisp
(defun shout/handler (cmd)
"The handler for the ‘shout’ command"
(let ((args (mapcar #’string-upcase (clingon:command-arguments cmd)))
(user (clingon:getopt cmd :user))) ;; <- a global option
(format t "HEY, ~A!~%" user)
(format t "~A!~%" (clingon:join-list args #\Space))))

(defun shout/command ()
"Returns a command which SHOUTS back anything we write on the command-line"
(clingon:make-command
:name "shout"
:description "shouts back anything you write"
:usage "[options] [arguments ...]"
:handler #’shout/handler))
#+end_src

And now, we will wire up our sub-command making it part of the
/top-level/ command we have so far.

#+begin_src lisp
(defun top-level/command ()
"Creates and returns the top-level command"
(clingon:make-command
:name "clingon-intro"
...
:sub-commands (list (shout/command)))) ;; <- new code
#+end_src

You should also notice here that within the =SHOUT/HANDLER= we are
actually referencing an option, which is defined somewhere else. This
option is actually defined on our top-level command, but thanks’s to
the automatic management of relationships that =clingon= provides we
can now refer to global options as well.

Let’s move on to the final section of this guide, where we will create
a system definition for our application and build it.

** Packaging it up

One final piece which remains to be added to our code is to provide an
entrypoint for our application, so let’s do it now.

#+begin_src lisp
(defun main ()
(let ((app (top-level/command)))
(clingon:run app)))
#+end_src

This is the entrypoint which will be used when we invoke our
application on the command-line, which we’ll set in our ASDF
definition.

And here’s a simple system definition for the application we’ve
developed so far.

#+begin_src lisp
(defpackage :clingon-intro-system
(:use :cl :asdf))
(in-package :clingon-intro-system)

(defsystem "clingon.intro"
:name "clingon.intro"
:long-name "clingon.intro"
:description "An introduction to the clingon system"
:version "0.1.0"
:author "John Doe <john.doe@example.org>"
:license "BSD 2-Clause"
:depends-on (:clingon)
:components ((:module "intro"
:pathname #P"examples/intro/"
:components ((:file "intro"))))
:build-operation "program-op"
:build-pathname "clingon-intro"
:entry-point "clingon.intro:main")
#+end_src

Now we can build our application and start using it on the
command-line.

#+begin_src shell
sbcl –eval ’(ql:quickload :clingon.intro)’ \
–eval ’(asdf:make :clingon.intro)’ \
–eval ’(quit)’
#+end_src

This will produce a new binary called =clingon-intro= in the directory
of the =clingon.intro= system.

** Testing it out on the command-line

Time to check things up on the command-line.

#+begin_src shell
$ ./clingon-intro –help
NAME:
clingon-intro - my first clingon cli app

USAGE:
clingon-intro [-v] [-u <USER>]

OPTIONS:
–help display usage information and exit
–version display version and exit
-u, –user <VALUE> user to greet [default: stranger] [env: $USER]
-v, –verbose verbosity level [default: 0]

COMMANDS:
shout shouts back anything you write

AUTHORS:
John Doe <john.doe@example.com>

LICENSE:
BSD 2-Clause
#+end_src

Let’s try out our commands.

#+begin_src shell
$ ./clingon-intro -vvv –user Lisper
Hello, Lisper!
The current verbosity level is set to 3
You have provided 0 arguments
Bye.
#+end_src

And let’s try our sub-command as well.

#+begin_src shell
$ ./clingon-intro –user stranger shout why are yelling at me?
HEY, stranger!
WHY ARE YELLING AT ME?!
#+end_src

You can find the full code we’ve developed in this guide in the
[[https://github.com/dnaeon/clingon/tree/master/examples][clingon/examples]] directory of the repo.

* Exiting

When a command needs to exit with a given status code you can use the
=CLINGON:EXIT= function.

* Handling SIGINT (CTRL-C) signals

=clingon= by default will provide a handler for =SIGINT= signals,
which when detected will cause the application to immediately exit
with status code =130=.

If your commands need to provide some cleanup logic as part of their
job, e.g. close out all open files, TCP session, etc., you could wrap
your =clingon= command handlers in [[http://www.lispworks.com/documentation/HyperSpec/Body/s_unwind.htm][UNWIND-PROTECT]] to make sure that
your cleanup tasks are always executed.

However, using [[http://www.lispworks.com/documentation/HyperSpec/Body/s_unwind.htm][UNWIND-PROTECT]] may not be appropriate in all cases,
since the cleanup forms will always be executed, which may or may not
be what you need.

For example if you are developing a =clingon= application, which
populates a database in a transaction you would want to use
[[http://www.lispworks.com/documentation/HyperSpec/Body/s_unwind.htm][UNWIND-PROTECT]], but only for releasing the database connection itself.

If the application is interrupted while it inserts or updates records,
what you want to do is to rollback the transaction as well, so your
database is left in a consistent state.

In those situations you would want to use the [[https://github.com/compufox/with-user-abort][WITH-USER-ABORT]] system,
so that your =clingon= command can detect the =SIGINT= signal and act
upon it, e.g. taking care of rolling back the transaction.

* Generating Documentation

=clingon= can generate documentation for your application by using the
=CLINGON:PRINT-DOCUMENTATION= generic function.

Currently the documentation generator supports only the /Markdown/
format, but other formats can be developed as separate extensions to
=clingon=.

Here’s how you can generate the Markdown documentation for the
=clingon-demo= application from the REPL.

#+begin_src lisp
CL-USER> (ql:quickload :clingon.demo)
CL-USER> (in-package :clingon.demo)
DEMO> (with-open-file (out #P"clingon-demo.md" :direction :output)
(clingon:print-documentation :markdown (top-level/command) out))
#+end_src

You can also create a simple command, which can be added to your
=clingon= apps and have it generate the documentation for you, e.g.

#+begin_src lisp
(defun print-doc/command ()
"Returns a command which will print the app’s documentation"
(clingon:make-command
:name "print-doc"
:description "print the documentation"
:usage ""
:handler (lambda (cmd)
;; Print the documentation starting from the parent
;; command, so we can traverse all sub-commands in the
;; tree.
(clingon:print-documentation :markdown (clingon:command-parent cmd) t))))
#+end_src

Above command can be wired up anywhere in your application.

Make sure to also check the =clingon-demo= app, which provides a
=print-doc= sub-command, which operates on the /top-level/ command and
generates the documentation for all sub-commands.

You can also find the generated documentation for the =clingon-demo=
app in the =docs/= directory of the =clingon= repo.

* Command Hooks

=clingon= allows you to associate =pre= and =post= hooks with a
command.

The =pre= and =post= hooks are functions which will be invoked before
and after the respective command handler is executed. They are useful
in cases when you need to set up or tear things down before executing
the command’s handler.

An example of a =pre-hook= might be to configure the logging level of
your application based on the value of a global flag. A =post-hook=
might be responsible for shutting down any active connections, etc.

The =pre-hook= and =post-hook= functions accept a single argument,
which is an instance of =CLINGON:COMMAND=. That way the hooks can
examine the command’s context and lookup any flags or options.

Hooks are also hierachical in the sense that they will be executed
based on the command’s lineage.

Consider the following example, where we have a CLI app with three
commands.

#+begin_src text
main -> foo -> bar
#+end_src

In above example the =bar= command is a sub-command of =foo=, which in
turn is a sub-command of =main=. Also, consider that we have added
pre- and post-hooks to each command.

If a user executed the following on the command-line:

#+begin_src shell
$ main foo bar
#+end_src

Based on the above command-line =clingon= would do the following:

- Execute any =pre-hook= functions starting from the least-specific up to the
most-specific node from the commands’ lineage
- Execute the command’s handler
- Execute any =post-hook= functions starting from the most-specific down to the
least-specific node from the command’s lineage

In above example that would be:

#+begin_src text
> main (pre-hook)
>> foo (pre-hook)
>>> bar (pre-hook)
>>>> bar (handler)
>>> bar (post-hook)
>> foo (post-hook)
> main (post-hook)
#+end_src

Associating hooks with commands is done during instantiation of a
command. The following example creates a new command with a =pre-hook=
and =post-hook=.

#+begin_src lisp
(defun foo/pre-hook (cmd)
"The pre-hook for ‘foo’ command"
(declare (ignore cmd))
(format t "foo pre-hook has been invoked~&"))

(defun foo/post-hook (cmd)
"The post-hook for ‘foo’ command"
(declare (ignore cmd))
(format t "foo post-hook has been invoked~&"))

(defun foo/handler (cmd)
(declare (ignore cmd))
(format t "foo handler has been invoked~&"))

(defun foo/command ()
"Returns the ‘foo’ command"
(clingon:make-command
:name "foo"
:description "the foo command"
:authors ’("John Doe <john.doe@example.org>")
:handler #’foo/handler
:pre-hook #’foo/pre-hook
:post-hook #’foo/post-hook
:options nil
:sub-commands nil))
#+end_src

If we have executed above command we would see the following output.

#+begin_src shell
foo pre-hook has been invoked
foo handler has been invoked
foo post-hook has been invoked
#+end_src

* Options

The =clingon= system supports various kinds of options, each of which
is meant to serve a specific purpose.

Each builtin option can be initialized via environment variables, and
new mechanisms for initializing options can be developed, if needed.

Options are created via the single =CLINGON:MAKE-OPTION= interface.

The supported option kinds include:

- =counter=
- =integer=
- =string=
- =boolean=
- =boolean/true=
- =boolean/false=
- =choice=
- =enum=
- =list=
- =list/integer=
- =filepath=
- =list/filepath=
- etc.

** Counters Options

A =counter= is an option kind, which increments every time it is set
on the command-line.

A good example for =counter= options is to provide a flag, which
increases the verbosity level, depending on the number of times the
flag was provided, similar to the way =ssh(1)= does it, e.g.

#+begin_src shell
ssh -vvv user@host
#+end_src

Here’s an example of creating a =counter= option.

#+begin_src lisp
(clingon:make-option
:counter
:short-name #\v
:long-name "verbose"
:description "how noisy we want to be"
:key :verbose)
#+end_src

The default =step= for counters is set to =1=, but you can change
that, if needed.

#+begin_src lisp
(clingon:make-option
:counter
:short-name #\v
:long-name "verbose"
:description "how noisy we want to be"
:step 42
:key :verbose)
#+end_src

** Boolean Options

The following boolean option kinds are supported by =clingon=.

The =:boolean= kind is an option which expects an argument, which
represents a boolean value.

Arguments =true= and =1= map to =T= in Lisp, anything else is
considered a falsey value and maps to =NIL=.

#+begin_src lisp
(clingon:make-option
:boolean
:description "my boolean"
:short-name #\b
:long-name "my-boolean"
:key :boolean)
#+end_src

This creates an option =-b, –my-boolean <VALUE>=, which can be
provided on the command-line, where =<VALUE>= should be =true= or =1=
for truthy values, and anything else maps to =NIL=.

The =:boolean/true= option kind creates a flag, which always returns
=T=.

The =:boolean/false= option kind creates a flag, which always returns
=NIL=.

The =:flag= option kind is an alias for =:boolean/true=.

** Integer Options

Here’s an example of creating an option, which expects an integer
argument.

#+begin_src lisp
(clingon:make-option
:integer
:description "my integer opt"
:short-name #\i
:long-name "int"
:key :my-int
:initial-value 42)
#+end_src

** Choice Options

=choice= options are useful when you have to limit the arguments
provided on the command-line to a specific set of values.

For example:

#+begin_src lisp
(clingon:make-option
:choice
:description "log level"
:short-name #\l
:long-name "log-level"
:key :choice
:items ’("info" "warn" "error" "debug"))
#+end_src

With this option defined, you can now set the logging level only to
=info=, =warn=, =error= or =debug=, e.g.

#+begin_src shell
-l, –log-level [info|warn|error|debug]
#+end_src

** Enum Options

Enum options are similar to the =choice= options, but instead of
returning the value itself they can be mapped to something else.

For example:

#+begin_src lisp
(clingon:make-option
:enum
:description "enum option"
:short-name #\e
:long-name "my-enum"
:key :enum
:items ’(("one" . 1)
("two" . 2)
("three" . 3)))
#+end_src

If a user specifies =–my-enum=one= on the command-line the option
will be have the value =1= associated with it, when being looked up
via =CLINGON:GETOPT=.

The values you associate with the enum variant, can be any object.

This is one of the options being used by the /clingon-demo/
application, which maps user input to Lisp functions, in order to
perform some basic math operations.

#+begin_src lisp
(clingon:make-option
:enum
:description "operation to perform"
:short-name #\o
:long-name "operation"
:required t
:items ‘(("add" . ,#’+)
("sub" . ,#’-)
("mul" . ,#’*)
("div" . ,#’/))
:key :math/operation)
#+end_src

** List / Accumulator Options

The =:list= option kind accumulates each argument it is given on the
command-line into a list.

For example:

#+begin_src lisp
(clingon:make-option
:list
:description "files to process"
:short-name #\f
:long-name "file"
:key :files)
#+end_src

If you invoke an application, which uses a similar option like the one
above using the following command-line arguments:

#+begin_src shell
$ my-app –file foo –file bar –file baz
#+end_src

When you retrieve the value associated with your option, you will get a
list of all the files specified on the command-line, e.g.

#+begin_src lisp
(clingon:getopt cmd :files) ;; => ’("foo" "bar" "baz")
#+end_src

A similar option exists for integer values using the =:list/integer=
option, e.g.

#+begin_src lisp
(clingon:make-option
:list/integer
:description "list of integers"
:short-name #\l
:long-name "int"
:key :integers)
#+end_src

** Switch Options

=:SWITCH= options are a variation of =:BOOLEAN= options with an
associated list of known states that can turn a switch /on/ or
/off/.

Here is an example of a =:SWITCH= option.

#+begin_src lisp
(clingon:make-option
:switch
:description "my switch option"
:short-name #\s
:long-name "state"
:key :switch)
#+end_src

The default states for a switch to be considered as /on/ are:

- /on/, /yes/, /true/, /enable/ and /1/

The default states considered to turn the switch /off/ are:

- /off/, /no/, /false/, /disable/ and /0/

You can customize the list of /on/ and /off/ states by specifying them
using the =:ON-STATES= and =:OFF-STATES= initargs, e.g.

#+begin_src lisp
(clingon:make-option
:switch
:description "engine switch option"
:short-name #\s
:long-name "state"
:on-states ’("start")
:off-states ’("stop")
:key :engine)
#+end_src

These sample command-line arguments will turn a switch on and off.

#+begin_src shell
my-app –engine=start –engine=stop
#+end_src

The final value of the =:engine= option will be =NIL= in the above
example.

* Generic Functions Operating on Options

If the existing options provided by =clingon= are not enough for you,
and you need something a bit more specific for your use case, then you
can always implement a new option kind.

The following generic functions operate on options and are exported by
the =clingon= system.

- =CLINGON:INITILIAZE-OPTION=
- =CLINGON:FINALIZE-OPTION=
- =CLINGON:DERIVE-OPTION-VALUE=
- =CLINGON:OPTION-USAGE-DETAILS=
- =CLINGON:OPTION-DESCRIPTION-DETAILS=
- =CLINGON:MAKE-OPTION=

New option kinds should inherit from the =CLINGON:OPTION= class, which
implements all of the above generic functions. If you need to
customize the behaviour of your new option, you can still override the
default implementations.

** CLINGON:INITIALIZE-OPTION

The =CLINGON:INITIALIZE-OPTION= as the name suggests is being used to
initialize an option.

The default implementation of this generic function supports
initialization from environment variables, but implementors
can choose to support other initialization methods, e.g.
be able to initialize an option from a key/value store like
/Redis/, /Consul/ or /etcd/ for example.

** CLINGON:FINALIZE-OPTION

The =CLINGON:FINALIZE-OPTION= generic function is called after
all command-line arguments have been processed and values for them
have been derived already.

=CLINGON:FINALIZE-OPTION= is meant to /finalize/ the option’s value,
e.g. transform it to another object, if needed.

For example the =:BOOLEAN= option kind transforms user-provided input
like =true=, =false=, =1= and =0= into their respective Lisp counterparts
like =T= and =NIL=.

Another example where you might want to customize the behaviour of
=CLINGON:FINALIZE-OPTION= is to convert a string option provided on
the command-line, which represents a database connection string into
an actual session object for the database.

The default implementation of this generic function simply returns the
already set value, e.g. calls =#’IDENTITY= on the last derived value.

** CLINGON:DERIVE-OPTION-VALUE

The =CLINGON:DERIVE-OPTION-VALUE= is called whenever an option is
provided on the command-line.

If that option accepts an argument, it will be passed the respective
value from the command-line, otherwise it will be called with a =NIL=
argument.

Responsibility of the option is to derive a value from the given input
and return it to the caller. The returned value will be set by the
parser and later on it will be used to produce a final value, by
calling the =CLINGON:FINALIZE-OPTION= generic function.

Different kinds of options implement this one different – for example
the =:LIST= option kind accumulates each given argument, while others
ignore any previously derived values and return the last provided
argument.

The =:ENUM= option kind for example will derive a value from a
pre-defined list of allowed values.

If an option fails to derive a value (e.g. invalid value has been
provided) the implementation of this generic function should signal a
=CLINGON:OPTION-DERIVE-ERROR= condition, so that =clingon= can provide
appropriate restarts.

** CLINGON:OPTION-USAGE-DETAILS

This generic function is used to provide a pretty-printed usage format
for the given option. It will be used when printing usage information
on the command-line for the respective commands.

** CLINGON:OPTION-DESCRIPTION-DETAILS

This generic function is meant to enrich the description of the option
by providing as much details as possible for the given option, e.g.
listing the available values that an option can accept.

** CLINGON:MAKE-OPTION

The =CLINGON:MAKE-OPTION= generic function is the primary way for
creating new options. Implementors of new option kinds should simply
provide an implementation of this generic function, along with the
respective option kind.

Additional option kinds may be implemented as separate sub-systems,
but still follow the same principle by providing a single and
consistent interface for option creation.

* Developing New Options

This section contains short guides explaining how to develop new
options for =clingon=.

** Developing an Email Option

The option which we’ll develop in this section will be used for
specifying email addresses.

Start up your Lisp REPL session and do let’s some work. Load the
=:clingon= and =:cl-ppcre= systems, since we will need them.

#+begin_src lisp
CL-USER> (ql:quickload :clingon)
CL-USER> (ql:quickload :cl-ppcre)
#+end_src

We will first create a new package for our extension and import the
symbols we will need from the =:clingon= and =:cl-ppcre= systems.

#+begin_src lisp
(defpackage :clingon.extensions/option-email
(:use :cl)
(:import-from
:cl-ppcre
:scan)
(:import-from
:clingon
:option
:initialize-option
:derive-option-value
:make-option
:option-value
:option-derive-error)
(:export
:option-email))
(in-package :clingon.extensions/option-email)
#+end_src

Then lets define the class, which will represent an email address
option.

#+begin_src lisp
(defclass option-email (option)
((pattern
:initarg :pattern
:initform "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"
:reader option-email-pattern
:documentation "Pattern used to match for valid email addresses"))
(:default-initargs
:parameter "EMAIL")
(:documentation "An option used to represent an email address"))
#+end_src

Now we will implement =CLINGON:INITIALIZE-OPTION= for our new
option. We will keep the default initialization logic as-is, but also
add an additional step to validate the email address, if we have any
initial value at all.

#+begin_src lisp
(defmethod initialize-option ((option option-email) &key)
"Initializes our new email address option"
;; Make sure to invoke our parent initialization method first, so
;; various things like setting up initial value from environment
;; variables can still be applied.
(call-next-method)

;; If we don’t have any value set, there’s nothing else to
;; initialize further here.
(unless (option-value option)
(return-from initialize-option))

;; If we get to this point, that means we’ve got some initial value,
;; which is either set as a default, or via environment
;; variables. Next thing we need to do is make sure we’ve got a good
;; initial value, so let’s derive a value from it.
(let ((current (option-value option)))
(setf (option-value option)
(derive-option-value option current))))
#+end_src

Next we will implement =CLINGON:DERIVE-OPTION-VALUE= for our new
option kind.

#+begin_src lisp
(defmethod derive-option-value ((option option-email) arg &key)
"Derives a new value based on the given argument.
If the given ARG represents a valid email address according to the
pattern we know of we consider this as a valid email address."
(unless (scan (option-email-pattern option) arg)
(error ’option-derive-error :reason (format nil "~A is not a valid email address" arg)))
arg)
#+end_src

Finally, lets register our new option as a valid kind by implemeting
the =CLINGON:MAKE-OPTION= generic function.

#+begin_src lisp
(defmethod make-option ((kind (eql :email)) &rest rest)
(apply #’make-instance ’option-email rest))
#+end_src

We can test things out now. Go back to your REPL and try these
expressions out. First we make a new instance of our new option.

#+begin_src lisp
(defparameter *opt*
(make-option :email :short-name #\e :description "email opt" :key :email))
#+end_src

And now, lets validate a couple of good email addresses.

#+begin_src lisp
EXTENSIONS/OPTION-EMAIL> (derive-option-value *opt* "test@example.com")
"test@example.com"
EXTENSIONS/OPTION-EMAIL> (derive-option-value *opt* "foo@bar.com")
"foo@bar.com"
#+end_src

If we try deriving a value from a bad email address we will have a
condition of type =CLINGON:OPTION-DERIVE-ERROR= signalled.

#+begin_src lisp
EXTENSIONS/OPTION-EMAIL> (derive-option-value opt "bad-email-address-here")
; Debugger entered on #<OPTION-DERIVE-ERROR {1002946463}>
...
bad-email-address-here is not a valid email address
[Condition of type OPTION-DERIVE-ERROR]
#+end_src

Good, we can catch invalid email addresses as well. Whenever an option
fails to derive a new value from a given argument, and we signal
=CLINGON:OPTION-DERIVE-ERROR= condition we can recover by providing
new values or discarding them completely, thanks to the Common Lisp
Condition System.

Last thing to do is actually package this up as an extension system
and register it in Quicklisp. That way everyone else can benefit from
the newly developed option.

* Shell Completions

=clingon= provides support for Bash and Zsh shell completions.

** Bash Completions

In order to enable the Bash completions for your =clingon= app,
follow these instructions.

#+begin_src shell
APP=app-name source extras/completions.bash
#+end_src

Make sure to set =APP= to your correct application name.

The [[https://github.com/dnaeon/clingon/blob/master/extras/completions.bash][completions.bash]] script will dynamically provide completions by
invoking the =clingon= app with the =–bash-completions= flag. This
builtin flag when provided on the command-line will return completions
for the sub-commands and the available flags.

** Zsh Completions

When developing your CLI app with =clingon= you can provide an
additional command, which will take care of generating the Zsh
completion script for your users.

The following code can be used in your app and added as a sub-command
to your top-level command.

#+begin_src lisp
(defun zsh-completion/command ()
"Returns a command for generating the Zsh completion script"
(clingon:make-command
:name "zsh-completion"
:description "generate the Zsh completion script"
:usage ""
:handler (lambda (cmd)
;; Use the parent command when generating the completions,
;; so that we can traverse all sub-commands in the tree.
(let ((parent (clingon:command-parent cmd)))
(clingon:print-documentation :zsh-completions parent t)))))
#+end_src

You can also check out the =clingon-demo= app for a fully working CLI
app with Zsh completions support.

[[./images/clingon-zsh-completions.gif]]

* Ideas For Future Improvements

** Additional Documentation Generators

As of now =clingon= supports generating documentation only in /Markdown/
format.

Would be nice to have additional documentation generators, e.g.
/man pages/, /HTML/, etc.

** Performance Notes

=clingon= has been developed and tested on a GNU/Linux system using
SBCL.

Performance of the resulting binaries with SBCL seem to be good,
although I have noticed better performance when the binaries have been
produced with Clozure CL. And by better I mean better in terms of
binary size and speed (startup + run time).

Although you can enable compression on the image when using SBCL you
have to pay the extra price for the startup time.

Here are some additional details. Build the =clingon-demo= app with
SBCL.

#+begin_src shell
$ LISP=sbcl make demo
sbcl –eval ’(ql:quickload :clingon.demo)’ \
–eval ’(asdf:make :clingon.demo)’ \
–eval ’(quit)’
This is SBCL 2.1.7, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
To load "clingon.demo":
Load 1 ASDF system:
clingon.demo
; Loading "clingon.demo"
[package clingon.utils]...........................
[package clingon.conditions]......................
[package clingon.options].........................
[package clingon.command].........................
[package clingon].................................
[package clingon.demo]
[undoing binding stack and other enclosing state... done]
[performing final GC... done]
[defragmenting immobile space... (fin,inst,fdefn,code,sym)=1118+969+19070+19610+26536... done]
[saving current Lisp image into /home/dnaeon/Projects/lisp/clingon/clingon-demo:
writing 0 bytes from the read-only space at 0x50000000
writing 736 bytes from the static space at 0x50100000
writing 31391744 bytes from the dynamic space at 0x1000000000
writing 2072576 bytes from the immobile space at 0x50200000
writing 12341248 bytes from the immobile space at 0x52a00000
done]
#+end_src

Now, build it using Clozure CL.

#+begin_src shell
$ LISP=ccl make demo
ccl –eval ’(ql:quickload :clingon.demo)’ \
–eval ’(asdf:make :clingon.demo)’ \
–eval ’(quit)’
To load "clingon.demo":
Load 1 ASDF system:
clingon.demo
; Loading "clingon.demo"
[package clingon.utils]...........................
[package clingon.conditions]......................
[package clingon.options].........................
[package clingon.command].........................
[package clingon].................................
[package clingon.demo].
#+end_src

In terms of file size the binaries produced by Clozure CL are smaller.

#+begin_src shell
$ ls -lh clingon-demo*
-rwxr-xr-x 1 dnaeon dnaeon 33M Aug 20 12:56 clingon-demo.ccl
-rwxr-xr-x 1 dnaeon dnaeon 45M Aug 20 12:55 clingon-demo.sbcl
#+end_src

Generating the Markdown documentation for the demo app when using the
SBCL executable looks like this.

#+begin_src shell
$ time ./clingon-demo.sbcl print-doc > /dev/null

real 0m0.098s
user 0m0.071s
sys 0m0.027s
#+end_src

And when doing the same thing with the executable produced by Clozure
CL we see these results.

#+begin_src shell
$ time ./clingon-demo.ccl print-doc > /dev/null

real 0m0.017s
user 0m0.010s
sys 0m0.007s
#+end_src

* Tests

The =clingon= tests are provided as part of the =:clingon.test= system.

In order to run the tests you can evaluate the following expressions.

#+begin_src lisp
CL-USER> (ql:quickload :clingon.test)
CL-USER> (asdf:test-system :clingon.test)
#+end_src

Or you can run the tests using the =run-tests.sh= script instead, e.g.

#+begin_src shell
LISP=sbcl ./run-tests.sh
#+end_src

Here’s how to run the tests against SBCL, CCL and ECL for example.

#+begin_src shell
for lisp in sbcl ccl ecl; do
echo "Running tests using ${lisp} ..."
LISP=${lisp} make test > ${lisp}-tests.out
done
#+end_src

* Docker Images

A few Docker images are available.

Build and run the tests in a container.

#+begin_src shell
docker build -t clingon.test:latest -f Dockerfile.tests .
docker run –rm clingon.test:latest
#+end_src

Build and run the =clingon-intro= application.

#+begin_src shell
docker build -t clingon.intro:latest -f Dockerfile.intro .
docker run –rm clingon.intro:latest
#+end_src

Build and run the =clingon.demo= application.

#+begin_src lisp
docker build -t clingon.demo:latest -f Dockerfile.demo .
docker run –rm clingon.demo:latest
#+end_src

* Contributing

=clingon= is hosted on [[https://github.com/dnaeon/clingon][Github]]. Please contribute by reporting issues,
suggesting features or by sending patches using pull requests.

* License

This project is Open Source and licensed under the [[http://opensource.org/licenses/BSD-2-Clause][BSD License]].

* Authors

- Marin Atanasov Nikolov <dnaeon@gmail.com>

Version

0.3.5

Dependencies
  • uiop (system).
  • bobbin (system).
  • cl-reexport (system).
  • split-sequence (system).
  • with-user-abort (system).
Source

clingon.asd.

Child Components

3 Modules

Modules are listed depth-first from the system components tree.


Next: , Previous: , Up: Modules   [Contents][Index]

3.1 clingon/utils

Source

clingon.asd.

Parent Component

clingon (system).

Child Component

utils.lisp (file).


3.2 clingon/core

Dependency

utils (module).

Source

clingon.asd.

Parent Component

clingon (system).

Child Components

Previous: , Up: Modules   [Contents][Index]

3.3 clingon/client-package

Dependency

core (module).

Source

clingon.asd.

Parent Component

clingon (system).

Child Component

package.lisp (file).


4 Files

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


Previous: , Up: Files   [Contents][Index]

4.1 Lisp


Next: , Previous: , Up: Lisp   [Contents][Index]

4.1.1 clingon/clingon.asd

Source

clingon.asd.

Parent Component

clingon (system).

ASDF Systems

clingon.

Packages

clingon-system.


4.1.2 clingon/utils/utils.lisp

Source

clingon.asd.

Parent Component

utils (module).

Packages

clingon.utils.

Public Interface
Internals

argv (function).


4.1.3 clingon/core/conditions.lisp

Source

clingon.asd.

Parent Component

core (module).

Packages

clingon.conditions.

Public Interface

4.1.4 clingon/core/options.lisp

Source

clingon.asd.

Parent Component

core (module).

Packages

clingon.options.

Public Interface
Internals

4.1.5 clingon/core/command.lisp

Dependencies
Source

clingon.asd.

Parent Component

core (module).

Packages

clingon.command.

Public Interface
Internals

4.1.6 clingon/client-package/package.lisp

Source

clingon.asd.

Parent Component

client-package (module).

Packages

clingon.


5 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

5.1 clingon

Source

package.lisp.

Use List

common-lisp.


Next: , Previous: , Up: Packages   [Contents][Index]

5.2 clingon.options

Source

options.lisp.

Use List

common-lisp.

Public Interface
Internals

Next: , Previous: , Up: Packages   [Contents][Index]

5.3 clingon-system

Source

clingon.asd.

Use List
  • asdf/interface.
  • common-lisp.

Next: , Previous: , Up: Packages   [Contents][Index]

5.4 clingon.command

Source

command.lisp.

Use List

common-lisp.

Public Interface
Internals

5.5 clingon.utils

Source

utils.lisp.

Use List

common-lisp.

Public Interface
Internals

argv (function).


Previous: , Up: Packages   [Contents][Index]

5.6 clingon.conditions

Source

conditions.lisp.

Use List

common-lisp.

Public Interface

6 Definitions

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


Next: , Previous: , Up: Definitions   [Contents][Index]

6.1 Public Interface


Next: , Previous: , Up: Public Interface   [Contents][Index]

6.1.1 Special variables

Special Variable: *end-of-options-marker*

A marker specifying the end of options

Package

clingon.options.

Source

options.lisp.


6.1.2 Macros

Macro: with-command-tree ((node top-level) &body body)

Evaluates BODY for each node in the command’s tree starting from TOP-LEVEL

Package

clingon.command.

Source

command.lisp.


6.1.3 Ordinary functions

Function: discard-option (condition)

A handler which can be used to invoke the ‘discard-option’ restart

Package

clingon.command.

Source

command.lisp.

Function: end-of-options-p (arg)

A predicate which returns T if the given argument specifies end of options

Package

clingon.options.

Source

options.lisp.

Function: exit (&optional code)

Exit the program returning the given status code

Package

clingon.utils.

Source

utils.lisp.

Function: git-rev-parse (&key short rev path)

Returns the git revision with the given REV

Package

clingon.utils.

Source

utils.lisp.

Function: group-by (sequence predicate)

Groups the items from SEQUENCE based on the result from PREDICATE

Package

clingon.utils.

Source

utils.lisp.

Function: hashtable-keys (htable)

Returns the keys from the given hashtable

Package

clingon.utils.

Source

utils.lisp.

Function: hashtable-values (htable)

Returns the values from the given hashtable

Package

clingon.utils.

Source

utils.lisp.

Function: join-list (list separator)

Returns a string representing the items in the given LIST with SEPARATOR between each item

Package

clingon.utils.

Source

utils.lisp.

Function: long-option-p (arg)

A predicate which returns T if the given argument is a long option

Package

clingon.options.

Source

options.lisp.

Function: make-command (&rest rest)

Creates a new COMMAND instance

Package

clingon.command.

Source

command.lisp.

Function: missing-option-argument-p (value)
Package

clingon.conditions.

Source

conditions.lisp.

Function: option-derive-error-p (value)
Package

clingon.conditions.

Source

conditions.lisp.

Function: short-option-p (arg)

A predicate which returns T if the given argument is a short option

Package

clingon.options.

Source

options.lisp.

Function: treat-as-argument (condition)

A handler which can be used to invoke the ‘treat-as-argument’ restart

Package

clingon.command.

Source

command.lisp.

Function: unknown-option-p (value)
Package

clingon.conditions.

Source

conditions.lisp.

Function: walk (root neighbors-func &key order)

Walks a tree structure starting from ROOT. Neighbors of each node are discovered by invoking the NEIGHBORS-FUNC function, which should accept a single argument – the node we are currently visiting, and should return a list of adjacent nodes.

The ORDER should be either :dfs or :bfs for Depth-First Search or Breadth-First Search respectively.

Package

clingon.utils.

Source

utils.lisp.


6.1.4 Generic functions

Generic Function: apply-hooks (kind command &key)

Applies any hooks associated with the given COMMAND

Package

clingon.command.

Source

command.lisp.

Methods
Method: apply-hooks ((kind (eql :post)) (command command) &key)

Applies the post-hooks associated with command’s lineage
starting from the most-specific node down to the least-specific one

Method: apply-hooks ((kind (eql :pre)) (command command) &key)

Applies any pre-hooks associated with the command’s lineage starting from the least-specific node up to the most-specific one.

Generic Reader: circular-dependency-items (condition)
Package

clingon.conditions.

Methods
Reader Method: circular-dependency-items ((condition circular-dependency))
Source

conditions.lisp.

Target Slot

items.

Generic Reader: command-aliases (object)
Package

clingon.command.

Methods
Reader Method: command-aliases ((command command))

Aliases of the command

Source

command.lisp.

Target Slot

aliases.

Generic Reader: command-args-to-parse (object)
Generic Writer: (setf command-args-to-parse) (object)
Package

clingon.command.

Methods
Reader Method: command-args-to-parse ((command command))
Writer Method: (setf command-args-to-parse) ((command command))

Arguments to be parsed based on the command options

Source

command.lisp.

Target Slot

args-to-parse.

Generic Reader: command-arguments (object)
Generic Writer: (setf command-arguments) (object)
Package

clingon.command.

Methods
Reader Method: command-arguments ((command command))
Writer Method: (setf command-arguments) ((command command))

Discovered free arguments after parsing the options

Source

command.lisp.

Target Slot

arguments.

Generic Reader: command-authors (object)
Package

clingon.command.

Methods
Reader Method: command-authors ((command command))

Authors of the command

Source

command.lisp.

Target Slot

authors.

Generic Reader: command-description (object)
Package

clingon.command.

Methods
Reader Method: command-description ((command command))

Short description of what the command does

Source

command.lisp.

Target Slot

description.

Generic Reader: command-examples (object)
Package

clingon.command.

Methods
Reader Method: command-examples ((command command))

A list of examples describing how to use the command

Source

command.lisp.

Target Slot

examples.

Generic Function: command-full-name (command)
Package

clingon.command.

Methods
Method: command-full-name ((command command))

Returns a string representing the full name of the command

Source

command.lisp.

Generic Function: command-full-path (command)
Package

clingon.command.

Methods
Method: command-full-path ((command command))

Returns the full path to the command

Source

command.lisp.

Generic Reader: command-handler (object)
Package

clingon.command.

Methods
Reader Method: command-handler ((command command))

A function which accepts a single argument. The
argument is an instance of the COMMAND class, which provides the context and environment for options.

Source

command.lisp.

Target Slot

handler.

Generic Function: command-is-top-level-p (top-level)
Package

clingon.command.

Methods
Method: command-is-top-level-p ((top-level command))

Returns T if the command is a top-level command, NIL otherwise

Source

command.lisp.

Generic Reader: command-license (object)
Package

clingon.command.

Methods
Reader Method: command-license ((command command))

License for the command

Source

command.lisp.

Target Slot

license.

Generic Function: command-lineage (command)
Package

clingon.command.

Methods
Method: command-lineage ((command command))

Returns the lineage of the command up to the root

Source

command.lisp.

Generic Reader: command-long-description (object)
Package

clingon.command.

Methods
Reader Method: command-long-description ((command command))

Long description of what the command does

Source

command.lisp.

Target Slot

long-description.

Generic Reader: command-name (object)
Package

clingon.command.

Methods
Reader Method: command-name ((command command))

Command name

Source

command.lisp.

Target Slot

name.

Generic Reader: command-options (object)
Generic Writer: (setf command-options) (object)
Package

clingon.command.

Methods
Reader Method: command-options ((command command))
Writer Method: (setf command-options) ((command command))

Command options

Source

command.lisp.

Target Slot

options.

Generic Reader: command-parent (object)
Generic Writer: (setf command-parent) (object)
Package

clingon.command.

Methods
Reader Method: command-parent ((command command))
Writer Method: (setf command-parent) ((command command))

Parent command. This one will be automatically set during instantiation.

Source

command.lisp.

Target Slot

parent.

Generic Reader: command-post-hook (object)
Package

clingon.command.

Methods
Reader Method: command-post-hook ((command command))

A post-hook is a function which will be invoked
after the command handler is executed. The function must accept a single argument, which is an instance of the COMMAND class.

Source

command.lisp.

Target Slot

post-hook.

Generic Reader: command-pre-hook (object)
Package

clingon.command.

Methods
Reader Method: command-pre-hook ((command command))

A pre-hook is a function which will be invoked
before the command handler is executed. The function must accept a single argument, which is an instance of the COMMAND class.

Source

command.lisp.

Target Slot

pre-hook.

Generic Reader: command-sub-commands (object)
Package

clingon.command.

Methods
Reader Method: command-sub-commands ((command command))

Sub-commands for the command

Source

command.lisp.

Target Slot

sub-commands.

Generic Function: command-tree (top-level)
Package

clingon.command.

Methods
Method: command-tree ((top-level command))

Collects the nodes representing the command’s tree starting from TOP-LEVEL

Source

command.lisp.

Generic Reader: command-usage (object)
Package

clingon.command.

Methods
Reader Method: command-usage ((command command))

Usage information for the command

Source

command.lisp.

Target Slot

usage.

Generic Function: command-usage-string (command)
Package

clingon.command.

Methods
Method: command-usage-string ((command command))

Returns the usage string for the given command

Source

command.lisp.

Generic Reader: command-version (object)
Package

clingon.command.

Methods
Reader Method: command-version ((command command))

Version of the command

Source

command.lisp.

Target Slot

version.

Generic Function: derive-option-value (option value &key)

Derives a new value for the option based on the given string VALUE

Package

clingon.options.

Source

options.lisp.

Methods
Method: derive-option-value ((option option-switch) arg &key)
Method: derive-option-value ((option option-enum) arg &key)
Method: derive-option-value ((option option-choice) arg &key)
Method: derive-option-value ((option option-list-integer) arg &key)
Method: derive-option-value ((option option-integer) arg &key)
Method: derive-option-value ((option option-list) arg &key)
Method: derive-option-value ((option option-counter) arg &key)
Method: derive-option-value ((option option-boolean-false) arg &key)
Method: derive-option-value ((option option-boolean-true) arg &key)
Method: derive-option-value ((option option-boolean) arg &key)
Method: derive-option-value ((option option) arg &key)
Generic Reader: duplicate-command-items (condition)
Package

clingon.conditions.

Methods
Reader Method: duplicate-command-items ((condition duplicate-commands))
Source

conditions.lisp.

Target Slot

items.

Generic Reader: duplicate-option-items (condition)
Package

clingon.conditions.

Methods
Reader Method: duplicate-option-items ((condition duplicate-options))
Source

conditions.lisp.

Target Slot

items.

Generic Reader: duplicate-option-kind (condition)
Package

clingon.conditions.

Methods
Reader Method: duplicate-option-kind ((condition duplicate-options))
Source

conditions.lisp.

Target Slot

kind.

Generic Reader: duplicate-option-name (condition)
Package

clingon.conditions.

Methods
Reader Method: duplicate-option-name ((condition duplicate-options))
Source

conditions.lisp.

Target Slot

name.

Generic Function: finalize-command (command &key)

Finalizes a command and derives the set of reduced options

Package

clingon.command.

Source

command.lisp.

Methods
Method: finalize-command ((command command) &key)

Finalizes the command and derives the reduced set of option values

Generic Function: finalize-option (option &key)

Finalizes an option, e.g. performs any value transformations

Package

clingon.options.

Source

options.lisp.

Methods
Method: finalize-option ((option option-list) &key)
Method: finalize-option ((option option-boolean) &key)
Method: finalize-option ((option option) &key)

Finalizes the value of the option

Generic Function: find-option (kind object name &key)

Returns the option of the given KIND and NAME, or NIL otherwise

Package

clingon.command.

Source

command.lisp.

Methods
Method: find-option ((kind (eql :long)) (command command) name &key)

Finds the option with the given long name

Method: find-option ((kind (eql :short)) (command command) name &key)

Finds the option with the given short name

Generic Function: find-sub-command (command name &key)
Package

clingon.command.

Methods
Method: find-sub-command ((command command) name &key)

Returns the sub-command with the given name or alias

Source

command.lisp.

Generic Function: getopt (command opt-key &optional default)
Package

clingon.command.

Methods
Method: getopt ((command command) opt-key &optional default)

Returns the value of the option with the given OPT-KEY,
by traversing the lineage of the given COMMAND,
starting from the most-specific to least-specific command.

Make sure to call GETOPT on a command, which has been
finalized.

For example, if we have the following command line:

$ my-app –verbose –some-flag foo-command –foo-flag bar-command –bar-flag –some-flag

Where ‘cmd’ is bound to the command named ‘bar-command’ then
the result of the following expression:

(clingon:getopt cmd :verbose)

Will return the global flag ‘–verbose’, which is associated with the
top-level ‘my-app’ command.

However, if we request the value of the ‘–some-flag’ option, which
is defined on both – ‘my-app’ and ‘bar-command’ then the following
expression:

(clingon:getopt cmd :bar-flag)

Will return the most-specific flag, which in this case is the one
defined on ‘bar-command’.

This approach allows sub-commands to re-use already defined global
flags and options, which are defined by other commands from their
lineage.

Source

command.lisp.

Generic Function: initialize-command (command &key)

Initializes a command

Package

clingon.command.

Source

command.lisp.

Methods
Method: initialize-command ((command command) &key)

Initializes the command and the options associated with it.

Generic Function: initialize-option (option &key)

Initializes an option, e.g. sets initial option value

Package

clingon.options.

Source

options.lisp.

Methods
Method: initialize-option ((option option-switch) &key)

Initializes the switch option kind

Method: initialize-option ((option option-enum) &key)
Method: initialize-option ((option option-choice) &key)
Method: initialize-option ((option option-list-integer) &key)
Method: initialize-option ((option option-integer) &key)

Initializes the integer option. In case the option was
first initialized by other means, such as environment variables, we make sure that the provided value is a valid integer.

Method: initialize-option ((option option-list) &key)

Initializes a list option. If the option has been initialized via environment variables, the initial value for the list would be represented as a string. This method will ensure that if the option is initialized from a string source it is represented as a valid list before deriving any other values for the option.

Method: initialize-option ((option option) &key)

Initialize the value of the option.

Environment variables take precedence over any initial-value configured for the option.

The first environment variable that resolves to a non-NIL result will be used to set the option.

Generic Reader: invalid-option-item (condition)
Package

clingon.conditions.

Methods
Reader Method: invalid-option-item ((condition invalid-option))
Source

conditions.lisp.

Target Slot

item.

Generic Reader: invalid-option-reason (condition)
Package

clingon.conditions.

Methods
Reader Method: invalid-option-reason ((condition invalid-option))
Source

conditions.lisp.

Target Slot

reason.

Generic Function: make-option (kind &rest rest)

Creates a new option of the given kind

Package

clingon.options.

Source

options.lisp.

Methods
Method: make-option ((kind (eql :switch)) &rest rest)
Method: make-option ((kind (eql :enum)) &rest rest)
Method: make-option ((kind (eql :choice)) &rest rest)
Method: make-option ((kind (eql :list/integer)) &rest rest)
Method: make-option ((kind (eql :integer)) &rest rest)
Method: make-option ((kind (eql :list/filepath)) &rest rest)
Method: make-option ((kind (eql :list)) &rest rest)
Method: make-option ((kind (eql :counter)) &rest rest)
Method: make-option ((kind (eql :boolean/false)) &rest rest)
Method: make-option ((kind (eql :flag)) &rest rest)
Method: make-option ((kind (eql :boolean/true)) &rest rest)
Method: make-option ((kind (eql :boolean)) &rest rest)
Method: make-option ((kind (eql :filepath)) &rest rest)
Method: make-option ((kind (eql :string)) &rest rest)
Method: make-option ((kind (eql :generic)) &rest rest)

Creates a generic option

Generic Reader: missing-option-argument-command (condition)
Package

clingon.conditions.

Methods
Reader Method: missing-option-argument-command ((condition missing-option-argument))
Source

conditions.lisp.

Target Slot

command.

Generic Reader: missing-option-argument-item (condition)
Package

clingon.conditions.

Methods
Reader Method: missing-option-argument-item ((condition missing-option-argument))
Source

conditions.lisp.

Target Slot

item.

Generic Reader: missing-required-option-value-command (condition)
Package

clingon.conditions.

Methods
Reader Method: missing-required-option-value-command ((condition missing-required-option-value))
Source

conditions.lisp.

Target Slot

command.

Generic Reader: missing-required-option-value-item (condition)
Package

clingon.conditions.

Methods
Reader Method: missing-required-option-value-item ((condition missing-required-option-value))
Source

conditions.lisp.

Target Slot

item.

Generic Function: opt-is-set-p (command opt-key)
Package

clingon.command.

Methods
Method: opt-is-set-p ((command command) opt-key)

Returns T if the OPT-KEY is defined anywhere in the command’s lineage

Source

command.lisp.

Generic Reader: option-category (object)
Package

clingon.options.

Methods
Reader Method: option-category ((option option))

Category for the option. Options with the same category will be grouped together

Source

options.lisp.

Target Slot

category.

Generic Reader: option-choice-items (object)
Package

clingon.options.

Methods
Reader Method: option-choice-items ((option-choice option-choice))

The available choices

Source

options.lisp.

Target Slot

items.

Generic Reader: option-counter-step (object)
Package

clingon.options.

Methods
Reader Method: option-counter-step ((option-counter option-counter))

Numeric value to increase the counter with

Source

options.lisp.

Target Slot

step.

Generic Reader: option-derive-error-reason (condition)
Package

clingon.conditions.

Methods
Reader Method: option-derive-error-reason ((condition option-derive-error))
Source

conditions.lisp.

Target Slot

reason.

Generic Reader: option-description (object)
Package

clingon.options.

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

Short description of the option

Source

options.lisp.

Target Slot

description.

Generic Function: option-description-details (kind object &key)

Returns a formatted and probably enriched content of the option’s description

Package

clingon.options.

Source

options.lisp.

Methods
Method: option-description-details ((kind (eql :zsh-option-spec)) (option option-switch) &key)
Method: option-description-details ((kind (eql :zsh-option-spec)) (option option-enum) &key)
Method: option-description-details ((kind (eql :default)) (option option-enum) &key)
Method: option-description-details ((kind (eql :zsh-option-spec)) (option option-choice) &key)
Method: option-description-details ((kind (eql :default)) (option option-choice) &key)
Method: option-description-details ((kind (eql :zsh-option-spec)) (option option-filepath) &key)
Method: option-description-details ((kind (eql :zsh-option-spec)) (option option) &key)
Method: option-description-details ((kind (eql :default)) (option option) &key)
Generic Reader: option-enum-items (object)
Package

clingon.options.

Methods
Reader Method: option-enum-items ((option-enum option-enum))

The enum variants and their associated values

Source

options.lisp.

Target Slot

items.

Generic Reader: option-env-vars (object)
Package

clingon.options.

Methods
Reader Method: option-env-vars ((option option))

List of env vars which can set the option value

Source

options.lisp.

Target Slot

env-vars.

Generic Reader: option-hidden-p (object)
Package

clingon.options.

Methods
Reader Method: option-hidden-p ((option option))

Whether or not this option will be hidden on the usage pages

Source

options.lisp.

Target Slot

hidden.

Generic Reader: option-initial-value (object)
Package

clingon.options.

Methods
Reader Method: option-initial-value ((option option))

Initial value for the option

Source

options.lisp.

Target Slot

initial-value.

Generic Reader: option-integer-radix (object)
Package

clingon.options.

Methods
Reader Method: option-integer-radix ((option-list-integer option-list-integer))

automatically generated reader method

Source

options.lisp.

Target Slot

radix.

Reader Method: option-integer-radix ((option-integer option-integer))

automatically generated reader method

Source

options.lisp.

Target Slot

radix.

Generic Reader: option-is-set-p (object)
Generic Writer: (setf option-is-set-p) (object)
Package

clingon.options.

Methods
Reader Method: option-is-set-p ((option option))
Writer Method: (setf option-is-set-p) ((option option))

Predicate which returns T if the option was set

Source

options.lisp.

Target Slot

is-set-p.

Generic Reader: option-key (object)
Package

clingon.options.

Methods
Reader Method: option-key ((option option))

Key used to associate the option with it’s value

Source

options.lisp.

Target Slot

key.

Generic Reader: option-list-separator (object)
Package

clingon.options.

Methods
Reader Method: option-list-separator ((option-list option-list))

Character used to separate items in a list represented as a string

Source

options.lisp.

Target Slot

separator.

Generic Reader: option-long-name (object)
Package

clingon.options.

Methods
Reader Method: option-long-name ((option option))

Long option name

Source

options.lisp.

Target Slot

long-name.

Generic Reader: option-parameter (object)
Package

clingon.options.

Methods
Reader Method: option-parameter ((option option))

Option takes a parameter identified by the given name

Source

options.lisp.

Target Slot

parameter.

Generic Reader: option-required-p (object)
Package

clingon.options.

Methods
Reader Method: option-required-p ((option option))

Mark the option as required. Only valid if the option takes a parameter

Source

options.lisp.

Target Slot

required.

Generic Reader: option-short-name (object)
Package

clingon.options.

Methods
Reader Method: option-short-name ((option option))

Short option name

Source

options.lisp.

Target Slot

short-name.

Generic Reader: option-switch-off-states (object)
Package

clingon.options.

Methods
Reader Method: option-switch-off-states ((option-switch option-switch))

The list of states considered to ‘deactivate’ the switch

Source

options.lisp.

Target Slot

off-states.

Generic Reader: option-switch-on-states (object)
Package

clingon.options.

Methods
Reader Method: option-switch-on-states ((option-switch option-switch))

The list of states considered to ‘activate’ the switch

Source

options.lisp.

Target Slot

on-states.

Generic Function: option-usage-details (kind object &key)

Returns the usage details for the option as a
string. The returned string will be used for formatting and displaying the option as part of help pages.

Package

clingon.options.

Source

options.lisp.

Methods
Method: option-usage-details ((kind (eql :zsh-option-spec)) (option option-list) &key)

List options may be repeated on the command-line

Method: option-usage-details ((kind (eql :zsh-option-spec)) (option option-counter) &key)

Counter options may be repeated on the command-line

Method: option-usage-details ((kind (eql :zsh-option-spec)) (option option) &key)
Method: option-usage-details ((kind (eql :default)) (option option) &key)
Generic Reader: option-value (object)
Generic Writer: (setf option-value) (object)
Package

clingon.options.

Methods
Reader Method: option-value ((option option))
Writer Method: (setf option-value) ((option option))

Computed value after finalizing the option

Source

options.lisp.

Target Slot

value.

Generic Function: parse-command-line (top-level arguments)
Package

clingon.command.

Methods
Method: parse-command-line ((top-level command) arguments)

Parses the arguments for the given top-level command and returns the most-specific command that is matched against the given arguments. The returned command contains the environment for the command handler to be executed with already populated options.

Source

command.lisp.

Generic Function: parse-option (kind object &key)

Parses an option of the given KIND

Package

clingon.command.

Source

command.lisp.

Methods
Method: parse-option ((kind (eql :long)) (command command) &key)

Parses a long option

Method: parse-option ((kind (eql :short)) (command command) &key)

Parses a short option

Method: parse-option ((kind (eql :free-argument)) (command command) &key)

Consume the option and treat it as a free argument

Method: parse-option ((kind (eql :consume-all-arguments)) (command command) &key)

Consumes all arguments after the end-of-options flag

Generic Function: print-bash-completions (command stream)
Package

clingon.command.

Methods
Method: print-bash-completions ((command command) stream)

Prints the bash completions for the given command

Source

command.lisp.

Generic Function: print-bash-completions-and-exit (command stream)
Package

clingon.command.

Methods
Method: print-bash-completions-and-exit ((command command) stream)

Prints the bash completions for the given command and exits

Source

command.lisp.

Generic Function: print-documentation (kind command stream &key wrap-at)

Prints the documentation of the given top-level command

Package

clingon.command.

Source

command.lisp.

Methods
Method: print-documentation ((kind (eql :zsh-completions)) (top-level command) stream &key)

Prints the Zsh completion script for the given top-level command

Method: print-documentation ((kind (eql :markdown)) (top-level command) stream &key wrap-at)

Prints the documentation for the given TOP-LEVEL command in Markdown format

Generic Function: print-options-usage (command stream &key wrap-at-width)
Package

clingon.command.

Methods
Method: print-options-usage ((command command) stream &key wrap-at-width)

Prints the usage information about the options for the given command

Source

command.lisp.

Generic Function: print-sub-commands-info (command stream &key wrap-at-width)
Package

clingon.command.

Methods
Method: print-sub-commands-info ((command command) stream &key wrap-at-width)

Prints a summary of the sub-commands available for the command

Source

command.lisp.

Generic Function: print-usage (command stream &key wrap-at)

Prints the usage information of the command

Package

clingon.command.

Source

command.lisp.

Methods
Method: print-usage ((command command) stream &key wrap-at)
Generic Function: print-usage-and-exit (command stream)
Package

clingon.command.

Methods
Method: print-usage-and-exit ((command command) stream)
Source

command.lisp.

Generic Function: print-version-and-exit (command stream)
Package

clingon.command.

Methods
Method: print-version-and-exit ((command command) stream)
Source

command.lisp.

Generic Function: run (top-level &optional arguments)
Package

clingon.command.

Methods
Method: run ((top-level command) &optional arguments)

Runs the specified top-level command

Source

command.lisp.

Generic Reader: unknown-option-kind (condition)
Package

clingon.conditions.

Methods
Reader Method: unknown-option-kind ((condition unknown-option))
Source

conditions.lisp.

Target Slot

kind.

Generic Reader: unknown-option-name (condition)
Package

clingon.conditions.

Methods
Reader Method: unknown-option-name ((condition unknown-option))
Source

conditions.lisp.

Target Slot

name.

Generic Function: validate-top-level-command (top-level)
Package

clingon.command.

Methods
Method: validate-top-level-command ((top-level command))

Validates the top-level command and it’s sub-commands

Source

command.lisp.

Generic Function: visible-options (command)
Package

clingon.command.

Methods
Method: visible-options ((command command))

Returns the list of visible options for the given command

Source

command.lisp.


6.1.5 Standalone methods

Method: initialize-instance :after ((option option) &key)
Source

options.lisp.

Method: initialize-instance :after ((command command) &key)
Source

command.lisp.

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

options.lisp.

Method: print-object ((command command) stream)
Source

command.lisp.


6.1.6 Conditions

Condition: circular-dependency

A condition which is signalled when a circular dependency is detected

Package

clingon.conditions.

Source

conditions.lisp.

Direct superclasses

simple-error.

Direct methods

circular-dependency-items.

Direct slots
Slot: items
Initform

(quote (error "must specify items"))

Initargs

:items

Readers

circular-dependency-items.

Writers

This slot is read-only.

Condition: duplicate-commands

A condition which is signalled when a command provides duplicate sub-commands

Package

clingon.conditions.

Source

conditions.lisp.

Direct superclasses

simple-error.

Direct methods

duplicate-command-items.

Direct slots
Slot: items
Initform

(quote (error "must specify duplicate items"))

Initargs

:items

Readers

duplicate-command-items.

Writers

This slot is read-only.

Condition: duplicate-options

A condition which is signalled when a command provides duplicate options

Package

clingon.conditions.

Source

conditions.lisp.

Direct superclasses

simple-error.

Direct methods
Direct slots
Slot: kind
Initform

(quote (error "must specify option kind"))

Initargs

:kind

Readers

duplicate-option-kind.

Writers

This slot is read-only.

Slot: items
Initform

(quote (error "must specify option items"))

Initargs

:items

Readers

duplicate-option-items.

Writers

This slot is read-only.

Slot: name
Initform

(quote (error "must specify option name"))

Initargs

:name

Readers

duplicate-option-name.

Writers

This slot is read-only.

Condition: invalid-option

A condition which is signalled when an option is identified as invalid

Package

clingon.conditions.

Source

conditions.lisp.

Direct superclasses

simple-error.

Direct methods
Direct slots
Slot: item

The option which is identified as invalid

Initform

(quote (error "must specify option item"))

Initargs

:item

Readers

invalid-option-item.

Writers

This slot is read-only.

Slot: reason

The reason why this option is invalid

Initform

(quote (error "must specify reason"))

Initargs

:reason

Readers

invalid-option-reason.

Writers

This slot is read-only.

Condition: missing-option-argument

A condition which is signalled when an option expects an argument, but none was provided

Package

clingon.conditions.

Source

conditions.lisp.

Direct superclasses

simple-error.

Direct methods
Direct slots
Slot: item
Initform

(quote (error "must specify option item"))

Initargs

:item

Readers

missing-option-argument-item.

Writers

This slot is read-only.

Slot: command
Initform

(quote (error "must specify command"))

Initargs

:command

Readers

missing-option-argument-command.

Writers

This slot is read-only.

Condition: missing-required-option-value

A condition which is signalled when a required option value was not set

Package

clingon.conditions.

Source

conditions.lisp.

Direct superclasses

simple-error.

Direct methods
Direct slots
Slot: item

The option item which requires a value

Initform

(quote (error "must specify option item"))

Initargs

:item

Readers

missing-required-option-value-item.

Writers

This slot is read-only.

Slot: command

The command to which the option is associated

Initform

(quote (error "must specify command"))

Initargs

:command

Readers

missing-required-option-value-command.

Writers

This slot is read-only.

Condition: option-derive-error

A condition which is signalled when deriving an option’s value has failed

Package

clingon.conditions.

Source

conditions.lisp.

Direct superclasses

simple-error.

Direct methods

option-derive-error-reason.

Direct slots
Slot: reason

Reason for which deriving a value failed

Initform

(quote (error "must specify reason"))

Initargs

:reason

Readers

option-derive-error-reason.

Writers

This slot is read-only.

Condition: unknown-option

A condition which is signalled when an unknown option is seen

Package

clingon.conditions.

Source

conditions.lisp.

Direct superclasses

error.

Direct methods
Direct slots
Slot: name
Initform

(quote (error "must specify option name"))

Initargs

:name

Readers

unknown-option-name.

Writers

This slot is read-only.

Slot: kind
Initform

(quote (error "must specify option kind"))

Initargs

:kind

Readers

unknown-option-kind.

Writers

This slot is read-only.


Previous: , Up: Public Interface   [Contents][Index]

6.1.7 Classes

Class: command

A class to represent a command to be handled

Package

clingon.command.

Source

command.lisp.

Direct methods
Direct slots
Slot: name

Command name

Initform

(error "must specify command name")

Initargs

:name

Readers

command-name.

Writers

This slot is read-only.

Slot: options

Command options

Initargs

:options

Readers

command-options.

Writers

(setf command-options).

Slot: handler

A function which accepts a single argument. The
argument is an instance of the COMMAND class, which provides the context and environment for options.

Initargs

:handler

Readers

command-handler.

Writers

This slot is read-only.

Slot: pre-hook

A pre-hook is a function which will be invoked
before the command handler is executed. The function must accept a single argument, which is an instance of the COMMAND class.

Initargs

:pre-hook

Readers

command-pre-hook.

Writers

This slot is read-only.

Slot: post-hook

A post-hook is a function which will be invoked
after the command handler is executed. The function must accept a single argument, which is an instance of the COMMAND class.

Initargs

:post-hook

Readers

command-post-hook.

Writers

This slot is read-only.

Slot: sub-commands

Sub-commands for the command

Initargs

:sub-commands

Readers

command-sub-commands.

Writers

This slot is read-only.

Slot: parent

Parent command. This one will be automatically set during instantiation.

Initargs

:parent

Readers

command-parent.

Writers

(setf command-parent).

Slot: args-to-parse

Arguments to be parsed based on the command options

Initargs

:args-to-parse

Readers

command-args-to-parse.

Writers

(setf command-args-to-parse).

Slot: arguments

Discovered free arguments after parsing the options

Initargs

:arguments

Readers

command-arguments.

Writers

(setf command-arguments).

Slot: context

The context contains the reduced set of options for the command

Initform

(make-hash-table :test (function equal))

Initargs

:context

Readers

command-context.

Writers

(setf command-context).

Slot: version

Version of the command

Initargs

:version

Readers

command-version.

Writers

This slot is read-only.

Slot: authors

Authors of the command

Initargs

:authors

Readers

command-authors.

Writers

This slot is read-only.

Slot: license

License for the command

Initargs

:license

Readers

command-license.

Writers

This slot is read-only.

Slot: description

Short description of what the command does

Initargs

:description

Readers

command-description.

Writers

This slot is read-only.

Slot: long-description

Long description of what the command does

Initargs

:long-description

Readers

command-long-description.

Writers

This slot is read-only.

Slot: examples

A list of examples describing how to use the command

Initargs

:examples

Readers

command-examples.

Writers

This slot is read-only.

Slot: aliases

Aliases of the command

Initargs

:aliases

Readers

command-aliases.

Writers

This slot is read-only.

Slot: usage

Usage information for the command

Initargs

:usage

Readers

command-usage.

Writers

This slot is read-only.

Class: option

A class representing a command-line option

Package

clingon.options.

Source

options.lisp.

Direct subclasses
Direct methods
Direct slots
Slot: parameter

Option takes a parameter identified by the given name

Initargs

:parameter

Readers

option-parameter.

Writers

This slot is read-only.

Slot: required

Mark the option as required. Only valid if the option takes a parameter

Initargs

:required

Readers

option-required-p.

Writers

This slot is read-only.

Slot: short-name

Short option name

Initargs

:short-name

Readers

option-short-name.

Writers

This slot is read-only.

Slot: long-name

Long option name

Initargs

:long-name

Readers

option-long-name.

Writers

This slot is read-only.

Slot: description

Short description of the option

Initform

(error "must specify description")

Initargs

:description

Readers

option-description.

Writers

This slot is read-only.

Slot: category

Category for the option. Options with the same category will be grouped together

Initform

""

Initargs

:category

Readers

option-category.

Writers

This slot is read-only.

Slot: env-vars

List of env vars which can set the option value

Initargs

:env-vars

Readers

option-env-vars.

Writers

This slot is read-only.

Slot: initial-value

Initial value for the option

Initargs

:initial-value

Readers

option-initial-value.

Writers

This slot is read-only.

Slot: key

Key used to associate the option with it’s value

Initform

(error "must specify option key")

Initargs

:key

Readers

option-key.

Writers

This slot is read-only.

Slot: is-set-p

Predicate which returns T if the option was set

Initargs

:is-set-p

Readers

option-is-set-p.

Writers

(setf option-is-set-p).

Slot: hidden

Whether or not this option will be hidden on the usage pages

Initargs

:hidden

Readers

option-hidden-p.

Writers

This slot is read-only.

Slot: value

Computed value after finalizing the option

Initargs

:value

Readers

option-value.

Writers

(setf option-value).

Class: option-boolean

An option which represents a boolean flag

Package

clingon.options.

Source

options.lisp.

Direct superclasses

option.

Direct subclasses
Direct methods
Direct Default Initargs
InitargValue
:parametervalue
Class: option-boolean-false

A boolean option which always returns false

Package

clingon.options.

Source

options.lisp.

Direct superclasses

option-boolean.

Direct methods

derive-option-value.

Direct Default Initargs
InitargValue
:parameternil
Class: option-boolean-true

A boolean option which always returns true

Package

clingon.options.

Source

options.lisp.

Direct superclasses

option-boolean.

Direct methods

derive-option-value.

Direct Default Initargs
InitargValue
:parameternil
Class: option-choice

An option which allows selecting an item from a predefined list

Package

clingon.options.

Source

options.lisp.

Direct superclasses

option.

Direct methods
Direct Default Initargs
InitargValue
:parameterchoice
Direct slots
Slot: items

The available choices

Initform

(error "must specify available items")

Initargs

:items

Readers

option-choice-items.

Writers

This slot is read-only.

Class: option-counter

An option which increments every time it is set

Package

clingon.options.

Source

options.lisp.

Direct superclasses

option.

Direct methods
Direct Default Initargs
InitargValue
:initial-value0
Direct slots
Slot: step

Numeric value to increase the counter with

Package

common-lisp.

Initform

1

Initargs

:step

Readers

option-counter-step.

Writers

This slot is read-only.

Class: option-enum

An option which represents an enum with variants and associated values

Package

clingon.options.

Source

options.lisp.

Direct superclasses

option.

Direct methods
Direct Default Initargs
InitargValue
:parametervariant
Direct slots
Slot: items

The enum variants and their associated values

Initform

(error "must specify available variants")

Initargs

:items

Readers

option-enum-items.

Writers

This slot is read-only.

Class: option-filepath

An option which represents a filepath

Package

clingon.options.

Source

options.lisp.

Direct superclasses

option.

Direct subclasses

option-list-filepath.

Direct methods

option-description-details.

Direct Default Initargs
InitargValue
:parameterpath
Class: option-integer

An option class to represent an integer

Package

clingon.options.

Source

options.lisp.

Direct superclasses

option.

Direct methods
Direct Default Initargs
InitargValue
:parameterint
Direct slots
Slot: radix
Initform

10

Initargs

:radix

Readers

option-integer-radix.

Writers

This slot is read-only.

Class: option-list

An option which collects values into a list

Package

clingon.options.

Source

options.lisp.

Direct superclasses

option.

Direct subclasses
Direct methods
Direct Default Initargs
InitargValue
:initial-valuenil
:parameteritem
Direct slots
Slot: separator

Character used to separate items in a list represented as a string

Initform

#\,

Initargs

:separator

Readers

option-list-separator.

Writers

This slot is read-only.

Class: option-list-filepath

An option which represents a list of filepaths

Package

clingon.options.

Source

options.lisp.

Direct superclasses
Direct Default Initargs
InitargValue
:parameterpath
Class: option-list-integer

An option which collects integers into a list

Package

clingon.options.

Source

options.lisp.

Direct superclasses

option-list.

Direct methods
Direct slots
Slot: radix
Initform

10

Initargs

:radix

Readers

option-integer-radix.

Writers

This slot is read-only.

Class: option-switch

An option which represents a switch with a state

Package

clingon.options.

Source

options.lisp.

Direct superclasses

option-boolean.

Direct methods
Direct Default Initargs
InitargValue
:parameterstate
Direct slots
Slot: on-states

The list of states considered to ‘activate’ the switch

Initform

(quote ("on" "yes" "true" "enable" "1"))

Initargs

:on-states

Readers

option-switch-on-states.

Writers

This slot is read-only.

Slot: off-states

The list of states considered to ‘deactivate’ the switch

Initform

(quote ("off" "no" "false" "disable" "0"))

Initargs

:off-states

Readers

option-switch-off-states.

Writers

This slot is read-only.


6.2 Internals


Next: , Previous: , Up: Internals   [Contents][Index]

6.2.1 Special variables

Special Variable: *default-bash-completions-flag*

The default ‘–bash-completions’ flag

Package

clingon.command.

Source

command.lisp.

Special Variable: *default-help-flag*

The default ‘–help’ flag

Package

clingon.command.

Source

command.lisp.

Special Variable: *default-options*

A list of default options to add to each sub-command

Package

clingon.command.

Source

command.lisp.

Special Variable: *default-version-flag*

The default ‘–version’ flag

Package

clingon.command.

Source

command.lisp.

Special Variable: *zsh-compfunc-with-sub-commands*

Template for a Zsh completion function which contains sub-commands

Package

clingon.command.

Source

command.lisp.

Special Variable: *zsh-compfunc-without-sub-commands*

Template for a Zsh completion function without sub-commands

Package

clingon.command.

Source

command.lisp.


6.2.2 Ordinary functions

Function: argv ()

Returns the list of command-line arguments

Package

clingon.utils.

Source

utils.lisp.

Function: parse-integer-or-lose (value &key radix)
Package

clingon.options.

Source

options.lisp.


Next: , Previous: , Up: Internals   [Contents][Index]

6.2.3 Generic functions

Generic Reader: command-context (object)
Generic Writer: (setf command-context) (object)
Package

clingon.command.

Methods
Reader Method: command-context ((command command))
Writer Method: (setf command-context) ((command command))

The context contains the reduced set of options for the command

Source

command.lisp.

Target Slot

context.

Generic Function: derive-option-with-restarts (command option optarg)
Package

clingon.command.

Methods
Method: derive-option-with-restarts ((command command) (option option) optarg)

Provides possible restarts when deriving an option’s value

Source

command.lisp.

Generic Function: ensure-unique-options (command)
Package

clingon.command.

Methods
Method: ensure-unique-options ((command command))

Ensures that the given COMMAND does not contain duplicate options

Source

command.lisp.

Generic Function: ensure-unique-sub-commands (command)
Package

clingon.command.

Methods
Method: ensure-unique-sub-commands ((command command))

Ensure that the given COMMAND does not contain duplicate sub-command names

Source

command.lisp.

Generic Function: handle-missing-argument-with-restarts (command option)
Package

clingon.command.

Methods
Method: handle-missing-argument-with-restarts ((command command) (option option))

Provides possible restarts when an option requires an argument, but none was provided

Source

command.lisp.

Generic Function: handle-unknown-option-with-restarts (command kind full-name)
Package

clingon.command.

Methods
Method: handle-unknown-option-with-restarts ((command command) kind full-name)

Provides possible restarts when an unknown option is detected

Source

command.lisp.

Generic Function: parse-command-line% (command)
Package

clingon.command.

Methods
Method: parse-command-line% ((command command))
Source

command.lisp.

Generic Function: zsh-sub-command-dispatch-items (command)
Package

clingon.command.

Methods
Method: zsh-sub-command-dispatch-items ((command command))

Returns a list of of command-name -> function-name dispatch strings, which will be used for populating into the Zsh completion function.

Source

command.lisp.

Generic Function: zsh-sub-command-items (command)
Package

clingon.command.

Methods
Method: zsh-sub-command-items ((command command))

Returns the sub-command items, which will be populated in the Zsh completion function

Source

command.lisp.


Previous: , Up: Internals   [Contents][Index]

6.2.4 Classes

Class: option-string

An option which represents a string

Package

clingon.options.

Source

options.lisp.

Direct superclasses

option.

Direct Default Initargs
InitargValue
:parametervalue

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts


Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   (  
A   C   D   E   F   G   H   I   J   L   M   O   P   R   S   T   U   V   W   Z  
Index Entry  Section

(
(setf command-args-to-parse): Public generic functions
(setf command-args-to-parse): Public generic functions
(setf command-arguments): Public generic functions
(setf command-arguments): Public generic functions
(setf command-context): Private generic functions
(setf command-context): Private generic functions
(setf command-options): Public generic functions
(setf command-options): Public generic functions
(setf command-parent): Public generic functions
(setf command-parent): Public generic functions
(setf option-is-set-p): Public generic functions
(setf option-is-set-p): Public generic functions
(setf option-value): Public generic functions
(setf option-value): Public generic functions

A
apply-hooks: Public generic functions
apply-hooks: Public generic functions
apply-hooks: Public generic functions
argv: Private ordinary functions

C
circular-dependency-items: Public generic functions
circular-dependency-items: Public generic functions
command-aliases: Public generic functions
command-aliases: Public generic functions
command-args-to-parse: Public generic functions
command-args-to-parse: Public generic functions
command-arguments: Public generic functions
command-arguments: Public generic functions
command-authors: Public generic functions
command-authors: Public generic functions
command-context: Private generic functions
command-context: Private generic functions
command-description: Public generic functions
command-description: Public generic functions
command-examples: Public generic functions
command-examples: Public generic functions
command-full-name: Public generic functions
command-full-name: Public generic functions
command-full-path: Public generic functions
command-full-path: Public generic functions
command-handler: Public generic functions
command-handler: Public generic functions
command-is-top-level-p: Public generic functions
command-is-top-level-p: Public generic functions
command-license: Public generic functions
command-license: Public generic functions
command-lineage: Public generic functions
command-lineage: Public generic functions
command-long-description: Public generic functions
command-long-description: Public generic functions
command-name: Public generic functions
command-name: Public generic functions
command-options: Public generic functions
command-options: Public generic functions
command-parent: Public generic functions
command-parent: Public generic functions
command-post-hook: Public generic functions
command-post-hook: Public generic functions
command-pre-hook: Public generic functions
command-pre-hook: Public generic functions
command-sub-commands: Public generic functions
command-sub-commands: Public generic functions
command-tree: Public generic functions
command-tree: Public generic functions
command-usage: Public generic functions
command-usage: Public generic functions
command-usage-string: Public generic functions
command-usage-string: Public generic functions
command-version: Public generic functions
command-version: Public generic functions

D
derive-option-value: Public generic functions
derive-option-value: Public generic functions
derive-option-value: Public generic functions
derive-option-value: Public generic functions
derive-option-value: Public generic functions
derive-option-value: Public generic functions
derive-option-value: Public generic functions
derive-option-value: Public generic functions
derive-option-value: Public generic functions
derive-option-value: Public generic functions
derive-option-value: Public generic functions
derive-option-value: Public generic functions
derive-option-with-restarts: Private generic functions
derive-option-with-restarts: Private generic functions
discard-option: Public ordinary functions
duplicate-command-items: Public generic functions
duplicate-command-items: Public generic functions
duplicate-option-items: Public generic functions
duplicate-option-items: Public generic functions
duplicate-option-kind: Public generic functions
duplicate-option-kind: Public generic functions
duplicate-option-name: Public generic functions
duplicate-option-name: Public generic functions

E
end-of-options-p: Public ordinary functions
ensure-unique-options: Private generic functions
ensure-unique-options: Private generic functions
ensure-unique-sub-commands: Private generic functions
ensure-unique-sub-commands: Private generic functions
exit: Public ordinary functions

F
finalize-command: Public generic functions
finalize-command: Public generic functions
finalize-option: Public generic functions
finalize-option: Public generic functions
finalize-option: Public generic functions
finalize-option: Public generic functions
find-option: Public generic functions
find-option: Public generic functions
find-option: Public generic functions
find-sub-command: Public generic functions
find-sub-command: Public generic functions
Function, argv: Private ordinary functions
Function, discard-option: Public ordinary functions
Function, end-of-options-p: Public ordinary functions
Function, exit: Public ordinary functions
Function, git-rev-parse: Public ordinary functions
Function, group-by: Public ordinary functions
Function, hashtable-keys: Public ordinary functions
Function, hashtable-values: Public ordinary functions
Function, join-list: Public ordinary functions
Function, long-option-p: Public ordinary functions
Function, make-command: Public ordinary functions
Function, missing-option-argument-p: Public ordinary functions
Function, option-derive-error-p: Public ordinary functions
Function, parse-integer-or-lose: Private ordinary functions
Function, short-option-p: Public ordinary functions
Function, treat-as-argument: Public ordinary functions
Function, unknown-option-p: Public ordinary functions
Function, walk: Public ordinary functions

G
Generic Function, (setf command-args-to-parse): Public generic functions
Generic Function, (setf command-arguments): Public generic functions
Generic Function, (setf command-context): Private generic functions
Generic Function, (setf command-options): Public generic functions
Generic Function, (setf command-parent): Public generic functions
Generic Function, (setf option-is-set-p): Public generic functions
Generic Function, (setf option-value): Public generic functions
Generic Function, apply-hooks: Public generic functions
Generic Function, circular-dependency-items: Public generic functions
Generic Function, command-aliases: Public generic functions
Generic Function, command-args-to-parse: Public generic functions
Generic Function, command-arguments: Public generic functions
Generic Function, command-authors: Public generic functions
Generic Function, command-context: Private generic functions
Generic Function, command-description: Public generic functions
Generic Function, command-examples: Public generic functions
Generic Function, command-full-name: Public generic functions
Generic Function, command-full-path: Public generic functions
Generic Function, command-handler: Public generic functions
Generic Function, command-is-top-level-p: Public generic functions
Generic Function, command-license: Public generic functions
Generic Function, command-lineage: Public generic functions
Generic Function, command-long-description: Public generic functions
Generic Function, command-name: Public generic functions
Generic Function, command-options: Public generic functions
Generic Function, command-parent: Public generic functions
Generic Function, command-post-hook: Public generic functions
Generic Function, command-pre-hook: Public generic functions
Generic Function, command-sub-commands: Public generic functions
Generic Function, command-tree: Public generic functions
Generic Function, command-usage: Public generic functions
Generic Function, command-usage-string: Public generic functions
Generic Function, command-version: Public generic functions
Generic Function, derive-option-value: Public generic functions
Generic Function, derive-option-with-restarts: Private generic functions
Generic Function, duplicate-command-items: Public generic functions
Generic Function, duplicate-option-items: Public generic functions
Generic Function, duplicate-option-kind: Public generic functions
Generic Function, duplicate-option-name: Public generic functions
Generic Function, ensure-unique-options: Private generic functions
Generic Function, ensure-unique-sub-commands: Private generic functions
Generic Function, finalize-command: Public generic functions
Generic Function, finalize-option: Public generic functions
Generic Function, find-option: Public generic functions
Generic Function, find-sub-command: Public generic functions
Generic Function, getopt: Public generic functions
Generic Function, handle-missing-argument-with-restarts: Private generic functions
Generic Function, handle-unknown-option-with-restarts: Private generic functions
Generic Function, initialize-command: Public generic functions
Generic Function, initialize-option: Public generic functions
Generic Function, invalid-option-item: Public generic functions
Generic Function, invalid-option-reason: Public generic functions
Generic Function, make-option: Public generic functions
Generic Function, missing-option-argument-command: Public generic functions
Generic Function, missing-option-argument-item: Public generic functions
Generic Function, missing-required-option-value-command: Public generic functions
Generic Function, missing-required-option-value-item: Public generic functions
Generic Function, opt-is-set-p: Public generic functions
Generic Function, option-category: Public generic functions
Generic Function, option-choice-items: Public generic functions
Generic Function, option-counter-step: Public generic functions
Generic Function, option-derive-error-reason: Public generic functions
Generic Function, option-description: Public generic functions
Generic Function, option-description-details: Public generic functions
Generic Function, option-enum-items: Public generic functions
Generic Function, option-env-vars: Public generic functions
Generic Function, option-hidden-p: Public generic functions
Generic Function, option-initial-value: Public generic functions
Generic Function, option-integer-radix: Public generic functions
Generic Function, option-is-set-p: Public generic functions
Generic Function, option-key: Public generic functions
Generic Function, option-list-separator: Public generic functions
Generic Function, option-long-name: Public generic functions
Generic Function, option-parameter: Public generic functions
Generic Function, option-required-p: Public generic functions
Generic Function, option-short-name: Public generic functions
Generic Function, option-switch-off-states: Public generic functions
Generic Function, option-switch-on-states: Public generic functions
Generic Function, option-usage-details: Public generic functions
Generic Function, option-value: Public generic functions
Generic Function, parse-command-line: Public generic functions
Generic Function, parse-command-line%: Private generic functions
Generic Function, parse-option: Public generic functions
Generic Function, print-bash-completions: Public generic functions
Generic Function, print-bash-completions-and-exit: Public generic functions
Generic Function, print-documentation: Public generic functions
Generic Function, print-options-usage: Public generic functions
Generic Function, print-sub-commands-info: Public generic functions
Generic Function, print-usage: Public generic functions
Generic Function, print-usage-and-exit: Public generic functions
Generic Function, print-version-and-exit: Public generic functions
Generic Function, run: Public generic functions
Generic Function, unknown-option-kind: Public generic functions
Generic Function, unknown-option-name: Public generic functions
Generic Function, validate-top-level-command: Public generic functions
Generic Function, visible-options: Public generic functions
Generic Function, zsh-sub-command-dispatch-items: Private generic functions
Generic Function, zsh-sub-command-items: Private generic functions
getopt: Public generic functions
getopt: Public generic functions
git-rev-parse: Public ordinary functions
group-by: Public ordinary functions

H
handle-missing-argument-with-restarts: Private generic functions
handle-missing-argument-with-restarts: Private generic functions
handle-unknown-option-with-restarts: Private generic functions
handle-unknown-option-with-restarts: Private generic functions
hashtable-keys: Public ordinary functions
hashtable-values: Public ordinary functions

I
initialize-command: Public generic functions
initialize-command: Public generic functions
initialize-instance: Public standalone methods
initialize-instance: Public standalone methods
initialize-option: Public generic functions
initialize-option: Public generic functions
initialize-option: Public generic functions
initialize-option: Public generic functions
initialize-option: Public generic functions
initialize-option: Public generic functions
initialize-option: Public generic functions
initialize-option: Public generic functions
invalid-option-item: Public generic functions
invalid-option-item: Public generic functions
invalid-option-reason: Public generic functions
invalid-option-reason: Public generic functions

J
join-list: Public ordinary functions

L
long-option-p: Public ordinary functions

M
Macro, with-command-tree: Public macros
make-command: Public ordinary functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
make-option: Public generic functions
Method, (setf command-args-to-parse): Public generic functions
Method, (setf command-arguments): Public generic functions
Method, (setf command-context): Private generic functions
Method, (setf command-options): Public generic functions
Method, (setf command-parent): Public generic functions
Method, (setf option-is-set-p): Public generic functions
Method, (setf option-value): Public generic functions
Method, apply-hooks: Public generic functions
Method, apply-hooks: Public generic functions
Method, circular-dependency-items: Public generic functions
Method, command-aliases: Public generic functions
Method, command-args-to-parse: Public generic functions
Method, command-arguments: Public generic functions
Method, command-authors: Public generic functions
Method, command-context: Private generic functions
Method, command-description: Public generic functions
Method, command-examples: Public generic functions
Method, command-full-name: Public generic functions
Method, command-full-path: Public generic functions
Method, command-handler: Public generic functions
Method, command-is-top-level-p: Public generic functions
Method, command-license: Public generic functions
Method, command-lineage: Public generic functions
Method, command-long-description: Public generic functions
Method, command-name: Public generic functions
Method, command-options: Public generic functions
Method, command-parent: Public generic functions
Method, command-post-hook: Public generic functions
Method, command-pre-hook: Public generic functions
Method, command-sub-commands: Public generic functions
Method, command-tree: Public generic functions
Method, command-usage: Public generic functions
Method, command-usage-string: Public generic functions
Method, command-version: Public generic functions
Method, derive-option-value: Public generic functions
Method, derive-option-value: Public generic functions
Method, derive-option-value: Public generic functions
Method, derive-option-value: Public generic functions
Method, derive-option-value: Public generic functions
Method, derive-option-value: Public generic functions
Method, derive-option-value: Public generic functions
Method, derive-option-value: Public generic functions
Method, derive-option-value: Public generic functions
Method, derive-option-value: Public generic functions
Method, derive-option-value: Public generic functions
Method, derive-option-with-restarts: Private generic functions
Method, duplicate-command-items: Public generic functions
Method, duplicate-option-items: Public generic functions
Method, duplicate-option-kind: Public generic functions
Method, duplicate-option-name: Public generic functions
Method, ensure-unique-options: Private generic functions
Method, ensure-unique-sub-commands: Private generic functions
Method, finalize-command: Public generic functions
Method, finalize-option: Public generic functions
Method, finalize-option: Public generic functions
Method, finalize-option: Public generic functions
Method, find-option: Public generic functions
Method, find-option: Public generic functions
Method, find-sub-command: Public generic functions
Method, getopt: Public generic functions
Method, handle-missing-argument-with-restarts: Private generic functions
Method, handle-unknown-option-with-restarts: Private generic functions
Method, initialize-command: Public generic functions
Method, initialize-instance: Public standalone methods
Method, initialize-instance: Public standalone methods
Method, initialize-option: Public generic functions
Method, initialize-option: Public generic functions
Method, initialize-option: Public generic functions
Method, initialize-option: Public generic functions
Method, initialize-option: Public generic functions
Method, initialize-option: Public generic functions
Method, initialize-option: Public generic functions
Method, invalid-option-item: Public generic functions
Method, invalid-option-reason: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, make-option: Public generic functions
Method, missing-option-argument-command: Public generic functions
Method, missing-option-argument-item: Public generic functions
Method, missing-required-option-value-command: Public generic functions
Method, missing-required-option-value-item: Public generic functions
Method, opt-is-set-p: Public generic functions
Method, option-category: Public generic functions
Method, option-choice-items: Public generic functions
Method, option-counter-step: Public generic functions
Method, option-derive-error-reason: Public generic functions
Method, option-description: Public generic functions
Method, option-description-details: Public generic functions
Method, option-description-details: Public generic functions
Method, option-description-details: Public generic functions
Method, option-description-details: Public generic functions
Method, option-description-details: Public generic functions
Method, option-description-details: Public generic functions
Method, option-description-details: Public generic functions
Method, option-description-details: Public generic functions
Method, option-enum-items: Public generic functions
Method, option-env-vars: Public generic functions
Method, option-hidden-p: Public generic functions
Method, option-initial-value: Public generic functions
Method, option-integer-radix: Public generic functions
Method, option-integer-radix: Public generic functions
Method, option-is-set-p: Public generic functions
Method, option-key: Public generic functions
Method, option-list-separator: Public generic functions
Method, option-long-name: Public generic functions
Method, option-parameter: Public generic functions
Method, option-required-p: Public generic functions
Method, option-short-name: Public generic functions
Method, option-switch-off-states: Public generic functions
Method, option-switch-on-states: Public generic functions
Method, option-usage-details: Public generic functions
Method, option-usage-details: Public generic functions
Method, option-usage-details: Public generic functions
Method, option-usage-details: Public generic functions
Method, option-value: Public generic functions
Method, parse-command-line: Public generic functions
Method, parse-command-line%: Private generic functions
Method, parse-option: Public generic functions
Method, parse-option: Public generic functions
Method, parse-option: Public generic functions
Method, parse-option: Public generic functions
Method, print-bash-completions: Public generic functions
Method, print-bash-completions-and-exit: Public generic functions
Method, print-documentation: Public generic functions
Method, print-documentation: Public generic functions
Method, print-object: Public standalone methods
Method, print-object: Public standalone methods
Method, print-options-usage: Public generic functions
Method, print-sub-commands-info: Public generic functions
Method, print-usage: Public generic functions
Method, print-usage-and-exit: Public generic functions
Method, print-version-and-exit: Public generic functions
Method, run: Public generic functions
Method, unknown-option-kind: Public generic functions
Method, unknown-option-name: Public generic functions
Method, validate-top-level-command: Public generic functions
Method, visible-options: Public generic functions
Method, zsh-sub-command-dispatch-items: Private generic functions
Method, zsh-sub-command-items: Private generic functions
missing-option-argument-command: Public generic functions
missing-option-argument-command: Public generic functions
missing-option-argument-item: Public generic functions
missing-option-argument-item: Public generic functions
missing-option-argument-p: Public ordinary functions
missing-required-option-value-command: Public generic functions
missing-required-option-value-command: Public generic functions
missing-required-option-value-item: Public generic functions
missing-required-option-value-item: Public generic functions

O
opt-is-set-p: Public generic functions
opt-is-set-p: Public generic functions
option-category: Public generic functions
option-category: Public generic functions
option-choice-items: Public generic functions
option-choice-items: Public generic functions
option-counter-step: Public generic functions
option-counter-step: Public generic functions
option-derive-error-p: Public ordinary functions
option-derive-error-reason: Public generic functions
option-derive-error-reason: Public generic functions
option-description: Public generic functions
option-description: Public generic functions
option-description-details: Public generic functions
option-description-details: Public generic functions
option-description-details: Public generic functions
option-description-details: Public generic functions
option-description-details: Public generic functions
option-description-details: Public generic functions
option-description-details: Public generic functions
option-description-details: Public generic functions
option-description-details: Public generic functions
option-enum-items: Public generic functions
option-enum-items: Public generic functions
option-env-vars: Public generic functions
option-env-vars: Public generic functions
option-hidden-p: Public generic functions
option-hidden-p: Public generic functions
option-initial-value: Public generic functions
option-initial-value: Public generic functions
option-integer-radix: Public generic functions
option-integer-radix: Public generic functions
option-integer-radix: Public generic functions
option-is-set-p: Public generic functions
option-is-set-p: Public generic functions
option-key: Public generic functions
option-key: Public generic functions
option-list-separator: Public generic functions
option-list-separator: Public generic functions
option-long-name: Public generic functions
option-long-name: Public generic functions
option-parameter: Public generic functions
option-parameter: Public generic functions
option-required-p: Public generic functions
option-required-p: Public generic functions
option-short-name: Public generic functions
option-short-name: Public generic functions
option-switch-off-states: Public generic functions
option-switch-off-states: Public generic functions
option-switch-on-states: Public generic functions
option-switch-on-states: Public generic functions
option-usage-details: Public generic functions
option-usage-details: Public generic functions
option-usage-details: Public generic functions
option-usage-details: Public generic functions
option-usage-details: Public generic functions
option-value: Public generic functions
option-value: Public generic functions

P
parse-command-line: Public generic functions
parse-command-line: Public generic functions
parse-command-line%: Private generic functions
parse-command-line%: Private generic functions
parse-integer-or-lose: Private ordinary functions
parse-option: Public generic functions
parse-option: Public generic functions
parse-option: Public generic functions
parse-option: Public generic functions
parse-option: Public generic functions
print-bash-completions: Public generic functions
print-bash-completions: Public generic functions
print-bash-completions-and-exit: Public generic functions
print-bash-completions-and-exit: Public generic functions
print-documentation: Public generic functions
print-documentation: Public generic functions
print-documentation: Public generic functions
print-object: Public standalone methods
print-object: Public standalone methods
print-options-usage: Public generic functions
print-options-usage: Public generic functions
print-sub-commands-info: Public generic functions
print-sub-commands-info: Public generic functions
print-usage: Public generic functions
print-usage: Public generic functions
print-usage-and-exit: Public generic functions
print-usage-and-exit: Public generic functions
print-version-and-exit: Public generic functions
print-version-and-exit: Public generic functions

R
run: Public generic functions
run: Public generic functions

S
short-option-p: Public ordinary functions

T
treat-as-argument: Public ordinary functions

U
unknown-option-kind: Public generic functions
unknown-option-kind: Public generic functions
unknown-option-name: Public generic functions
unknown-option-name: Public generic functions
unknown-option-p: Public ordinary functions

V
validate-top-level-command: Public generic functions
validate-top-level-command: Public generic functions
visible-options: Public generic functions
visible-options: Public generic functions

W
walk: Public ordinary functions
with-command-tree: Public macros

Z
zsh-sub-command-dispatch-items: Private generic functions
zsh-sub-command-dispatch-items: Private generic functions
zsh-sub-command-items: Private generic functions
zsh-sub-command-items: Private generic functions

Jump to:   (  
A   C   D   E   F   G   H   I   J   L   M   O   P   R   S   T   U   V   W   Z  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   *  
A   C   D   E   H   I   K   L   N   O   P   R   S   U   V  
Index Entry  Section

*
*default-bash-completions-flag*: Private special variables
*default-help-flag*: Private special variables
*default-options*: Private special variables
*default-version-flag*: Private special variables
*end-of-options-marker*: Public special variables
*zsh-compfunc-with-sub-commands*: Private special variables
*zsh-compfunc-without-sub-commands*: Private special variables

A
aliases: Public classes
args-to-parse: Public classes
arguments: Public classes
authors: Public classes

C
category: Public classes
command: Public conditions
command: Public conditions
context: Public classes

D
description: Public classes
description: Public classes

E
env-vars: Public classes
examples: Public classes

H
handler: Public classes
hidden: Public classes

I
initial-value: Public classes
is-set-p: Public classes
item: Public conditions
item: Public conditions
item: Public conditions
items: Public conditions
items: Public conditions
items: Public conditions
items: Public classes
items: Public classes

K
key: Public classes
kind: Public conditions
kind: Public conditions

L
license: Public classes
long-description: Public classes
long-name: Public classes

N
name: Public conditions
name: Public conditions
name: Public classes

O
off-states: Public classes
on-states: Public classes
options: Public classes

P
parameter: Public classes
parent: Public classes
post-hook: Public classes
pre-hook: Public classes

R
radix: Public classes
radix: Public classes
reason: Public conditions
reason: Public conditions
required: Public classes

S
separator: Public classes
short-name: Public classes
Slot, aliases: Public classes
Slot, args-to-parse: Public classes
Slot, arguments: Public classes
Slot, authors: Public classes
Slot, category: Public classes
Slot, command: Public conditions
Slot, command: Public conditions
Slot, context: Public classes
Slot, description: Public classes
Slot, description: Public classes
Slot, env-vars: Public classes
Slot, examples: Public classes
Slot, handler: Public classes
Slot, hidden: Public classes
Slot, initial-value: Public classes
Slot, is-set-p: Public classes
Slot, item: Public conditions
Slot, item: Public conditions
Slot, item: Public conditions
Slot, items: Public conditions
Slot, items: Public conditions
Slot, items: Public conditions
Slot, items: Public classes
Slot, items: Public classes
Slot, key: Public classes
Slot, kind: Public conditions
Slot, kind: Public conditions
Slot, license: Public classes
Slot, long-description: Public classes
Slot, long-name: Public classes
Slot, name: Public conditions
Slot, name: Public conditions
Slot, name: Public classes
Slot, off-states: Public classes
Slot, on-states: Public classes
Slot, options: Public classes
Slot, parameter: Public classes
Slot, parent: Public classes
Slot, post-hook: Public classes
Slot, pre-hook: Public classes
Slot, radix: Public classes
Slot, radix: Public classes
Slot, reason: Public conditions
Slot, reason: Public conditions
Slot, required: Public classes
Slot, separator: Public classes
Slot, short-name: Public classes
Slot, step: Public classes
Slot, sub-commands: Public classes
Slot, usage: Public classes
Slot, value: Public classes
Slot, version: Public classes
Special Variable, *default-bash-completions-flag*: Private special variables
Special Variable, *default-help-flag*: Private special variables
Special Variable, *default-options*: Private special variables
Special Variable, *default-version-flag*: Private special variables
Special Variable, *end-of-options-marker*: Public special variables
Special Variable, *zsh-compfunc-with-sub-commands*: Private special variables
Special Variable, *zsh-compfunc-without-sub-commands*: Private special variables
step: Public classes
sub-commands: Public classes

U
usage: Public classes

V
value: Public classes
version: Public classes

Jump to:   *  
A   C   D   E   H   I   K   L   N   O   P   R   S   U   V  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   C   D   F   I   M   O   P   S   U  
Index Entry  Section

C
circular-dependency: Public conditions
Class, command: Public classes
Class, option: Public classes
Class, option-boolean: Public classes
Class, option-boolean-false: Public classes
Class, option-boolean-true: Public classes
Class, option-choice: Public classes
Class, option-counter: Public classes
Class, option-enum: Public classes
Class, option-filepath: Public classes
Class, option-integer: Public classes
Class, option-list: Public classes
Class, option-list-filepath: Public classes
Class, option-list-integer: Public classes
Class, option-string: Private classes
Class, option-switch: Public classes
client-package: The clingon/client-package module
clingon: The clingon system
clingon: The clingon package
clingon-system: The clingon-system package
clingon.asd: The clingon/clingon․asd file
clingon.command: The clingon․command package
clingon.conditions: The clingon․conditions package
clingon.options: The clingon․options package
clingon.utils: The clingon․utils package
command: Public classes
command.lisp: The clingon/core/command․lisp file
Condition, circular-dependency: Public conditions
Condition, duplicate-commands: Public conditions
Condition, duplicate-options: Public conditions
Condition, invalid-option: Public conditions
Condition, missing-option-argument: Public conditions
Condition, missing-required-option-value: Public conditions
Condition, option-derive-error: Public conditions
Condition, unknown-option: Public conditions
conditions.lisp: The clingon/core/conditions․lisp file
core: The clingon/core module

D
duplicate-commands: Public conditions
duplicate-options: Public conditions

F
File, clingon.asd: The clingon/clingon․asd file
File, command.lisp: The clingon/core/command․lisp file
File, conditions.lisp: The clingon/core/conditions․lisp file
File, options.lisp: The clingon/core/options․lisp file
File, package.lisp: The clingon/client-package/package․lisp file
File, utils.lisp: The clingon/utils/utils․lisp file

I
invalid-option: Public conditions

M
missing-option-argument: Public conditions
missing-required-option-value: Public conditions
Module, client-package: The clingon/client-package module
Module, core: The clingon/core module
Module, utils: The clingon/utils module

O
option: Public classes
option-boolean: Public classes
option-boolean-false: Public classes
option-boolean-true: Public classes
option-choice: Public classes
option-counter: Public classes
option-derive-error: Public conditions
option-enum: Public classes
option-filepath: Public classes
option-integer: Public classes
option-list: Public classes
option-list-filepath: Public classes
option-list-integer: Public classes
option-string: Private classes
option-switch: Public classes
options.lisp: The clingon/core/options․lisp file

P
Package, clingon: The clingon package
Package, clingon-system: The clingon-system package
Package, clingon.command: The clingon․command package
Package, clingon.conditions: The clingon․conditions package
Package, clingon.options: The clingon․options package
Package, clingon.utils: The clingon․utils package
package.lisp: The clingon/client-package/package․lisp file

S
System, clingon: The clingon system

U
unknown-option: Public conditions
utils: The clingon/utils module
utils.lisp: The clingon/utils/utils․lisp file

Jump to:   C   D   F   I   M   O   P   S   U