getopt-declare 1.13 → 1.20

Sign up to get free protection for your applications and to get access to all the features.
data/Declare.rdoc CHANGED
@@ -5,14 +5,24 @@
5
5
  #
6
6
  # = VERSION
7
7
  #
8
- # This document describes version 1.09 of Getopt::Declare,
9
- # released May 21, 1999 for Perl.
10
- # Released Jan 15, 2003 for Ruby.
8
+ # This document describes version 1.20 of Getopt::Declare,
9
+ # Released Jan 15, 2007 for Ruby.
10
+ #
11
+ # Original Perl's Getopt-Declare v1.09, Released May 21, 1999.
11
12
  #
12
13
  # = SYNOPSIS
13
14
  #
14
15
  # require "Getopt/Declare"
15
- # args = Getopt::Declare.new(specification_string, optional_source);
16
+ # args = Getopt::Declare.new(<<'EOF')
17
+ #
18
+ # -q, --quiet quiet
19
+ # -f, --files <files:if>... input files
20
+ #
21
+ # EOF
22
+ #
23
+ # p args['-q']
24
+ # p args['-f']
25
+ # p args.unused
16
26
  #
17
27
  #
18
28
  # = DESCRIPTION
@@ -81,8 +91,8 @@
81
91
  # * Optional conditional execution of embedded actions (i.e. only on
82
92
  # successful parsing of the entire command-line)
83
93
  #
84
- # * Strict or non-strict parsing (unrecognized command-line elements may either
85
- # trigger an error or may simply be left in +ARGV+
94
+ # * Strict or non-strict parsing (unrecognized command-line elements may
95
+ # either trigger an error or may simply be left in +ARGV+
86
96
  #
87
97
  # * Declarative specification of various inter-parameter relationships (for
88
98
  # example, two parameters may be declared mutually exclusive and this
@@ -97,6 +107,8 @@
97
107
  # * The ability to parse files (especially configuration files) instead of
98
108
  # the command-line.
99
109
  #
110
+ # * GNU style parameter definition allowed (-q, --quiet) in a single line.
111
+ #
100
112
  # == Terminology
101
113
  #
102
114
  # The terminology of command-line processing is often confusing, with various
@@ -136,8 +148,8 @@
136
148
  #
137
149
  # * <b>"parameter definition"</b>
138
150
  #
139
- # A specification of one actual syntax variant matched by a parameter. Always
140
- # consists of a leading _parameter_ _flag_ or _parameter_ _variable_,
151
+ # A specification of one actual syntax variant matched by a parameter.
152
+ # Always consists of a leading _parameter_ _flag_ or _parameter_ _variable_,
141
153
  # optionally followed by one or more _parameter_ _components_ (that is,
142
154
  # other parameter variables or _punctuators_. In the above example,
143
155
  # <tt>--window <height> x <width></tt> is a parameter definition.
@@ -145,18 +157,18 @@
145
157
  #
146
158
  # * <b>"parameter flag" (or just "flag")</b>
147
159
  #
148
- # A sequence of non-space characters which introduces a parameter. Traditionally
149
- # a parameter flag begins with "-" or "--", but Getopt::Declare allows
150
- # almost any sequence of characters to be used as a flag. In the above example,
151
- # <tt>--window</tt> is the parameter flag.
160
+ # A sequence of non-space characters which introduces a parameter.
161
+ # Traditionally a parameter flag begins with "-" or "--", but
162
+ # Getopt::Declare allows almost any sequence of characters to be used as
163
+ # a flag. In the above example, <tt>--window</tt> is the parameter flag.
152
164
  #
153
165
  #
154
166
  # * <b>"parameter variable"</b>
155
167
  #
156
168
  # A place-holder (within a parameter specification) for a value that
157
169
  # will appear in any argument matching that parameter. In the above example,
158
- # <tt>-height</tt>, <tt>-width</tt>, <tt>-h</tt>, <tt>-w</tt>, <tt>-x</tt>, and <tt>-y</tt> are
159
- # all parameter variables.
170
+ # <tt>-height</tt>, <tt>-width</tt>, <tt>-h</tt>, <tt>-w</tt>, <tt>-x</tt>,
171
+ # and <tt>-y</tt> are all parameter variables.
160
172
  #
161
173
  #
162
174
  # * <b>"parameter punctuator" (or just "punctuator")</b>
@@ -204,8 +216,9 @@
204
216
  # The parameter definition consists of a leading flag or parameter
205
217
  # variable, followed by any number of parameter variables or
206
218
  # punctuators, optionally separated by spaces. The parameter definition
207
- # is terminated by one or more tabs (at least one trailing tab _must_
208
- # be present).
219
+ # is terminated by one or more tabs or, alternatively, 3 or more spaces
220
+ # (at least one trailing tab or 3 trailing spaces _must_ appear for the
221
+ # line to be considered a parameter definition).
209
222
  #
210
223
  # For example, all of the following are valid Getopt::Declare parameter
211
224
  # definitions:
@@ -248,9 +261,9 @@
248
261
  # --lines1-10
249
262
  # --lines 1-10
250
263
  #
251
- # Note that the optional nature of spaces in parameter specification implies that
252
- # flags and punctuators cannot contain the character '<' (which is taken as the
253
- # delimiter for a parameter variable) nor the character '[' (which
264
+ # Note that the optional nature of spaces in parameter specification implies
265
+ # that flags and punctuators cannot contain the character '<' (which is taken
266
+ # as the delimiter for a parameter variable) nor the character '[' (which
254
267
  # introduces an optional parameter component - see
255
268
  # "Optional parameter components".
256
269
  #
@@ -344,8 +357,8 @@
344
357
  # -list [<page>...]
345
358
  #
346
359
  # Two or more parameter components may be made jointly optional, by specifying
347
- # them in the same pair of brackets. Optional components may also be nested. For
348
- # example:
360
+ # them in the same pair of brackets. Optional components may also be nested.
361
+ # For example:
349
362
  #
350
363
  # -range <from> [.. [<to>] ]
351
364
  #
@@ -364,6 +377,18 @@
364
377
  # Note that the actual flags for these three parameters are <tt>-num</tt>,
365
378
  # <tt>-lexic</tt> and <tt>-b</tt>, respectively.
366
379
  #
380
+ # == GNU-style parameters
381
+ #
382
+ # As of v1.20 of Getopt-Declare, it is also possible to write
383
+ # parameter descriptions following GNU's conventions.
384
+ # You can write, for example:
385
+ #
386
+ # -f, --file <file:if> Filename to read
387
+ #
388
+ # This allows both <tt>-f <file></tt> and <tt>--file <file></tt> to be
389
+ # valid options.
390
+ # When retrieving the value, use the short form <tt>args['-f']</tt>.
391
+ #
367
392
  # == Parameter descriptions
368
393
  #
369
394
  # Providing a textual description for each parameter (or parameter
@@ -423,7 +448,7 @@
423
448
  # same name. For example:
424
449
  #
425
450
  # +range <from>..<to> Set range
426
- # { setrange($from, $to) }
451
+ # { setrange(from, to) }
427
452
  #
428
453
  # -list <page:i>... Specify pages to list
429
454
  # { page.each { |i|
@@ -461,7 +486,7 @@
461
486
  # verbose = 2
462
487
  # else
463
488
  # verbose = 1
