chickadee » usage » make-usage

make-usage helperprocedure

Returns a procedure that, when called, prints a usage message for the running program. The usage message is the retun value of helper, a one-argument procedure which receives the program name (with the directory stripped) as argument.

The procedure returned by make-usage can optionally be given a number which indicates the program's exit code.

Here's an usage example of usage (considering the code below is in a file called usage-test):

(use usage)

(define usage
   (lambda (program)
     (print #<#EOH
Usage: #{program} <options>

<options> are:

  -foo: foobarizes
  -bar: barbarizes

(if (member "-h" (command-line-arguments))
    (usage 1))

When run with th -h command line argument, usage-test prints the usage message to (current-output-port). When run without command line options or with any option which is not -h, usage-test prints the usage message to (current-error-port) and aborts the program with exit code 1.

$ csi -s usage-test -h
Usage: usage-test <options>

<options> are:

  -foo: foobarizes
  -bar: barbarizes