Reformat all the docstrings.
[lisp] / optparse-test
CommitLineData
861345b4 1#! /usr/local/bin/runlisp
861345b4 2
3;; (format t "Startup!~%")
4(asdf:operate 'asdf:load-op 'mdw :verbose nil)
5fa07b7a 5(use-package '#:optparse)
861345b4 6
7(defvar opt-bool nil)
8(defvar opt-int nil)
9(defvar opt-list nil)
10(defvar opt-int-list nil)
11(defvar opt-string nil)
12(defvar opt-keyword nil)
13(defvar opt-enum nil)
14(defvar opt-counter 2)
15
16(defconstant options
17 (options
18 "Help options"
19 (#\h "help"
20 (lambda (arg)
21 (declare (ignore arg))
22 (show-help *program-name* "1.0.0" "usage-blah" options)
23 (exit 0))
24 ("Show this help text."))
25 ( "version"
26 (lambda (arg)
27 (declare (ignore arg))
28 (format t "~A, version ~A~%" *program-name* "1.0.0")
29 (exit 0))
30 ("Show ~A's version number." *program-name*))
31 "Test options"
32 (#\b "boolean" (set opt-bool) (clear opt-bool)
33 ("Set (or clear, if negated) the boolean flag."))
34 (#\i "integer" (:arg "INT") (int opt-int :min -10 :max 10)
35 ("Set an integer between -10 and +10."))
36 (#\l "list" (:arg "STRING") (list opt-list)
37 ("Stash an item in the string list."))
38 (#\I "int-list" (:arg "INT")
39 (list opt-int-list 'int :min -10 :max 10)
40 ("Stash an integer between -10 and +10 in the int list."))
41 (#\s "string" (:arg "STRING") (string opt-string)
42 ("Set a string."))
43 (#\q "quiet" (dec opt-counter 0)
44 ("Be more quiet."))
45 (#\v "verbose" (inc opt-counter 5)
46 ("Be more verbose."))
47 (#\Q "very-quiet" (dec opt-counter 0 3)
48 ("Be much more quiet."))
49 (#\V "very-verbose" (inc opt-counter 5 3)
50 ("Be much more verbose."))
51 (#\k "keywword" (:arg "KEYWORD") (keyword opt-keyword)
52 ("Set an arbitrary keyword."))
53 (#\e "enumeration" (:arg "ENUM")
54 (keyword opt-enum :apple :apple-pie :abacus :banana)
55 ("Set a keyword from a fixed set."))))
56
57(defun test (args)
5fa07b7a 58 (let ((op (make-option-parser :args (cdr args) :options options)))
861345b4 59 (unless (option-parse-try
60 (loop
61 (multiple-value-bind (opt arg) (option-parse-next op)
62 (unless opt (return))
63 (format t "Option ~S: `~A'~%" opt arg))))
64 (exit 1))
65 (format t "Non-option arguments: ~S~%" (option-parse-remainder op))
66 (format t "boolean: ~S~%" opt-bool)
67 (format t "integer: ~S~%" opt-int)
68 (format t "list: ~S~%" opt-list)
69 (format t "int-list: ~S~%" opt-int-list)
70 (format t "string : ~S~%" opt-string)
71 (format t "counter: ~S~%" opt-counter)
72 (format t "keyword: ~S~%" opt-keyword)
73 (format t "enum: ~S~%" opt-enum)))
74(test *command-line-strings*)
75
76
77