464
- # end
489
+ # end
465
490
  # }
466
491
  #
467
492
  # * <tt>\_FOUND_</tt> Hash
@@ -485,8 +510,8 @@
485
510
  #
486
511
  # For reasons that will be explained in "Rejection and termination",
487
512
  # a given parameter is not marked as found until _after_ its
488
- # associated actions are executed. That is, <tt>_FOUND_[\_PARAM_]</tt> will not
489
- # (usually) be true during a parameter action.
513
+ # associated actions are executed. That is, <tt>_FOUND_[\_PARAM_]</tt> will
514
+ # not (usually) be true during a parameter action.
490
515
  #
491
516
  #
492
517
  # Note that, although numerous other internal variables on which the
@@ -543,8 +568,9 @@
543
568
  #
544
569
  # -v Verbose mode
545
570
  #
546
- # means that the arguments "-q" and "-Q" will both match the <tt>-q</tt> parameter, but
547
- # that only "-v" (and _not_ "-V") will match the <tt>-v</tt> parameter.
571
+ # means that the arguments "-q" and "-Q" will both match the <tt>-q</tt>
572
+ # parameter, but that only "-v" (and _not_ "-V") will match the <tt>-v</tt>
573
+ # parameter.
548
574
  #
549
575
  # If a <tt>[nocase]</tt> directive appears anywhere _outside_ a parameter
550
576
  # description, then the entire specification is declared case-insensitive
@@ -630,16 +656,18 @@
630
656
  #
631
657
  # which restricts a parameter variable to matching positive, non-zero
632
658
  # numbers (that is, floating point numbers strictly greater than zero).
659
+ # Scientific notation can also be used.
633
660
  #
634
661
  # * :0+i
635
662
  #
636
- # which restricts a parameter variable to matching non-negative integers (that
637
- # is: 0, 1, 2, 3, etc.)
663
+ # which restricts a parameter variable to matching non-negative integers
664
+ # (that is: 0, 1, 2, 3, etc.)
638
665
  #
639
666
  # * :0+n
640
667
  #
641
- # which restricts a parameter variable to matching non-negative numbers (that
642
- # is, floating point numbers greater than or equal to zero).
668
+ # which restricts a parameter variable to matching non-negative numbers
669
+ # (that is, floating point numbers greater than or equal to zero).
670
+ # Scientific notation can also be used.
643
671
  #
644
672
  # * :s
645
673
  #
@@ -664,9 +692,10 @@
664
692
  #
665
693
  # * :of
666
694
  #
667
- # which is used to match output file names. It is exactly like type ':if' except
668
- # that it requires that the string is either "-" (indicating standard output)
669
- # or the name of a file that is either writable or non-existent.
695
+ # which is used to match output file names. It is exactly like type ':if'
696
+ # except that it requires that the string is either "-" (indicating
697
+ # standard output) or the name of a file that is either writable or
698
+ # non-existent.
670
699
  #
671
700
  # * :s
672
701
  #
@@ -697,14 +726,14 @@
697
726
  #
698
727
  # * %T
699
728
  #
700
- # If the sequence <tt>%T</tt> appears in a pattern, it is translated to a negative
701
- # lookahead containing the parameter variable's trailing context.
729
+ # If the sequence <tt>%T</tt> appears in a pattern, it is translated to a
730
+ # negative lookahead containing the parameter variable's trailing context.
702
731
  # Hence the parameter definition:
703
732
  #
704
733
  # -find <what:/(%T.)+/> ;
705
734
  #
706
- # ensures that the command line argument "-find abcd;" causes <tt><-what></tt>
707
- # to match "abcd", _not_ "abcd;".
735
+ # ensures that the command line argument "-find abcd;" causes
736
+ # <tt><-what></tt> to match "abcd", _not_ "abcd;".
708
737
  #
709
738
  #
710
739
  # * %D
@@ -793,10 +822,10 @@
793
822
  # match if it's Wednesday (like its parent type ":num").
794
823
  #
795
824
  # * the new type ":nbr" matches any string of digits (like its parent type
796
- # ":a num"), but then rejects the match if the global <tt>$no_nbr</tt> variable
797
- # is true. Otherwise it next prints out "a num!" (like its parent type
798
- # ":a num"), and finally rejects the match if it's Wednesday (like its
799
- # grandparent type ":num").
825
+ # ":a num"), but then rejects the match if the global <tt>$no_nbr</tt>
826
+ # variable is true. Otherwise it next prints out "a num!" (like its
827
+ # parent type ":a num"), and finally rejects the match if it's
828
+ # Wednesday (like its grandparent type ":num").
800
829
  #
801
830
  #
802
831
  # When a type action is executed (as part of a particular parameter
@@ -804,11 +833,12 @@
804
833
  #
805
834
  # * <tt>\_VAL_</tt> String/Fixnum/Float
806
835
  #
807
- # which contains the value matched by the type's pattern. It is this value which
808
- # is ultimately assigned to the local Ruby variable which is available to
809
- # parameter actions. Hence if the type action changes the value of <tt>\_VAL_</tt>,
810
- # that changed value becomes the "real" value of the corresponding parameter
811
- # variable (see the Roman numeral example below).
836
+ # which contains the value matched by the type's pattern. It is this
837
+ # value which is ultimately assigned to the local Ruby variable which is
838
+ # available to parameter actions. Hence if the type action changes the
839
+ # value of <tt>\_VAL_</tt>, that changed value becomes the "real" value
840
+ # of the corresponding parameter variable (see the Roman numeral example
841
+ # below).
812
842
  # Note that <tt>\_VAL_</tt> is a variable of different type based on
813
843
  # parameter specified. For [pvtype:...] it is always a String variable.
814
844
  #
@@ -909,8 +939,8 @@
909
939
  # Sometimes it is desirable to provide two or more alternate flags for
910
940
  # the same behaviour (typically, a short form and a long form). To
911
941
  # reduce the burden of specifying such pairs, the special directive
912
- # <tt>[ditto]</tt> is provided. If the description of a parameter _begins_ with
913
- # a <tt>[ditto]</tt> directive, that directive is replaced with the
942
+ # <tt>[ditto]</tt> is provided. If the description of a parameter _begins_
943
+ # with a <tt>[ditto]</tt> directive, that directive is replaced with the
914
944
  # description for the immediately preceding parameter (including any
915
945
  # other directives). For example:
916
946
  #
@@ -930,7 +960,8 @@
930
960
  # { $verbose = 1; }
931
961
  # --verbose [ditto]
932
962
  #
933
- # would result in the <tt>--verbose</tt> option setting <tt>$verbose</tt> just like the
963
+ # would result in the <tt>--verbose</tt> option setting
964
+ # <tt>$verbose</tt> just like the
934
965
  # <tt>-v</tt> option. On the other hand, the specification:
935
966
  #
936
967
  # -v Verbose mode
@@ -950,11 +981,11 @@
950
981
  # the command-line arguments they modify.
951
982
  #
952
983
  # To support this, Getopt::Declare provides a local operator (+defer+) which
