1 #! /usr/local/bin/runlisp
3 (let ((*compile-verbose* nil)
5 (asdf:oos 'asdf:load-op "mdw" :verbose nil))
7 (use-package '#:optparse)
8 (error (c) (invoke-debugger c)))
13 (defvar opt-int-list nil)
14 (defvar opt-string nil)
15 (defvar opt-keyword nil)
17 (defvar opt-counter 2)
18 (defvar opt-object nil)
21 :help "This program exists to test the Lisp options parser."
25 (help-options :short-version nil)
27 (#\b "boolean" (set opt-bool) (clear opt-bool)
28 ("Set (or clear, if negated) the boolean flag."))
29 (#\i "integer" (:arg "INT") (int opt-int :min -10 :max 10)
30 ("Set an integer between -10 and +10."))
31 (#\l "list" (:arg "STRING") (list opt-list)
32 ("Stash an item in the string list."))
33 (#\I "int-list" (:arg "INT")
34 (list opt-int-list 'int :min -10 :max (+ 5 5))
35 ("Stash an integer between -10 and +10 in the int list."))
36 (#\s "string" (:arg "STRING") (string opt-string)
38 (#\q "quiet" (dec opt-counter 0)
40 (#\v "verbose" (inc opt-counter 5)
42 (#\Q "very-quiet" (dec opt-counter 0 3)
43 ("Be much more quiet."))
44 (#\V "very-verbose" (inc opt-counter 5 3)
45 ("Be much more verbose."))
50 (:doc (concatenate 'string
52 (princ-to-string (get-universal-time))
54 (#\k "keyword" (:arg "KEYWORD") (keyword opt-keyword)
55 ("Set an arbitrary keyword."))
56 (#\e "enumeration" (:arg "ENUM")
57 (keyword opt-enum (list :apple :apple-pie :abacus :banana))
58 ("Set a keyword from a fixed set."))
59 (#\x "xray" (:arg "WAVELENGTH")
60 "Report an option immediately.")
61 (#\y "yankee" :yankee :no-yankee
62 "Report an option immediately.")
63 (#\z "zulu" (:opt-arg "TRIBE")
65 (when (and (plusp (length arg))
66 (char-equal (char arg 0) #\z))
67 (option-parse-return :zzulu arg))
68 (format t "Ignoring insufficiently zeddy Zulu ~A~%" arg))
69 "Report an option immediately.")))
72 (unless (option-parse-try
73 (do-options (:parser (make-option-parser :args args))
75 (format t "Emitting X-ray of wavelength ~A nm~%" arg))
77 (format t "Option ~S: `~A'~%" opt arg))
79 (format t "Non-option arguments: ~S~%" rest))))
81 (format t "boolean: ~S~%" opt-bool)
82 (format t "integer: ~S~%" opt-int)
83 (format t "list: ~S~%" opt-list)
84 (format t "int-list: ~S~%" opt-int-list)
85 (format t "string : ~S~%" opt-string)
86 (format t "counter: ~S~%" opt-counter)
87 (format t "keyword: ~S~%" opt-keyword)
88 (format t "enum: ~S~%" opt-enum)
89 (format t "object: ~S~%" opt-object))
90 (test (cdr *command-line-strings*))