| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
7.5.24 SRFI-37 - args-fold
This is a processor for GNU getopt_long-style program
arguments. It provides an alternative, less declarative interface
than getopt-long in (ice-9 getopt-long)
(see section The (ice-9 getopt-long) Module). Unlike
getopt-long, it supports repeated options and any number of
short and long names per option. Access it with:
(use-modules (srfi srfi-37))
SRFI-37 principally provides an option type and the
args-fold function. To use the library, create a set of
options with option and use it as a specification for invoking
args-fold.
Here is an example of a simple argument processor for the typical ‘--version’ and ‘--help’ options, which returns a backwards list of files given on the command line:
(args-fold (cdr (program-arguments))
(let ((display-and-exit-proc
(lambda (msg)
(lambda (opt name arg loads)
(display msg) (quit)))))
(list (option '(#\v "version") #f #f
(display-and-exit-proc "Foo version 42.0\n"))
(option '(#\h "help") #f #f
(display-and-exit-proc
"Usage: foo scheme-file ..."))))
(lambda (opt name arg loads)
(error "Unrecognized option `~A'" name))
(lambda (op loads) (cons op loads))
'())
- Scheme Procedure: option names required-arg? optional-arg? processor
Return an object that specifies a single kind of program option.
names is a list of command-line option names, and should consist of characters for traditional
getoptshort options and strings forgetopt_long-style long options.required-arg? and optional-arg? are mutually exclusive; one or both must be
#f. If required-arg?, the option must be followed by an argument on the command line, such as ‘--opt=value’ for long options, or an error will be signalled. If optional-arg?, an argument will be taken if available.processor is a procedure that takes at least 3 arguments, called when
args-foldencounters the option: the containing option object, the name used on the command line, and the argument given for the option (or#fif none). The rest of the arguments areargs-fold“seeds”, and the processor should return seeds as well.
- Scheme Procedure: option-names opt
- Scheme Procedure: option-required-arg? opt
- Scheme Procedure: option-optional-arg? opt
- Scheme Procedure: option-processor opt
Return the specified field of opt, an option object, as described above for
option.
- Scheme Procedure: args-fold args options unrecognized-option-proc operand-proc seed …
Process args, a list of program arguments such as that returned by
(cdr (program-arguments)), in order against options, a list of option objects as described above. All functions called take the “seeds”, or the last multiple-values as multiple arguments, starting with seed …, and must return the new seeds. Return the final seeds.Call
unrecognized-option-proc, which is like an option object’s processor, for any options not found in options.Call
operand-procwith any items on the command line that are not named options. This includes arguments after ‘--’. It is called with the argument in question, as well as the seeds.
| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on April 20, 2013 using texi2html 5.0.