953
- # delays the execution of a particular action until the command-line processing
954
- # is finished. The +defer+ operator takes a single block, the execution of which
955
- # is deferred until the command-line is fully and successfully parsed. If
956
- # command-line processing _fails_ for some reason (see "DIAGNOSTICS"), the
957
- # deferred blocks are never executed.
984
+ # delays the execution of a particular action until the command-line
985
+ # processing is finished. The +defer+ operator takes a single block, the
986
+ # execution of which is deferred until the command-line is fully and
987
+ # successfully parsed. If command-line processing _fails_ for some reason
988
+ # (see "DIAGNOSTICS"), the deferred blocks are never executed.
958
989
  #
959
990
  # For example:
960
991
  #
@@ -1016,8 +1047,8 @@
1016
1047
  # controlling "+".
1017
1048
  #
1018
1049
  # In some circumstances a clustered sequence of flags on the command-line
1019
- # might also match a single (multicharacter) parameter flag. For example, given
1020
- # the specifications:
1050
+ # might also match a single (multicharacter) parameter flag.
1051
+ # For example, given the specifications:
1021
1052
  #
1022
1053
  # -a Blood type is A
1023
1054
  # -b Blood type is B
@@ -1035,7 +1066,8 @@
1035
1066
  # but (as the above example illustrates) may not always do so. If the
1036
1067
  # idea of unconstrained flag clustering is too libertarian for a particular
1037
1068
  # application, the feature may be restricted (or removed completely),
1038
- # by including a <tt>[cluster:...]</tt> directive anywhere in the specification string.
1069
+ # by including a <tt>[cluster:...]</tt> directive anywhere in the
1070
+ # specification string.
1039
1071
  #
1040
1072
  # The options are:
1041
1073
  #
@@ -1047,7 +1079,8 @@
1047
1079
  # * <tt>[cluster: flags]</tt>
1048
1080
  #
1049
1081
  # This version of the directive restricts clustering to parameters which are
1050
- # "pure" flags (that is, those which have no parameter variables or punctuators).
1082
+ # "pure" flags (that is, those which have no parameter variables or
1083
+ # punctuators).
1051
1084
  #
1052
1085
  # * <tt>[cluster: singles]</tt>
1053
1086
  #
@@ -1072,15 +1105,17 @@
1072
1105
  # [cluster:singles]
1073
1106
  # EOSPEC
1074
1107
  #
1075
- # In the above example, only the <tt>-a</tt> and <tt>-b</tt> parameters may be clustered.
1108
+ # In the above example, only the <tt>-a</tt> and <tt>-b</tt> parameters may
1109
+ # be clustered.
1076
1110
  # The <tt>-bu</tt> parameter is excluded because it consists of more than one
1077
- # letter, whilst the <tt>-c</tt> and <tt>-d</tt> parameters are excluded because they
1078
- # take (or may take, in <tt>-d</tt>'s case) a variable. The <tt>-e[xec]</tt> parameter
1079
- # is excluded because it may take a trailing punctuator (<tt>[xec]</tt>).
1111
+ # letter, whilst the <tt>-c</tt> and <tt>-d</tt> parameters are excluded
1112
+ # because they take (or may take, in <tt>-d</tt>'s case) a variable. The
1113
+ # <tt>-e[xec]</tt> parameter is excluded because it may take a trailing
1114
+ # punctuator (<tt>[xec]</tt>).
1080
1115
  #
1081
1116
  # By comparison, if the directive had been <tt>[cluster: flags]</tt>, then
1082
- # <tt>-bu</tt> _could_ be clustered, though <tt>-c</tt>, <tt>-d</tt> and <tt>-e[xec]</tt> would
1083
- # still be excluded since they are not "pure flags").
1117
+ # <tt>-bu</tt> _could_ be clustered, though <tt>-c</tt>, <tt>-d</tt> and
1118
+ # <tt>-e[xec]</tt> would still be excluded since they are not "pure flags").
1084
1119
  #
1085
1120
  #
1086
1121
  # == Strict and non-strict command-line parsing
@@ -1185,8 +1220,8 @@
1185
1220
  #
1186
1221
  # However, it is sometimes useful to allow a particular parameter to match
1187
1222
  # more than once. Any parameter whose description includes the directive
1188
- # <tt>[repeatable]</tt> is _never_ excluded as a potential argument match, no matter
1189
- # how many times it has matched previously:
1223
+ # <tt>[repeatable]</tt> is _never_ excluded as a potential argument match,
1224
+ # no matter how many times it has matched previously:
1190
1225
  #
1191
1226
  # -nice Increase nice value (linearly if repeated)
1192
1227
  # [repeatable]
@@ -1196,9 +1231,9 @@
1196
1231
  # of the command-line
1197
1232
  # { warn = !warn }
1198
1233
  #
1199
- # As a more general mechanism is a <tt>[repeatable]</tt> directive appears in a
1200
- # specification anywhere other than a flag's description, then _all_ parameters
1201
- # are marked repeatable:
1234
+ # As a more general mechanism is a <tt>[repeatable]</tt> directive
1235
+ # appears in a specification anywhere other than a flag's description,
1236
+ # then _all_ parameters are marked repeatable:
1202
1237
  #
1203
1238
  # [repeatable]
1204
1239
  #
@@ -1259,9 +1294,10 @@
1259
1294
  # * <tt>[excludes: <flag list>]</tt>
1260
1295
  #
1261
1296
  # The <tt>[excludes:...]</tt> directive provides a "pairwise" version of
1262
- # mutual exclusion, specifying that the current parameter is mutually exclusive
1263
- # with all the other parameters lists, but those other parameters are not
1264
- # mutually exclusive with each other. That is, whereas the specification:
1297
+ # mutual exclusion, specifying that the current parameter is mutually
1298
+ # exclusive with all the other parameters lists, but those other
1299
+ # parameters are not mutually exclusive with each other. That is,
1300
+ # whereas the specification:
1265
1301
  #
1266
1302
  # -left Justify to left margin
1267
1303
  # -right Justify to right margin
@@ -1269,8 +1305,8 @@
1269
1305
  #
1270
1306
  # [mutex: -left -right -centre]
1271
1307
  #
1272
- # means that only one of these three justification alternatives can ever be used
1273
- # at once, the specification:
1308
+ # means that only one of these three justification alternatives can ever
1309
+ # be used at once, the specification:
1274
1310
  #
1275
1311
  # -left Justify to left margin
1276
1312
  # -right Justify to right margin
@@ -1278,7 +1314,8 @@
1278
1314
  #
1279
1315
  # means that <tt>-left</tt> and <tt>-right</tt> can still be used together
1280
1316
  # (probably to indicate "left _and_ right" justification), but that
1281
- # neither can be used with <tt>-centre</tt>. Note that the <tt>[excludes:...]</tt>
1317
+ # neither can be used with <tt>-centre</tt>. Note that
1318
+ # the <tt>[excludes:...]</tt>
1282
1319
  # directive also differs from the <tt>[mutex:...]</tt> in that it is always
1283
1320
  # connected with a paricular parameter, _implicitly_
1284
1321
  # using the flag of that parameter as the target of exclusion.
@@ -1290,7 +1327,8 @@
1290
1327
  # must also appear in order for a particular flag to be permitted in the
1291
1328
  # command-line. The condition is a boolean expression, in which the
1292
1329
  # terms are the flags or various parameters, and the operations are
1293
- # <tt>&&</tt>, <tt>||</tt>, <tt>!</tt>, and bracketting. For example, the specifications:
1330
+ # <tt>&&</tt>, <tt>||</tt>, <tt>!</tt>, and bracketting. For example,
1331
+ # the specifications:
1294
1332
  #
