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