2 ":"; exec cl-launch
-X
-s mdw
-- "$0" "$@" ||
exit 1 # -*-lisp-*-
4 (cl
:defpackage
#:optparse-test
5 (:use
#:common-lisp #:optparse))
6 (cl
:in-package
#:optparse-test)
11 (defvar opt-int-list nil
)
12 (defvar opt-string nil
)
13 (defvar opt-keyword nil
)
15 (defvar opt-counter
2)
16 (defvar opt-object nil
)
19 :help "This program exists to test the Lisp options parser."
23 (help-options
:short-version nil
)
25 (#\b "boolean" (set opt-bool) (clear opt-bool)
26 ("Set (or clear, if negated) the boolean flag."))
27 (#\i "integer" (:arg "INT") (int opt-int :min -10 :max 10)
28 ("Set an integer between -10 and +10."))
29 (#\l "list" (:arg "STRING") (list opt-list)
30 ("Stash an item in the string list."))
31 (#\I "int-list" (:arg "INT")
32 (list opt-int-list
'int :min -10 :max (+ 5 5))
33 ("Stash an integer between -10 and +10 in the int list."))
34 (#\s "string" (:arg "STRING") (string opt-string)
36 (#\q "quiet" (dec opt-counter 0)
38 (#\v "verbose" (inc opt-counter 5)
40 (#\Q "very-quiet" (dec opt-counter 0 3)
41 ("Be much more quiet."))
42 (#\V "very-verbose" (inc opt-counter 5 3)
43 ("Be much more verbose."))
48 (:doc (concatenate 'string
49 "Read object (time = "
50 (princ-to-string
(get-universal-time
))
52 (#\k "keyword" (:arg "KEYWORD") (keyword opt-keyword)
53 ("Set an arbitrary keyword."))
54 (#\e "enumeration" (:arg "ENUM")
55 (keyword opt-enum
(list
:apple
:apple-pie
:abacus
:banana
))
56 ("Set a keyword from a fixed set."))
57 (#\x "xray" (:arg "WAVELENGTH")
58 "Report an option immediately.")
59 (#\y "yankee" :yankee :no-yankee
60 "Report an option immediately.")
61 (#\z "zulu" (:opt-arg "TRIBE")
63 (when
(and
(plusp
(length arg
))
64 (char-equal
(char arg
0) #\z))
65 (option-parse-return
:zzulu arg
))
66 (format t
"Ignoring insufficiently zeddy Zulu ~A~%" arg
))
67 "Report an option immediately.")))
70 (unless
(option-parse-try
71 (do-options
(:parser
(make-option-parser
:args args
))
73 (format t
"Emitting X-ray of wavelength ~A nm~%" arg
))
75 (format t
"Option ~S: `~A'~%" opt arg
))
77 (format t
"Non-option arguments: ~S~%" rest
))))
79 (format t
"boolean: ~S~%" opt-bool
)
80 (format t
"integer: ~S~%" opt-int
)
81 (format t
"list: ~S~%" opt-list
)
82 (format t
"int-list: ~S~%" opt-int-list
)
83 (format t
"string : ~S~%" opt-string
)
84 (format t
"counter: ~S~%" opt-counter
)
85 (format t
"keyword: ~S~%" opt-keyword
)
86 (format t
"enum: ~S~%" opt-enum
)
87 (format t
"object: ~S~%" opt-object
))
88 (test (cdr
*command-line
*))