;; $Revision: 1.3 $ $Date: 2005/07/13 19:07:50 $ (use eggdoc) (include "eggdoc-zb.scm") (define examples `( (pre #< " (alist-ref 'elephant options))) ;; 'e or 'elephant both work ;; If command line is --cookie -e test -e hello: ;; cookie was tasty ;; elephant: arg is test ;; elephant: arg is hello ;; -e -> hello ;; If command line is --cookie -e test --foo: #| cookie was tasty elephant: arg is test ./args-example: unrecognized option: foo Usage: ./args-example [options...] [files...] -c, --cookie give me cookie -d [LEVEL] debug level [default: 1] -e, --elephant=ARG flatten the argument -f, --file=NAME parse file NAME -v, -V, --version Display version --abc Recite the alphabet -h, --help Display this text Report bugs to zbigniewsz at gmail. |# EOF ) (p "Additional examples can be found in " (a (@ (href "args-examples.scm")) "args-examples.scm") "."))) (define doc `((eggdoc:begin (name "args") (description "Command-line argument handling facilities, layered on SRFI 37 (args-fold).") (author (a (@ (href ,zbigniew-homepage)) "Zbigniew")) (history ; (version "1.1" (b "Fix typo")) (version "1.0" "Initial release")) (requires "srfi-37 [args-fold]" "srfi-13 [string-lib]" "srfi-1 [list-lib]") (usage) (download "args.egg") ;; download may also be a pair, in which case it's inserted verbatim (documentation (p "This extension provides a wrapper around SRFI 37 (args-fold). The main goal is to let the user parse command-line arguments without having to write a lot of similar support code every time.") (p "By default, options and operands (non-options) are collected into two lists and returned by the parser, and unrecognized options complain and display help. Therefore, it is very possible not to write any option-procs, operand-procs, or unrecognized-procs as required by SRFI 37. However, the capability to customize is there should you need it.") (p "Additionally, the help text for your options can be generated for you, so your options and usage information don't get out of sync.") ;;; CREATING OPTIONS (subsection "Creating options" ;; I'd like multiple signatures sometimes -- should they be a plain list, ;; an element followed by a list, one element per signature, attributes (@), or what? (group (macro "(args:make-option (OPTION-NAME ...) ARG-DATA [BODY])" (p "Make an args:option record, suitable for passing to args:parse.") (p "OPTION-NAME ... is a sequence of short or long option names. " "They must be literal symbols; single-character symbols become " "short options, and longer symbols become long options. So " (tt "(args:make-option (c cookie) ...)") " specifies a short " "option -c and long option --cookie. Under the hood, (c cookie) " "becomes '(#\\c \"cookie\"), as expected by SRFI 37's OPTION.") (p "ARG-DATA is either a pair (ARG-TYPE ARG-NAME) or a plain keyword ARG-TYPE. ARG-TYPE is a keyword that specifies whether the option takes an argument:") (symbol-table (describe "#:required" "Argument is required") (describe "#:optional" "Argument is optional") (describe "#:none" "No argument (actually, any other value than #:required or #:optional is interpreted as #:none)")) (p "ARG-NAME, if provided, is a string specifying the name of the argument. This name is used in the help text produced by args:usage.") (p "BODY is an optional sequence of statements executed when this option is encountered. Behind the scenes, BODY is wrapped in code which adds the current option and its argument to the final options alist. So, simply leave BODY blank and options will be collected for you. BODY is an option-processor as defined in SRFI 37, and has access to the variables OPT (the current #