You are looking at historical revision 23424 of this page. It may differ significantly from its current revision.
A very basic command-line option helper.
easy-args provides a simple way to handle command-line arguments as parameter objects.
Its use-case is singular: a list of possible command-line options is specified. For each of these, a new parameter object is created with a defualt value and optional guard procedure. These parameters can then be set from a list of command-line arguments.
define-arguments[syntax] (define-arguments (name value [guard]) ...)
Creates parameter objects for a set of possible command-line options. name must be an identifier and will be the name of the newly-created parameter object. value must be a string and will be the default value of the parameter object. guard may be a function which, if given, will be used as a conversion procedure when the parameter is assigned a value.
name, when prefixed by a single dash ("-"), will be used as that option's command-line flag. If name contains asterisks ("*"), they will be stripped from the flag.
use-argument-list[procedure] (use-argument-list lst)
Takes a flat list of strings to be considered as command-line arguments in alternating key/value order. Any parameter objects previously defined by define-arguments matching a key in the list will be set to the corresponding value.
A trivial example follows:
(use easy-args) (define-arguments (hello "Hello") (goodbye "Goodbye") (excitation-level "1" string->number)) (use-argument-list (command-line-arguments)) (for-each (lambda (message) (print (string-append (message) (make-string (excitation-level) #\!)))) (list hello goodbye))
With the file above as greeter.scm:
$ csc greeter.scm $ ./greeter Hello! Goodbye! $ ./greeter -hello "Greetings" -goodbye "Farewell" Greetings! Farewell! $ ./greeter -excitation-level 3 Hello!!! Goodbye!!!
- 0.1 Initial release
Copyright (c) 2010, Evan Hanson All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.