CLAP is a port cum re-imagining of Clojure library tools.cli. I found most of the existing tools for the purpose to be old and unmaintained.
You can set up your script like so.
(in-package :cl-user)
(defpackage my-program
(:use :cl :clap ))
(in-package :my-program)
(defparameter cli-options2
'(("-p" "--port" "Port number for the server."
:required "PORT"
:default 80)
("-v" nil "Verbosity"
:id :verbosity
:default 0)
("-h" "--help" "Print help message and exit")))
(clap:parse-opts (clap:get-argv) cli-options)Execute the command line:
my-program -vvvp8080 foo --help --invalid-opt
to produce the map:
((:options ((:port 8080)
(:verbosity 3)
(:help true)))
(:arguments ("foo"))
(:summary " -p, --port PORT 80 Port number
-v Verbosity level
-h, --help")
(:errors ("Unknown option: \"--invalid-opt\"")))You can optionaly give a keyword argument :handler-fn to parse-opts which takes as arguemnts options, arguments, summary, errors. Check out example.lisp to for a working example.
Right now this is not part of quicklisp so the easiest way to install it is in shell:
$ cd QUICKLISP_FOLDER/local-projects
$ git clone [email protected]:vigneshsarma/clap.gitgo to quicklisp loaded lisp repl:
(ql:quickload :clap)
should now work