I'd like to get and parse command line arguments in Common Lisp, so that e.g. myscript -a 1 -b 2
will allow me to get the values, and myscript -xyz
will work too. How can I do it portably(between compilers)?
相关问题
- Drakma and Dexador both fails at USocket call whil
- Is it possible to pass command-line arguments to @
- How to use mutually exclusive flags in your shell
- Forming Lisp code to task — related to flatten lis
- clisp 2.49: asdf cannot find asd
相关文章
- Does learning one Lisp help in learning the other?
- Passing command line arguments to Java via ant bui
- Common Lisp: Why does my tail-recursive function c
- How do I write a macro-defining macro in common li
- Get command line arguments as string
- How can I unintern a qualified method?
- Changing the nth element of a list
- Is a “transparent” macrolet possible?
You can try
unix-options
.You probably want to
:use
the package, but if you prefer to import symbols from it, don't forget about&free
and¶meters
. The library defines agetopt
function which is similar to the traditionalgetopt
utility. But it also defineswith-cli-options
, which is a little more lispy.¶meters
define parameters, which must be followed by a value;&free
For example:
Here I define the entry point of the program. In a real program, you can simply leave the first list empty, like this:
... and the options will be portably fetched from the actual command line arguments of your Lisp implementation. You can also call
(uiop:command-line-arguments)
to have to full command line, which seems to support more implementations and includes the name of the program as the first element. The above function allows me to test the behavior of the parser. Note for example that short options can be separated or joined:Be careful about options that are declared as parameters but aren't given actual values (or maybe they are, the case is ambiguous):
There are warnings for unknown parameters:
See the docs for details.