#! /usr/local/bin/runlisp ;;; -*-lisp-*- ;; (format t "Startup!~%") (asdf:operate 'asdf:load-op 'mdw :verbose nil) (use-package '#:mdw.optparse) (defvar opt-bool nil) (defvar opt-int nil) (defvar opt-list nil) (defvar opt-int-list nil) (defvar opt-string nil) (defvar opt-keyword nil) (defvar opt-enum nil) (defvar opt-counter 2) (defconstant options (options "Help options" (#\h "help" (lambda (arg) (declare (ignore arg)) (show-help *program-name* "1.0.0" "usage-blah" options) (exit 0)) ("Show this help text.")) ( "version" (lambda (arg) (declare (ignore arg)) (format t "~A, version ~A~%" *program-name* "1.0.0") (exit 0)) ("Show ~A's version number." *program-name*)) "Test options" (#\b "boolean" (set opt-bool) (clear opt-bool) ("Set (or clear, if negated) the boolean flag.")) (#\i "integer" (:arg "INT") (int opt-int :min -10 :max 10) ("Set an integer between -10 and +10.")) (#\l "list" (:arg "STRING") (list opt-list) ("Stash an item in the string list.")) (#\I "int-list" (:arg "INT") (list opt-int-list 'int :min -10 :max 10) ("Stash an integer between -10 and +10 in the int list.")) (#\s "string" (:arg "STRING") (string opt-string) ("Set a string.")) (#\q "quiet" (dec opt-counter 0) ("Be more quiet.")) (#\v "verbose" (inc opt-counter 5) ("Be more verbose.")) (#\Q "very-quiet" (dec opt-counter 0 3) ("Be much more quiet.")) (#\V "very-verbose" (inc opt-counter 5 3) ("Be much more verbose.")) (#\k "keywword" (:arg "KEYWORD") (keyword opt-keyword) ("Set an arbitrary keyword.")) (#\e "enumeration" (:arg "ENUM") (keyword opt-enum :apple :apple-pie :abacus :banana) ("Set a keyword from a fixed set.")))) (defun test (args) (let ((op (make-option-parser (cdr args) options))) (unless (option-parse-try (loop (multiple-value-bind (opt arg) (option-parse-next op) (unless opt (return)) (format t "Option ~S: `~A'~%" opt arg)))) (exit 1)) (format t "Non-option arguments: ~S~%" (option-parse-remainder op)) (format t "boolean: ~S~%" opt-bool) (format t "integer: ~S~%" opt-int) (format t "list: ~S~%" opt-list) (format t "int-list: ~S~%" opt-int-list) (format t "string : ~S~%" opt-string) (format t "counter: ~S~%" opt-counter) (format t "keyword: ~S~%" opt-keyword) (format t "enum: ~S~%" opt-enum))) (test *command-line-strings*)