chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] SRFI 37: Usage generator


From: Zbigniew
Subject: [Chicken-users] SRFI 37: Usage generator
Date: Tue, 7 Jun 2005 20:22:01 -0500

Based on the discussion Michele and I had, I updated my code to
generate usage text directly from the options you provide.  It is not
really a "parser" per se, but it is sweet with macro sugar. 
make-option's arguments are basically in the order they occur in usage
text.

http://gnook.org/~zbigniew/args/args.scm
http://gnook.org/~zbigniew/args/args-examples.scm

Here is an illustration [the output is spaced correctly under a
fixed-width font]:

(use args)
(define opt-help (args:make-option (h help) #:none "Display this text" (usage)))
(define opts
  (list (args:make-option (c cookie)    #:none     "give me cookie"
          (print "cookie was tasty"))
        (args:make-option (d)           (optional: "LEVEL")  "debug
level [default: 1]")
        (args:make-option (e elephant)  #:required "flatten the argument"
          (print "elephant: arg is " arg))
        (args:make-option (f file)      (required: "NAME") "parse file NAME")
        (args:make-option (v V version) #:none     "Display version"
          (print "args-examples $Revision: 1.13 $")
          (exit))
        (args:make-option (abc) #:none             "Recite the alphabet")
        opt-help))

(define (usage)
  (with-output-to-port (current-error-port)
    (lambda ()
      (print "Usage: " (car (argv)) " [options...] [files...]")
      (newline)
      (print (args:usage opts))
      (print "Report bugs to zbigniewsz at gmail.")))
  (exit 1))

(set!-values (options operands)
  (args:parse '("help") opts opt-help))

#|
Usage: ./args-examples [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.
|#


Two annoying things: args:make-option is a little verbose, and more
importantly the help option must be specified separately to args:parse
for proper unrecognized option handling.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]