1295
1333
  # -num Use numeric sort order
1296
1334
  # -lex Use "dictionary" sort order
@@ -1301,31 +1339,36 @@
1301
1339
  # -rev Reverse sort order
1302
1340
  # [requires: -num || -lex || !(-len && -field)]
1303
1341
  #
1304
- # means that the <tt>-rev</tt> flag is allowed only if either the <tt>-num</tt> or the
1305
- # <tt>-lex</tt> parameter has been used, or if it is not true that
1306
- # _both_ the <tt>-len</tt> _and_ the <tt>-field</tt> parameters have been used.
1342
+ # means that the <tt>-rev</tt> flag is allowed only if either the
1343
+ # <tt>-num</tt> or the <tt>-lex</tt> parameter has been used, or if it
1344
+ # is not true that _both_ the <tt>-len</tt> _and_ the <tt>-field</tt>
1345
+ # parameters have been used.
1307
1346
  #
1308
- # Note that the operators <tt>&&</tt>, <tt>||</tt> and <tt>!</tt> retain their normal
1309
- # Ruby precedences.
1347
+ # Note that the operators <tt>&&</tt>, <tt>||</tt> and <tt>!</tt> retain
1348
+ # their normal Ruby precedences.
1310
1349
  #
1311
1350
  #
1312
1351
  # == Parsing from other sources
1313
1352
  #
1314
1353
  # Getopt::Declare normally parses the contents of +ARGV+, but can
1315
1354
  # be made to parse specified files or other sources instead.
1316
- # To accommodate this, Getopt::Declare::new() takes an optional second parameter, which specifies a file to be parsed.
1317
- # This second parameter can also be passed directly onto Getopt::Declare::parse()
1355
+ # To accommodate this, Getopt::Declare::new() takes an optional second
1356
+ # parameter, which specifies a file to be parsed.
1357
+ # This second parameter can also be passed directly onto
1358
+ # Getopt::Declare::parse()
1318
1359
  # The parameter may be either:
1319
1360
  #
1320
1361
  # * An +IO+ object
1321
1362
  #
1322
1363
  # in which case Getopt::Declare::new() reads the corresponding handle until
1323
- # end-of-file, and parses the resulting text (even if it is an empty string).
1364
+ # end-of-file, and parses the resulting text (even if it is an
1365
+ # empty string).
1324
1366
  #
1325
1367
  # * An ARRAY containing the single string ['-CONFIG']
1326
1368
  #
1327
1369
  # in which case Getopt::Declare::new() looks for the files
1328
- # <tt>ENV['HOME']/.#{progname}rc</tt> and <tt>ENV['PWD']/.#{progname}rc</tt>,
1370
+ # <tt>ENV['HOME']/.#{progname}rc</tt> and
1371
+ # <tt>ENV['PWD']/.#{progname}rc</tt>,
1329
1372
  # concatenates their contents, and parses that.
1330
1373
  #
1331
1374
  # If neither file is found (or if both are inaccessible)
@@ -1339,7 +1382,8 @@
1339
1382
  # See "The Getopt::Declare::code() method" and
1340
1383
  # "The Getopt::Declare::parse() method".
1341
1384
  #
1342
- # * An ARRAY containing the single string ['-SKIP'] or the single value [nil] or nothing []
1385
+ # * An ARRAY containing the single string ['-SKIP'] or the single
1386
+ # value [nil] or nothing []
1343
1387
  #
1344
1388
  # in which case Getopt::Declare::new() immediately returns zero.
1345
1389
  # This alternative is useful when using a +File+:
@@ -1348,8 +1392,8 @@
1348
1392
  # File.new(filename) || ['-SKIP'])
1349
1393
  #
1350
1394
  # because it makes explicit what happens if File::new() fails. Of course,
1351
- # if the <tt>['-SKIP']</tt> alternative were omitted, Getopt::Declare::new would
1352
- # still return immediately, having found +nil+ as its second argument.
1395
+ # if the <tt>['-SKIP']</tt> alternative were omitted, Getopt::Declare::new
1396
+ # would still return immediately, having found +nil+ as its second argument.
1353
1397
  #
1354
1398
  # * An ARRAY containing the word "-ARGV" followed by another ARRAY
1355
1399
  #
@@ -1362,7 +1406,8 @@
1362
1406
  # * Any other ARRAY
1363
1407
  #
1364
1408
  # in which case Getopt::Declare::new() treats the array elements as a
1365
- # list of filenames, concatenates the contents of those files, and parses that.
1409
+ # list of filenames, concatenates the contents of those files, and
1410
+ # parses that.
1366
1411
  #
1367
1412
  # If the list does not denote any accessible file(s)
1368
1413
  # Getopt::Declare::new() immediately returns zero. If matching files
@@ -1385,8 +1430,8 @@
1385
1430
  # * Parameter data
1386
1431
  #
1387
1432
  # For each successfully matched parameter, the Getopt::Declare object
1388
- # will contain a hash element. The key of that element will be the leading flag
1389
- # or parameter variable name of the parameter.
1433
+ # will contain a hash element. The key of that element will be the
1434
+ # leading flag or parameter variable name of the parameter.
1390
1435
  #
1391
1436
  # The value of the element will be another hash which contains
1392
1437
  # the names and values of each distinct parameter variable and/or
@@ -1396,8 +1441,9 @@
1396
1441
  # Float, String). List parameter variables generate Arrays.
1397
1442
  #
1398
1443
  # As a special case, if a parameter consists of a single component
1399
- # (either a single flag or a single parameter variable), then the value for the
1400
- # corresponding hash key is not another hash, but the actual value matched.
1444
+ # (either a single flag or a single parameter variable), then the value
1445
+ # for the corresponding hash key is not another hash, but the actual
1446
+ # value matched.
1401
1447
  #
1402
1448
  # The following example illustrates the various possibilities:
1403
1449
  #
@@ -1425,9 +1471,9 @@
1425
1471
  #
1426
1472
  # The values which are assigned to the various hash elements are copied from
1427
1473
  # the corresponding blocked-scoped variables which are available within
1428
- # actions. In particular, if the value of any of those block-scoped variables
1429
- # is changed within an action, that changed value is saved in the hash. For
1430
- # example, given the specification:
1474
+ # actions. In particular, if the value of any of those block-scoped
1475
+ # variables is changed within an action, that changed value is saved in
1476
+ # the hash. For example, given the specification:
1431
1477
  #
1432
1478
  # args = Getopt::Declare.new( %q{
1433
1479
  #
@@ -1455,12 +1501,14 @@
1455
1501
  #
1456
1502
  # * The Getopt::Declare::usage() method
1457
1503
  #
1458
- # Once a Getopt::Declare object is created, its <tt>usage()</tt> method may be called
1459
- # to explicitly print out usage information corresponding to the specification
1460
- # with which it was built. See "Usage information" for more details.
1461
- # If the <tt>usage()</tt> method is called with an argument, that argument is passed
1462
- # to <tt>exit</tt> after the usage information is printed (the no-argument version of
1463
- # <tt>usage()</tt> simply returns at that point).
1504
+ # Once a Getopt::Declare object is created, its <tt>usage()</tt> method
1505
+ # may be called to explicitly print out usage information corresponding
1506
+ # to the specification with which it was built. See "Usage information"
1507
+ # for more details.
1508
+ # If the <tt>usage()</tt> method is called with an argument, that argument
1509
+ # is passed to <tt>exit</tt> after the usage information is printed
1510
+ # (the no-argument version of <tt>usage()</tt> simply returns at that
1511
+ # point).
1464
1512
  #
