Anybody got any experience with command line parsing for CL? We are making our first command line deliverable and would like to use a library for this. We're trying to keep our code portable between Allegro, Lispworks, SBCL and CCL.
-a
;; Read command line arguments
(defun command-line ()
"Get `groomed' command line arguments. These should just be the
arguments left to your program."
#+sbcl (cdr sb-ext:*posix-argv*)
#+lispworks system:*line-arguments*
#+cmu extensions:*command-line-words*
#+clisp ext:*args*
#-(or sbcl lispworks cmu clisp)
(error "Don't know how to get command line arguments in this Lisp.") )
(defun raw-command-line ()
"Get the raw command line. Not very useful as it may contain all
sorts of implementation dependent stuff. See COMMAND-LINE for
something a bit more useful."
#+sbcl sb-ext:*posix-argv*
#+clisp (ext:argv)
;; I don't have these imps
#+(or lispworks allegro)
(command-line)
;; Seems that command-line is the best I can do
#+(or cmu)
(command-line)
#-(or sbcl clisp lispworks allegro cmu)
(error "Don't know how to get command line arguments in this Lisp.") )smithzv wrote:I assume you have already found some of the libraries out there for doing this. Getopt and CL-cli-parser are available in Quicklisp.
smithzv wrote:Coincidentally, this morning I ended up using Getopt for a small script. Your previous post must have planted a seed because I haven't written a Lisp program invokable from the shell for a very long time. It seemed to work well and was simple to get working.
smithzv wrote:I'm not sure whether Getopt or cl-cli-parse are actively maintained. However, I doubt there is much activity on the GNU Getopt front either. It is a pretty simple functionality and is basically, dare I say, done. Lisp libraries in general are a testament to the idea that if something works, is compliant to a stable standard, and people don't fiddle with it, it will still work perpetually.
smithzv wrote:Another thing to keep in mind since you are "hiding the Lispness." Since you are probably going to be dumping a core, some lisps, like SBCL I believe, have options to control what arguments are passed to the executable core with it is run. There might be something similar to this in the other Lisps. Take a look at save-lisp-and-die and its equivalent in the other Lisps to be sure nothing funny will happen.
smithzv wrote:P.S. Never used CLON. In fact I was about to say you were confused and that CLON is a prototype based object oriented programming framework, but then I saw that there are several Lisp libraries named CLON. It actually might be something to really look at. It actually has a manual (big plus in my book), seems widely ported, and contains several of the features like typed option values and programmatically generated option help. It might be overkill for something that is a pretty simple problem.
Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests