6.24  Unit: srfi-37

A simple and flexible command-line option parsing facility. Options may be either short one-character options of the form -X[ARGUMENT] or long multicharacter ones of the form -XXX[=ARGUMENT]. Short options may be coalesced. An argument of the form - stops option processing. For more information take a look at the SRFI-37 documentation 24.

An example:

#!/usr/local/bin/csi -script
;;;; secho - display command-line arguments

(define nl 1)

(define help 
  (option 
   '(#\h"help") #f #f
   (lambda _ 
     (print "Usage: secho [OPTION] ARG ...
  -h  --help          show this text
  -n  --newline N     add N newline characters (default: 1)\")
     (exit) ) ) )

(define newlines
  (option
   '(#\n"newline") #t #f
   (lambda (o n x vals)
     (set! nl (string->number x))
     vals) ) )

(for-each 
 (lambda (x) (print* x \#\space))
 (reverse
  (args-fold
   (command-line-arguments)
   (list help newlines)
   (lambda (o n x vals)
     (error "unrecognized option" n) )
   cons
   '() ) ) )

(display (make-string nl \#\newline))


24 http://srfi.schemers.org/srfi-37/srfi-37.html