Commit | Line | Data |
---|---|---|
861345b4 | 1 | #! /usr/local/bin/runlisp |
861345b4 | 2 | |
8a2e8de1 MW |
3 | (let ((*compile-verbose* nil) |
4 | (*load-verbose* nil)) | |
5 | (asdf:oos 'asdf:load-op "mdw" :verbose nil)) | |
5fa07b7a | 6 | (use-package '#:optparse) |
861345b4 | 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) | |
b3bc3745 | 16 | (defvar opt-object nil) |
861345b4 | 17 | |
b3bc3745 MW |
18 | (define-program |
19 | :help "This program exists to test the Lisp options parser." | |
20 | :usage "ARGUMENTS..." | |
21 | :version "1.0.0" | |
22 | :options (options | |
23 | (help-options :short-version nil) | |
24 | "Test options" | |
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) | |
35 | ("Set a string.")) | |
36 | (#\q "quiet" (dec opt-counter 0) | |
37 | ("Be more quiet.")) | |
38 | (#\v "verbose" (inc opt-counter 5) | |
39 | ("Be more verbose.")) | |
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.")) | |
44 | ((:short-name #\o) | |
45 | (:long-name "object") | |
46 | (:arg "OBJECT") | |
47 | (read opt-object) | |
48 | (:doc (concatenate 'string | |
49 | "Read object (" | |
8a2e8de1 | 50 | (princ-to-string (get-universal-time)) |
b3bc3745 | 51 | ")"))) |
8a2e8de1 | 52 | (#\k "keyword" (:arg "KEYWORD") (keyword opt-keyword) |
b3bc3745 MW |
53 | ("Set an arbitrary keyword.")) |
54 | (#\e "enumeration" (:arg "ENUM") | |
a8bbb2e7 | 55 | (keyword opt-enum (list :apple :apple-pie :abacus :banana)) |
b3bc3745 MW |
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") | |
62 | (lambda (arg) | |
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."))) | |
861345b4 | 68 | |
69 | (defun test (args) | |
b3bc3745 MW |
70 | (unless (option-parse-try |
71 | (do-options (:parser (make-option-parser :args args)) | |
72 | (:xray (arg) | |
73 | (format t "Emitting X-ray of wavelength ~A nm~%" arg)) | |
74 | (t (opt arg) | |
75 | (format t "Option ~S: `~A'~%" opt arg)) | |
76 | (nil (rest) | |
77 | (format t "Non-option arguments: ~S~%" rest)))) | |
78 | (die-usage)) | |
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-strings*)) | |
861345b4 | 89 | |
90 | ||
91 |