1465
1513
  #
1466
1514
  # * The Getopt::Declare::version() method
@@ -1471,8 +1519,8 @@
1471
1519
  # Note that this implies that _all_ Getopt::Declare objects in a
1472
1520
  # single program will print out identical version information.
1473
1521
  #
1474
- # Like the <tt>usage()</tt> method, if <tt>version</tt> is passed an argument, it
1475
- # will exit with that value after printing.
1522
+ # Like the <tt>usage()</tt> method, if <tt>version</tt> is passed an
1523
+ # argument, it will exit with that value after printing.
1476
1524
  #
1477
1525
  #
1478
1526
  # * The Getopt::Declare::parse() method
@@ -1539,7 +1587,6 @@
1539
1587
  # specification, by extracting it from between the first "=for
1540
1588
  # Getopt::Declare" and the next "=cut" appearing on +$stdin+:
1541
1589
  #
1542
- # =begin
1543
1590
  # Just type in something, like:
1544
1591
  #
1545
1592
  # =for Getopt::Declare
@@ -1547,8 +1594,6 @@
1547
1594
  # -a Append mode
1548
1595
  # =cut
1549
1596
  #
1550
- # =end
1551
- #
1552
1597
  # $/ = '=cut'
1553
1598
  # if t = $stdin.readline
1554
1599
  # t.sub!( /^=for\s+Getopt::Declare\s*\n(.*?)\n=cut/esm ) {
@@ -1599,11 +1644,13 @@
1599
1644
  #
1600
1645
  # * All actions and comments are deleted,
1601
1646
  #
1602
- # * any <tt>[ditto]</tt> directive is converted to an appropriate set of "ditto" marks,
1647
+ # * any <tt>[ditto]</tt> directive is converted to an appropriate set of
1648
+ # "ditto" marks,
1603
1649
  #
1604
1650
  # * any text in matching square brackets (including any directive) is deleted,
1605
1651
  #
1606
- # * any parameter variable type specifier (":i", ":n", ":/pat/", etc.) is deleted.
1652
+ # * any parameter variable type specifier (":i", ":n", ":/pat/", etc.) is
1653
+ # deleted.
1607
1654
  #
1608
1655
  # Otherwise, the usage information displayed retains all the formatting
1609
1656
  # present in the original specification.
@@ -1615,10 +1662,10 @@
1615
1662
  # indicating how to determine the current version of the program (see
1616
1663
  # "Version parameters").
1617
1664
  #
1618
- # The usage information is printed to <tt>$stdout</tt> and (since Getopt::Declare
1619
- # tends to encourage longer and better-documented parameter lists) if
1620
- # the IO::Pager> package is available, an IO::Pager> object is used to
1621
- # page out the entire usage documentation.
1665
+ # The usage information is printed to <tt>$stdout</tt> and (since
1666
+ # Getopt::Declare tends to encourage longer and better-documented parameter
1667
+ # lists) if the IO::Pager> package is available, an IO::Pager> object is
1668
+ # used to page out the entire usage documentation.
1622
1669
  #
1623
1670
  # == Usage "decoration"
1624
1671
  #
@@ -1643,8 +1690,8 @@
1643
1690
  #
1644
1691
  # The following specification demonstrates various forms of usage
1645
1692
  # decoration. In fact, there are only four actual parameters (<tt>-in</tt>,
1646
- # <tt>-r</tt>, <tt>-p</tt>, and <tt>-out</tt>) specified. Note in particular that _leading_ tabs
1647
- # are perfectly acceptible in decorator lines.
1693
+ # <tt>-r</tt>, <tt>-p</tt>, and <tt>-out</tt>) specified. Note in particular
1694
+ # that _leading_ tabs are perfectly acceptible in decorator lines.
1648
1695
  #
1649
1696
  # args = Getopt::Declare.new(<<-'EOPARAM');
1650
1697
  #
@@ -1735,7 +1782,8 @@
1735
1782
  # specification (that is, it wasn't in the form: <_name_> or
1736
1783
  # <_name_:_type_>).
1737
1784
  #
1738
- # * "Error: bad type in Getopt::Declare parameter variable specification near %s"
1785
+ # * "Error: bad type in Getopt::Declare parameter variable specification
1786
+ # near %s"
1739
1787
  #
1740
1788
  # An unknown type specifier was used in a parameter variable type suffix.
1741
1789
  #
@@ -1745,9 +1793,10 @@
1745
1793
  #
1746
1794
  # * "Error: unattached action in Getopt::Declare specification:\n %s"
1747
1795
  #
1748
- # An action was found for which there was no preceding parameter specification.
1749
- # This usually occurs because the trailing tab was omitted from the preceding
1750
- # parameter specification.
1796
+ # An action was found for which there was no preceding parameter
1797
+ # specification.
1798
+ # This usually occurs because the trailing tab was omitted from the
1799
+ # preceding parameter specification.
1751
1800
  #
1752
1801
  # * "Error: incomplete action in Getopt::Declare specification:\n %s"
1753
1802
  #
@@ -1758,7 +1807,8 @@
1758
1807
  # The condition specified as part of the indicated <tt>[requires:...]</tt>
1759
1808
  # directive was not a well-formed boolean expression. Common problems
1760
1809
  # include: omitting a <tt>&&</tt>/<tt>||</tt> operator between two flags,
1761
- # mismatched brackets, or using <tt>and</tt>/<tt>or</tt> instead of <tt>&&</tt>/<tt>||</tt>.
1810
+ # mismatched brackets, or using <tt>and</tt>/<tt>or</tt> instead of
1811
+ # <tt>&&</tt>/<tt>||</tt>.
1762
1812
  #
1763
1813
  # * "Error: in generated command-line parser code:\n %s"
1764
1814
  #
@@ -1821,7 +1871,7 @@
1821
1871
  #
1822
1872
  # Gonzalo Garramuno (GGarramuno@aol.com) Ruby Port, Minor Bug Fixes,
1823
1873
  # Inline docs, and :d stdtype.
1824
- ##
1874
+ #
1825
1875
  # = BUGS AND ANNOYANCES
1826
1876
  #
1827
1877
  # There are undoubtedly serious bugs lurking somewhere in this code.
@@ -1835,7 +1885,7 @@
1835
1885
  # = COPYRIGHT
1836
1886
  #
1837
1887
  # Ruby Port:
1838
- # Copyright (c) 2004, Gonzalo Garramuno. All Rights Reserved.
1888
+ # Copyright (c) 2004-2007, Gonzalo Garramuno. All Rights Reserved.
1839
1889
  # This package is free software. It may be used, redistributed
1840
1890
  # and/or modified under the terms of the Perl Artistic License
1841
1891
  # (see http://www.perl.com/perl/misc/Artistic.html)
@@ -1848,14 +1898,18 @@
1848
1898
  #
1849
1899
  # This Getopt::Declare module relies on a custom version of DelimScanner.rb,
1850
1900
  # which is roughly a port of Perl's Text::Balanced.
