This is a minimalistic parser of command line options. Main advantage of this library is ability to concisely define command line options once and then use this definition for parsing and extraction of command line arguments, as well as printing description of command line options (you get --help for free). This way you don't need to repeat yourself. Also, unix-opts doesn't depend on anything and allows to precisely control behavior of the parser via Common Lisp restarts.

GitHub repository: https://github.com/mrkkrp/unix-opts

You can install it via Quicklisp:

(ql:quickload "unix-opts")

Here is an example how to define some command line options with unix-opts:

(opts:define-opts (:name :output :description "redirect output to file FILE" :short #\o :long "output" :arg-parser #'identity :meta-var "FILE") (:name :level :description "the program will run on LEVEL level" :short #\l :long "level" :arg-parser #'parse-integer :meta-var "LEVEL") (:name :verbose :description "verbose output" :short #\v :long "verbose") (:name :help :description "print this help text" :short #\h :long "help"))

See it in action (full source code of the example):

$ sh example.sh --help
example - program to demonstrate unix-opts library

Available options:
  -h, --help                 print this help text
  -v, --verbose              verbose output
  -l, --level LEVEL          the program will run on LEVEL level
  -o, --output FILE          redirect output to file FILE
so that's how it works...

free args:
$ sh example.sh -v file1.txt file2.txt
OK, running in verbose mode...
free args: file1.txt, file2.txt
$ sh example.sh --level 10 --output foo.txt bar.txt
I see you've supplied level option, you want 10 level!
I see you want to output the stuff to "foo.txt"!
free args: bar.txt
$ sh example.sh --level kitty foo.txt
fatal: cannot parse "kitty" as argument of "--level"
free args:
$ sh example.sh --hoola-boola noola.txt
warning: "--hoola-boola" option is unknown!
free args: noola.txt
$ sh example.sh -vgl=10
warning: "-g" option is unknown!
OK, running in verbose mode...
I see you've supplied level option, you want 10 level!
free args:

unix-opts is written and maintained by Mark Karpov.

It's distributed under MIT-license.

Relevant topics: library, console, system programming command-line options parser