Changeset 15624 in project


Ignore:
Timestamp:
08/29/09 07:08:49 (10 years ago)
Author:
iraikov
Message:

formatting fixes to getopt-long documenation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/getopt-long

    r15623 r15624  
    3636equivalent to {{--OPTION}}.  This is how to specify traditional
    3737Unix-style flags.
     38; {{(required? BOOL)}} : If {{BOOL}} is true, the option is required. {{getopt-long}} will raise an error if it is not found in the list of arguments.
     39; {{(value FLAG [(PROPERTY VALUE) ...])}} : If {{FLAG}} is {{#t}}, the option requires a value; if it is {{#f}}, it does not; if it is of the form {{(REQUIRED name)}} then the option requires and the name is used by the usage procedure if it is of the form {{(OPTIONAL name)}} the option may appear with or without a (named) value.
    3840
    39 ; {{(required? BOOL)}} : If {{BOOL}} is true, the option is
    40 required. {{getopt-long}} will raise an error if it is not found in
    41 the list of arguments.
    42 
    43 ; {{(value FLAG [(PROPERTY VALUE) ...])}} : If {{FLAG}} is {{#t}}, the
    44 option requires a value; if it is {{#f}}, it does not; if it is of the
    45 form {{(REQUIRED name)}} then the option requires and the name is used
    46 by the usage procedure if it is of the form {{(OPTIONAL name)}} the
    47 option may appear with or without a (named) value.
    48            
    4941In addition, the following properties can be defined for a value:
    5042
    51 ; {{(predicate FUNC)}} : If the option accepts a value (i.e. you
    52 specified {{(value #t)}} for this option), then {{getopt-long}} will
    53 apply {{FUNC}} to the value, and throw an exception if it returns
    54 {{#f}}.  {{FUNC}} should be a procedure which accepts a string and
    55 returns a boolean value; you may need to use quasiquotes to get it
    56 into the grammar.
    57 
    58 ; {{(transformer FUNC)}} : If the option accepts a value, then getopt
    59 will apply FUNC to the string provided on the command line, and put
    60 the resulting value in the list of parsed options returned by
    61 getopt-long.
     43; {{(predicate FUNC)}} : If the option accepts a value (i.e. you specified {{(value #t)}} for this option), then {{getopt-long}} will apply {{FUNC}} to the value, and throw an exception if it returns {{#f}}.  {{FUNC}} should be a procedure which accepts a string and returns a boolean value; you may need to use quasiquotes to get it into the grammar.
     44; {{(transformer FUNC)}} : If the option accepts a value, then getopt will apply FUNC to the string provided on the command line, and put the resulting value in the list of parsed options returned by getopt-long.
    6245
    6346The {{(PROPERTY VALUE)}} pairs may occur in any order, but each
     
    137120
    138121{{getopt-long}} throws an exception if:
    139  * it finds an unrecognized property in GRAMMAR
    140  * the value of the `single-char' property is not a character
    141  * it finds an unrecognized option in ARGS
    142  * a required option is omitted
    143  * an option that requires an argument doesn't get one
    144 
    145  * an option that doesn't accept an argument does get one (this can only happen using the long option {{--opt=value}} syntax)
    146  * an option predicate fails
     122* it finds an unrecognized property in GRAMMAR
     123* the value of the `single-char' property is not a character
     124* it finds an unrecognized option in ARGS
     125* a required option is omitted
     126* an option that requires an argument doesn't get one
     127* an option that doesn't accept an argument does get one (this can only happen using the long option {{--opt=value}} syntax)
     128* an option predicate fails
    147129
    148130=== Examples
     
    152134                  (value #t)
    153135                  (single-char #\k)
    154                   (value (required DIR)
     136                  (value (required DIR)
    155137                         (predicate ,directory?)))
    156 
     138 
    157139    (verbose (required? #f)
    158140             (single-char #\v)
    159141             (value #f))
    160 
     142 
    161143    (x-includes (single-char #\x)
    162144                (value #t))
    163 
     145 
    164146    (rnet-server (single-char #\y)
    165147                 (value (required SERVER)
    166148                        (predicate ,string?)))
    167149    ))
    168 
     150 
    169151  (getopt-long '("my-prog" "-vk" "/tmp" "foo1" "--x-includes=/usr/include"
    170152                 "--rnet-server=lamprod" "--" "-fred" "foo2" "foo3")
     
    189171
    190172 Copyright 2009 Ivan Raikov.
    191 
     173 
    192174 Portions copyright (C) 1998, 2001, 2006 Free Software Foundation,
    193175 Inc.
    194 
     176 
    195177 This program is free software: you can redistribute it and/or
    196178 modify it under the terms of the GNU Lesser General Public License
    197179 as published by the Free Software Foundation, either version 3 of
    198180 the License, or (at your option) any later version.
    199 
     181 
    200182 This program is distributed in the hope that it will be useful, but
    201183 WITHOUT ANY WARRANTY; without even the implied warranty of
    202184 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    203185 General Public License for more details.
    204 
     186 
    205187 A full copy of the Lesser GPL license can be found at
    206188 <http://www.gnu.org/licenses/>.
Note: See TracChangeset for help on using the changeset viewer.