1851
- # The main change added to that library was to add returning :suffix to several
1852
- # functions. DelimScanner.rb is:
1901
+ # The main change added to that library was to add returning :suffix to
1902
+ # several functions. DelimScanner.rb is:
1853
1903
  #
1854
1904
  # Copyright (c) 2002, 2003 The FaerieMUD Consortium. Most rights reserved.
1855
1905
  #
1856
- # This work is licensed under the Creative Commons Attribution License. To view
1857
- # a copy of this license, visit http://creativecommons.org/licenses/by/1.0 or
1858
- # send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
1859
- # 94305, USA.
1860
-
1906
+ # This work is licensed under the Creative Commons Attribution License.
1907
+ # To view a copy of this license, visit
1908
+ # http://creativecommons.org/licenses/by/1.0 or
1909
+ # send a letter to
1910
+ #
1911
+ # Creative Commons
1912
+ # 559 Nathan Abbott Way,
1913
+ # Stanford, California 94305, USA.
1914
+ #
1861
1915
 
data/HISTORY.txt CHANGED
@@ -1,3 +1,9 @@
1
+ 1.20 - Added support for using 3 spaces in addition to tabs for
2
+ parameter descriptions.
3
+ Added support for GNU -p, --param descriptions, for easier
4
+ GNU parameter support.
5
+ Fixed help description bug with [ditto] of single parameter flags.
6
+
1
7
  1.13 - Fixed bug that would always match parameters in a case insensitive
2
8
  way, as if [nocase] had been used. This should speed the parser a
3
9
  tiny bit.
data/Rakefile ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rake/gempackagetask'
4
+ require 'rake/rdoctask'
5
+
6
+ rdoc_files = ["Declare.rdoc", 'HISTORY.txt']
7
+
8
+ #
9
+ # TASK: Gem specification and creation ('gem')
10
+ #
11
+ spec = Gem::Specification.new do |spec|
12
+ spec.name = "getopt-declare"
13
+ spec.version = '1.20'
14
+ spec.author = "Gonzalo Garramuno"
15
+ spec.email = 'ggarra@advancedsl.com.ar, GGarramuno@aol.com'
16
+ spec.homepage = 'http://www.rubyforge.org/projects/getoptdeclare/'
17
+ spec.summary = 'Getopt-Declare is a command-line argument parser.'
18
+ spec.require_path = "lib"
19
+ spec.autorequire = "Getopt/Declare"
20
+ spec.files = ["lib/Getopt/Declare.rb", "lib/Getopt/DelimScanner.rb",
21
+ "Rakefile"]
22
+ spec.description = <<-"EOF"
23
+ Comprehensive and easy to use command-line parser library using
24
+ regular expressions. Port of Damian Conway\'s Perl Getopt-Declare.
25
+ EOF
26
+ # to fix emacs coloring bug
27
+ spec.extra_rdoc_files = rdoc_files
28
+ spec.has_rdoc = true
29
+ spec.test_files = Dir.glob('samples/*.rb')
30
+ spec.rubyforge_project = 'getoptdeclare'
31
+ spec.required_ruby_version = '>= 1.6.8'
32
+ end
33
+
34
+ Rake::GemPackageTask.new(spec) do |pkg|
35
+ pkg.need_tar = true
36
+ end
37
+
38
+
39
+ #
40
+ # TASK: Run rdoc to document code ('rdoc')
41
+ #
42
+ html_dir = 'doc/html'
43
+ library = 'Getopt/Declare'
44
+ Rake::RDocTask.new('rdoc') do |t|
45
+ t.rdoc_files.include(rdoc_files, 'lib/**/*.rb')
46
+ t.main = 'doc/index.html' # Main web page
47
+ t.title = "#{library} API documentation"
48
+ t.rdoc_dir = html_dir
49
+ end
50
+
51
+
52
+ #
53
+ # TASK: Upload docs to rubyforge ('upload-docs')
54
+ #
55
+ desc 'Upload documentation to RubyForge.'
56
+ task 'upload-docs' => ['rdoc'] do
57
+ rubyforge_user = 'gga'
58
+ rubyforge_project = spec.rubyforge_project
59
+ rubyforge_path = "/var/www/gforge-projects/#{rubyforge_project}/"
60
+
61
+ sh "scp -r #{html_dir}/* #{rubyforge_user}@rubyforge.org:#{rubyforge_path}"
62
+ end
63
+
64
+
65
+ #
66
+ # Main task
67
+ #
68
+ task :default => ['gem', 'upload-docs']
@@ -1,11 +1,11 @@
1
1
  #
2
2
  # Getopt::Declare - Declaratively Expressed Command-Line Arguments via Regular Expressions
3
3
  #
4
- # Ruby port of Perl's Getopt::Declare, version 1.12,
4
+ # Ruby port of Perl's Getopt::Declare, version 1.20,
5
5
  # released May 21, 1999.
6
6
  #
7
- # $Release Version: 1.12 $
8
- # $Date: 2004/01/15 10:53:09 $
7
+ # $Release Version: 1.20 $
8
+ # $Date: 2007/01/15 10:53:09 $
9
9
  # by Gonzalo Garramu�o
10
10
  #
11
11
  # For detailed instructions, see Declare.rdoc file
@@ -26,6 +26,7 @@
26
26
 
27
27
  require "Getopt/DelimScanner"
28
28
 
29
+
29
30
  # Verifies that code is valid Ruby code. returns false if not
30
31
  def valid_syntax?(code, fname = 'parser_code')
31
32
  eval("BEGIN {return true}\n#{code}", nil, fname, 0)
@@ -69,10 +70,14 @@ module Getopt
69
70
  # Main Class
70
71
  class Declare
71
72
 
72
- VERSION = '1.12'
73
+ VERSION = '1.20'
73
74
 
74
75
  # For debugging, use [debug] and it will output the ruby code as .CODE.rb
75
- @@debug = nil
76
+ @@debug = false
77
+
78
+ # Main separator used to distinguish arguments in Getopt/Declare spec.
79
+ # By default, one or more tabs or 3 spaces or more.
80
+ @@separator = '(?:\t+| {3})'
76
81
 
77
82
  # Class used to handle the beginning of options
78
83
  class StartOpt
@@ -108,7 +113,7 @@ module Getopt
108
113
  class EndOpt < StartOpt
109
114
  # Returns regex used matching end of options
110
115
  def matcher(g)
111
- '())?' # for emacs coloring we need a '
116
+ '())?'
112
117
  end
113
118
  end # EndOpt
114
119
 
@@ -123,7 +128,7 @@ module Getopt
123
128
  @@stdtype = {
124
129
  ':i' => { 'pattern' => '(?:(?:%T[+-]?)%D+)' },
125
130
  ':n' => { 'pattern' => '(?:(?:%T[+-]?)(?:%D+(?:%T\.%D*)?' +
126
- '(?:%T[eE]%D+)?|%T\.%D+(?:%T[eE]%D+)?))',
131
+ '(?:%T[eE](?:[+-])?%D+)?|%T\.%D+(?:%T[eE](?:[+-])?%D+)?))',
127
132
  },
128
133
  ':s' => { 'pattern' => '(?:%T(?:\S|\0))+' },
129
134
  ':qs' => { 'pattern' => %q#"(?:\\"|[^"])*"|'(?:\\'|[^"])*|(?:%T(?:\S|\0))+#
@@ -275,7 +280,7 @@ module Getopt
275
280
  end
276
281
 
277
282
  c = conversion
278
- c = "\n _VAL_ = _VAL_#{c}" if not c.empty?
283
+ c = "\n _VAL_ = _VAL_#{c}" if c
279
284
 
280
285
  code = <<-EOS
281
286
  _VAR_ = %q|<#{@name}>|
@@ -309,7 +314,7 @@ EOS
309
314
  return '.to_f'
310
315
  end
311
316
  }
312
- return ''
317
+ return nil
313
318
  end
314
319
 
315
320
  # Return string with code to cache argument in Getopt::Declare's cache
@@ -365,7 +370,7 @@ EOS
365
370
 
366
371
  # Handle conversion to proper type
367
372
  c = conversion
368
- if not c.empty?
373
+ if c
369
374
  code << " #{@name}.map! { |i| i#{c} }\n"
370
375
  end
371
376
 
@@ -503,16 +508,8 @@ EOS
503
508
  end
504
509
  end
505
510
 
506
- attr_accessor :flag
507
- attr_accessor :args
508
- attr_accessor :actions
509
- attr_accessor :ditto
510
- attr_accessor :required
511
- attr_accessor :requires
512
- attr_accessor :id
513
- attr_accessor :repeatable
514
- attr_accessor :desc
515
-
511
+ attr_accessor :flag, :args, :actions, :ditto, :nocase
512
+ attr_accessor :required, :requires, :id, :repeatable, :desc
516
513
 
517
514
 
518
515
  # Constructor
@@ -530,6 +527,7 @@ EOS
530
527
  @id = @@nextid
531
528
  @desc = spec.dup
532
529
  @items = 0
530
+ @nocase = false
533
531
 
534
532
  @desc.sub!(/\A\s*(.*?)\s*\Z/,'\1')
535
533
 
@@ -570,14 +568,14 @@ EOS
570
568
 
571
569
  # PUNCTUATION
572
570
  elsif spec.sub!( /\A(\s*)((\\.|[^\] \t\n\[<])+)/, "" )
573
- ows, punct = [ "#$1", "#$2" ]
571
+ ows, punct = $1, $2
574
572
  punct.gsub!( /\\(?!\\)(.)/, '\1' )
575
573
 
576
574
  if first == 1
577
575
  @flag = punct
578
576
  @@flags.push( punct )
579
577
  else
580
- @args.push( Punctuator.new(punct,!ows.length()) )
578
+ @args.push( Punctuator.new(punct, !(ows.size > 0)) )
581
579
  @items += 1
582
580
  end
583
581
 
@@ -587,7 +585,6 @@ EOS
587
585
  ensure
588
586
  first = 0
589
587
  end
590
-
591
588
  end # while
592
589
 
593
590
 
@@ -608,7 +605,7 @@ EOS
608
605
  flag = @flag
609
606
  clump = owner.clump
610
607
  i = 0
611
- nocase = ((Getopt::Declare::_nocase() || @nocase) ? 'i' : '')
608
+ nocasei = ((Getopt::Declare::nocase || @nocase) ? 'i' : '')
612
609
 
613
610
  code << " catch(:paramout) do\n"
614
611
  code += (!@repeatable) ? " while !_FOUND_['" + name() + "']" :
@@ -634,7 +631,7 @@ EOS
634
631
 
635
632
  code << '
636
633
  _args && _pos = gindex( _args, /\G(?:\s|\0)*' +
637
- Regexp::quote(flag) + boundary + '/' + nocase + ", _pos) or throw(:paramout)
634
+ Regexp::quote(flag) + boundary + '/' + nocasei + ", _pos) or throw(:paramout)
638
635
  unless @_errormsg
639
636
  @_errormsg = %q|incorrect specification of '" + flag + "' parameter|
640
637
  end
@@ -663,7 +660,7 @@ EOS
663
660
  code << @args[i].ows(@args[i].matcher(trailer[i]))
664
661
  }
665
662
 
666
- code << '/x' + nocase + ", _pos ) or throw(:paramout)\n"
663
+ code << '/x' + nocasei + ", _pos ) or throw(:paramout)\n"
667
664
  end # if @args
668
665
 
669
666
  0.upto( argcount ) { |i|
@@ -694,16 +691,25 @@ EOS
694
691
  code << "\n " + action + "\n"
695
692
  end
696
693
 
697
- if (flag && @items==0)
694
+ if flag && @items==0
698
695
  code << "\n @cache['#{flag}'] = '#{flag}'\n"
696
+ if @ditto
697
+ code << "\n @cache['#{@ditto.flag}'] = '#{flag}'\n"
698
+ end
699
699
  end
700
700
 
701
701
  if @items > 1
702
702
  code << " @cache['#{self.name}'] = {} unless @cache['#{self.name}']\n"
703
+ if @ditto
704
+ code << "\n @cache['#{@ditto.name}'] = {} unless @cache['#{@ditto.name}']\n"
705
+ end
703
706
  end
704
707
 
705
708
  for subarg in @args
706
- code << subarg.cachecode(self.name(),@items)
709
+ code << subarg.cachecode(self.name,@items)
710
+ if ditto
711
+ code << subarg.cachecode(@ditto.name,@items)
712
+ end
707
713
  end
708
714
 
709
715
  if flag =~ /\A([^a-z0-9]+)/i
@@ -742,10 +748,9 @@ EOS
742
748
 
743
749
  private
744
750
 
745
- # Check if global ignore case in regex is defined
746
- def Declare._nocase(*t)
747
- @@nocase = t[0] if t[0]
748
- @@nocase
751
+ class << self
752
+ @nocase = false
753
+ attr_accessor :nocase
749
754
  end
750
755
 
751
756
  #
@@ -782,13 +787,13 @@ EOS
782
787
  # Given an array or hash, flatten them to a string
783
788
  def flatten(val, nested = nil)
784
789
  case val
785
- when Array
790
+ when Array
786
791
  return val.map{ |i| flatten(i,1) }.join(" ")
787
- when Hash
792
+ when Hash
788
793
  return val.keys().map{ |i| nested ||
789
794
  i =~ /^-/ ? [i, flatten(val[i],1)] :
790
795
  [flatten(val[i],1)] }.join(" ")
791
- else
796
+ else
792
797
  return val
793
798
  end
794
799
  end
@@ -851,9 +856,9 @@ EOS
851
856
 
852
857
  if desc =~ /\[no\s*case\]/i
853
858
  if arg
854
- arg.nocase = true #should it be _nocase
859
+ arg.nocase = true
855
860
  else
856
- _nocase( true )
861
+ nocase = true
857
862
  end
858
863
  end
859
864
 
@@ -935,7 +940,7 @@ EOS
935
940
  originaldesc.gsub!(/""/,'" ')
936
941
  end
937
942
 
938
- "#{originaldesc}#{extra}"
943
+ "#{originaldesc}#{extra}\n"
939
944
  end
940
945
 
941
946
  # Check mutex conditions
@@ -961,6 +966,17 @@ EOS
961
966
  end
962
967
  end
963
968
 
969
+ # Returns a regex to match a single argument line
970
+ def re_argument
971
+ /\A(.*?\S.*?#{@@separator})(.*?\n)/
972
+ end
973
+
974
+ # Returns a regex to keep matching a multi-line description
975
+ # for an argument.
976
+ def re_more_desc
977
+ /\A((?![ \t]*(\{|\n)|.*?\S.*?#{@@separator}.*?\S).*?\S.*\n)/
978
+ end
979
+
964
980
  public
965
981
 
966
982
  # Constructor
@@ -993,9 +1009,10 @@ EOS
993
1009
  _strict = false
994
1010
  _all_repeatable = false
995
1011
  _lastdesc = nil
996
- Getopt::Declare::_nocase( false )
1012
+ Getopt::Declare::nocase = false
997
1013
  Getopt::Declare::ScalarArg::_reset_stdtype()
998
1014
 
1015
+
999
1016
  # CONSTRUCT GRAMMAR
1000
1017
  while i.length > 0
1001
1018
 
@@ -1047,21 +1064,39 @@ EOS
1047
1064
 
1048
1065
 
1049
1066
  # ARG + DESC:
1050
- if i.sub!(/\A(.*?\S.*?)(\t.*\n)/,"")
1051
- spec = "#$1"
1067
+ if i.sub!(re_argument,"")
1068
+ spec = "#$1".strip
1052
1069
  desc = "#$2"
1053
1070
  _strict ||= desc =~ /\[strict\]/
1054
1071
 
1055
- desc += "#$1" while i.sub!(/\A((?![ \t]*(\{|\n)|.*?\S.*?\t.*?\S).*?\S.*\n)/,"")
1072
+ while i.sub!(re_more_desc,"")
1073
+ desc += "#$1"
1074
+ end
1056
1075
 
1057
1076
  ditto = nil
1058
- ditto = 1 if _lastdesc and desc.sub!(/\A\s*\[ditto\]/,_lastdesc)
1059
- _lastdesc = desc
1077
+ if _lastdesc and desc.sub!(/\A\s*\[ditto\]/,_lastdesc)
1078
+ ditto = arg
1079
+ else
1080
+ _lastdesc = desc
1081
+ end
1082
+
1083
+ # Check for GNU spec line like: -d, --debug
1084
+ arg = nil
1085
+ if spec =~ /(-[\w_\d]+),\s+(--[\w_\d]+)(\s+.*)?/
1086
+ specs = ["#$1#$3", "#$2#$3"]
1087
+ specs.each { |spec|
1088
+ arg = Arg.new(spec,desc,ditto)
1089
+ _args.push( arg )
1090
+ _infer(desc, arg, _mutex)
1091
+ ditto = arg
1092
+ }
1093
+ else
1094
+ arg = Arg.new(spec,desc,ditto)
1095
+ _args.push( arg )
1096
+ _infer(desc, arg, _mutex)
1097
+ end
1060
1098
 
1061
- arg = Arg.new(spec,desc,ditto)
1062
- _args.push( arg )
1063
1099
 
1064
- _infer(desc, arg, _mutex)
1065
1100
  next
1066
1101
  end
1067
1102
 
@@ -1222,10 +1257,6 @@ EOS
1222
1257
  Getopt::Declare::ScalarArg::addtype(t)
1223
1258
  end
1224
1259
 
1225
-
1226
- @@nocase = false
1227
-
1228
-
1229
1260
  # Print out version information and maybe exit
1230
1261
  def version(*t)
1231
1262
  prog = "#{$0}"
@@ -1278,15 +1309,14 @@ EOS
1278
1309
 
1279
1310
 
1280
1311
  # ARG + DESC:
1281
- if t.sub!(/\A(.*?\S.*?\t+)(.*?\n)/,"")
1312
+ if t.sub!(re_argument,"")
1282
1313
  decfirst = 0 unless !decfirst.nil?
1283
1314
  spec = "#$1".expand_tabs!()
1284
1315
  desc = "#$2".expand_tabs!()
1285
1316
 
1286
- t.gsub!(/\A((?![ \t]*(\{|\n)|.*?\S.*?\t.*?\S).*?\S.*\n)/) { |i|
1287
- desc += "#$1".expand_tabs!()
1288
- ""
1289
- }
1317
+ while t.gsub!(re_more_desc, '')
1318
+ desc += "#$1".expand_tabs!
1319
+ end
1290
1320
 
1291
1321
  next if desc =~ /\[undocumented\]/i
1292
1322
 
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: getopt-declare
5
5
  version: !ruby/object:Gem::Version
6
- version: "1.13"
7
- date: 2006-05-17 00:00:00 -03:00
6
+ version: "1.20"
7
+ date: 2007-01-17 00:00:00 -03:00
8
8
  summary: Getopt-Declare is a command-line argument parser.
9
9
  require_paths:
10
10
  - lib
11
11
  email: ggarra@advancedsl.com.ar, GGarramuno@aol.com
12
12
  homepage: http://www.rubyforge.org/projects/getoptdeclare/
13
13
  rubyforge_project: getoptdeclare
14
- description: Comprehensive and easy to use command-line parser library using regular expressions. Port of Conway's Perl Getopt-Declare.
14
+ description: Comprehensive and easy to use command-line parser library using regular expressions. Port of Damian Conway's Perl Getopt-Declare.
15
15
  autorequire: Getopt/Declare
16
16
  default_executable:
17
17
  bindir: bin
18
- has_rdoc: false
18
+ has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
21
  - - ">="
@@ -25,14 +25,15 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Gonzalo Garramuno
30
31
  files:
31
32
  - lib/Getopt/Declare.rb
32
33
  - lib/Getopt/DelimScanner.rb
34
+ - Rakefile
33
35
  - Declare.rdoc
34
36
  - HISTORY.txt
35
- - getoptdeclare.gemspec
36
37
  test_files:
37
38
  - samples/cmdline_basic.rb
38
39
  - samples/cmdline_mid.rb
@@ -57,7 +58,6 @@ rdoc_options: []
57
58
  extra_rdoc_files:
58
59
  - Declare.rdoc
59
60
  - HISTORY.txt
60
- - getoptdeclare.gemspec
61
61
  executables: []
62
62
 
63
63
  extensions: []
@@ -1,22 +0,0 @@
1
- require "rubygems"
2
-
3
- spec = Gem::Specification.new do |spec|
4
- spec.name = "getopt-declare"
5
- spec.version = '1.13'
6
- spec.author = "Gonzalo Garramuno"
7
- spec.email = 'ggarra@advancedsl.com.ar, GGarramuno@aol.com'
8
- spec.homepage = 'http://www.rubyforge.org/projects/getoptdeclare/'
9
- spec.summary = 'Getopt-Declare is a command-line argument parser.'
10
- spec.require_path = "lib"
11
- spec.autorequire = "Getopt/Declare"
12
- spec.files = ["lib/Getopt/Declare.rb", "lib/Getopt/DelimScanner.rb"]
13
- spec.description = <<-EOF
14
- Comprehensive and easy to use command-line parser library using
15
- regular expressions. Port of Conway's Perl Getopt-Declare.
16
- EOF
17
- spec.extra_rdoc_files = ["Declare.rdoc", "HISTORY.txt", "getoptdeclare.gemspec"]
18
- spec.has_rdoc = false
19
- spec.test_files = Dir.glob('samples/*.rb')
20
- spec.rubyforge_project = 'getoptdeclare'
21
- spec.required_ruby_version = '>= 1.6.8'
22
- end