getopt-declare 1.20 → 1.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Declare.rdoc +18 -4
  2. data/HISTORY.txt +9 -0
  3. data/Rakefile +3 -3
  4. data/lib/Getopt/Declare.rb +96 -91
  5. metadata +3 -1
data/Declare.rdoc CHANGED
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # = VERSION
7
7
  #
8
- # This document describes version 1.20 of Getopt::Declare,
8
+ # This document describes version 1.21 of Getopt::Declare,
9
9
  # Released Jan 15, 2007 for Ruby.
10
10
  #
11
11
  # Original Perl's Getopt-Declare v1.09, Released May 21, 1999.
@@ -17,6 +17,8 @@
17
17
  #
18
18
  # -q, --quiet quiet
19
19
  # -f, --files <files:if>... input files
20
+ # -n, --number <num:n> a float number
21
+ # -i, --integer <num:i> an integer number
20
22
  #
21
23
  # EOF
22
24
  #
@@ -230,8 +232,8 @@
230
232
  # ignore bad lines
231
233
  # <outfile>
232
234
  #
233
- # Note that each of the above examples has at least one trailing tab
234
- # (even if you can't see them). Note too that this hodge-podge of
235
+ # Note that each of the above examples has to have at least one trailing tab
236
+ # (even if here Ruby's rdoc strips them). Note too that this hodge-podge of
235
237
  # parameter styles is certainly not recommended within a single program,
236
238
  # but is shown so as to illustrate some of the range of parameter syntax
237
239
  # conventions Getopt::Declare supports.
@@ -380,7 +382,7 @@
380
382
  # == GNU-style parameters
381
383
  #
382
384
  # As of v1.20 of Getopt-Declare, it is also possible to write
383
- # parameter descriptions following GNU's conventions.
385
+ # parameter definitions following GNU's conventions, within a single line.
384
386
  # You can write, for example:
385
387
  #
386
388
  # -f, --file <file:if> Filename to read
@@ -682,6 +684,18 @@
682
684
  # this type requires that the matched string is name of an existing
683
685
  # (and accesable) directory.
684
686
  #
687
+ # * :qs
688
+ #
689
+ # which allows a parameter variable to match any quote-delimited or
690
+ # whitespace-terminated string. Note that this specifier simply makes
691
+ # explicit the default behaviour.
692
+ #
693
+ # * :id
694
+ #
695
+ # which allows a parameter variable to match any identifier
696
+ # sequence. That is: a alphabetic or underscore, followed by
697
+ # zero-or-more alphanumerics or underscores.
698
+ #
685
699
  # * :if
686
700
  #
687
701
  # which is used to match input file names. Like type ':s', type ':if'
data/HISTORY.txt CHANGED
@@ -1,3 +1,12 @@
1
+ 1.21 - Incorporated Perl fixes done by Damian in v1.10 and v1.11 of the
2
+ corresponding Getopt-Declare into Ruby.
3
+
4
+ * If -p[rompt] and -p[rompt]2 are specified, they are now distinguished
5
+ as separate flags.
6
+ * Documented built-in :id and :qs parameter variable types
7
+ * Added \G to -v flag checker to solve nasty problem with embedded
8
+ args containing -v
9
+
1
10
  1.20 - Added support for using 3 spaces in addition to tabs for
2
11
  parameter descriptions.
3
12
  Added support for GNU -p, --param descriptions, for easier
data/Rakefile CHANGED
@@ -3,14 +3,14 @@
3
3
  require 'rake/gempackagetask'
4
4
  require 'rake/rdoctask'
5
5
 
6
- rdoc_files = ["Declare.rdoc", 'HISTORY.txt']
6
+ rdoc_files = ["Declare.rdoc", 'HISTORY.txt'] + Dir.glob('lib/*/*.rb')
7
7
 
8
8
  #
9
9
  # TASK: Gem specification and creation ('gem')
10
10
  #
11
11
  spec = Gem::Specification.new do |spec|
12
12
  spec.name = "getopt-declare"
13
- spec.version = '1.20'
13
+ spec.version = '1.21'
14
14
  spec.author = "Gonzalo Garramuno"
15
15
  spec.email = 'ggarra@advancedsl.com.ar, GGarramuno@aol.com'
16
16
  spec.homepage = 'http://www.rubyforge.org/projects/getoptdeclare/'
@@ -42,7 +42,7 @@ end
42
42
  html_dir = 'doc/html'
43
43
  library = 'Getopt/Declare'
44
44
  Rake::RDocTask.new('rdoc') do |t|
45
- t.rdoc_files.include(rdoc_files, 'lib/**/*.rb')
45
+ t.rdoc_files.include(rdoc_files)
46
46
  t.main = 'doc/index.html' # Main web page
47
47
  t.title = "#{library} API documentation"
48
48
  t.rdoc_dir = html_dir
@@ -1,10 +1,10 @@
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.20,
4
+ # Ruby port of Perl's Getopt::Declare, version 1.21,
5
5
  # released May 21, 1999.
6
6
  #
7
- # $Release Version: 1.20 $
7
+ # $Release Version: 1.21 $
8
8
  # $Date: 2007/01/15 10:53:09 $
9
9
  # by Gonzalo Garramu�o
10
10
  #
@@ -62,7 +62,7 @@ end
62
62
 
63
63
  # Regex for removing bracket directives
64
64
  BracketDirectives =
65
- /\[(?:ditto|tight|strict|repeatable|debug|required|mutex:.*|implies:.*|excludes:.*|requires:.*|cluster:.*)\]/
65
+ /\[\s*(?:ditto|tight|strict|no\s*case|repeatable|debug|required|mutex:.*|implies:.*|excludes:.*|requires:.*|cluster:.*)\s*\]/
66
66
 
67
67
 
68
68
  module Getopt
@@ -124,27 +124,26 @@ module Getopt
124
124
  @@stdtype = {}
125
125
 
126
126
  # (re)set standard types
127
- def ScalarArg._reset_stdtype()
127
+ def ScalarArg._reset_stdtype
128
128
  @@stdtype = {
129
129
  ':i' => { 'pattern' => '(?:(?:%T[+-]?)%D+)' },
130
130
  ':n' => { 'pattern' => '(?:(?:%T[+-]?)(?:%D+(?:%T\.%D*)?' +
131
131
  '(?:%T[eE](?:[+-])?%D+)?|%T\.%D+(?:%T[eE](?:[+-])?%D+)?))',
132
132
  },
133
- ':s' => { 'pattern' => '(?:%T(?:\S|\0))+' },
134
- ':qs' => { 'pattern' => %q#"(?:\\"|[^"])*"|'(?:\\'|[^"])*|(?:%T(?:\S|\0))+#
135
- },
136
- ':id' => { 'pattern' => '%T[a-zA-Z_](?:%T\w)*' },
133
+ ':s' => { 'pattern' => '(?:%T(?:\S|\0))+(?=\s|\0|\z)' },
134
+ ':qs' => { 'pattern' => %q{"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|(?:%T(?:\S|\0))+(?=\s|\0|\z)} },
135
+ ':id' => { 'pattern' => '%T[a-zA-Z_](?:%T\w)*(?=\s|\0|\z)' },
137
136
  ':d' => { 'pattern' => '(?:%T(?:\S|\0))+',
138
137
  'action' => %q%
139
138
  reject( (_VAL_.nil? || !test(?d, _VAL_) ),
140
139
  "in parameter '#{_PARAM_}' (\"#{_VAL_}\" is not a directory)")%
141
140
  },
142
- ':if' => { 'pattern' => '%F(?:%T(?:\S|\0))+',
141
+ ':if' => { 'pattern' => '%F(?:%T(?:\S|\0))+(?=\s|\0|\z)',
143
142
  'action' => %q%
144
143
  reject( (_VAL_.nil? || _VAL_ != "-" && !test(?r, _VAL_) ),
145
144
  "in parameter '#{_PARAM_}' (file \"#{_VAL_}\" is not readable)")%
146
145
  },
147
- ':of' => { 'pattern' => '%F(?:%T(?:\S|\0))+',
146
+ ':of' => { 'pattern' => '%F(?:%T(?:\S|\0))+(?=\s|\0|\z)',
148
147
  'action' => %q%
149
148
  reject( (_VAL_.nil? || _VAL_ != "-" &&
150
149
  test(?r, _VAL_) && !test(?w, _VAL_)),
@@ -266,15 +265,15 @@ module Getopt
266
265
  stdtype.gsub!(/\%D/,"(?:#{trailing}\\d)")
267
266
  stdtype.gsub!(/\%T/,trailing)
268
267
  unless ( stdtype.sub!("\%F","") )
269
- stdtype = Getopt::Declare::Arg::negflagpat() + stdtype
268
+ stdtype = Getopt::Declare::Arg::negflagpat + stdtype
270
269
  end
271
- "(?:#{stdtype})"
270
+ return "(?:#{stdtype})"
272
271
  end
273
272
 
274
273
  # Return string with code to process parameter
275
274
  def code(*t)
276
275
  if t[0]
277
- pos1 = t[0].to_s()
276
+ pos1 = t[0].to_s
278
277
  else
279
278
  pos1 = '0'
280
279
  end
@@ -334,7 +333,7 @@ EOS
334
333
  # Helps build regex that matches parameters of flags
335
334
  # Wraps parameter passed for #$1, etc. matching
336
335
  def ows(g)
337
- return '(?:\s|\0)*(' + g + ')' unless @nows
336
+ return '[\s|\0]*(' + g + ')' unless @nows
338
337
  '('+ g +')'
339
338
  end
340
339
 
@@ -346,17 +345,17 @@ EOS
346
345
 
347
346
  # Create regexp to match array
348
347
  def matcher(g)
349
- suffix = !g.nil? ? '\s+' : ''
350
- scalar = super(g) # contains regex to match a scalar element
348
+ suffix = !g.nil? ? '([\s\0]+)' : ''
349
+ scalar = super # contains regex to match a scalar element
351
350
  # we match one obligatory element, and one or more optionals ')*'
352
- scalar + '(?:\s+' + scalar + ')*' + suffix
351
+ return scalar + '(?:[\s\0]+' + scalar + ')*' + suffix
353
352
  end
354
353
 
355
354
  # Return string with code to process array parameter
356
355
  def code(*t)
357
356
 
358
357
  if t[0]
359
- pos1 = t[0].to_s()
358
+ pos1 = t[0].to_s
360
359
  else
361
360
  pos1 = '0'
362
361
  end
@@ -382,7 +381,7 @@ EOS
382
381
  end
383
382
  code << " end\n\n"
384
383
  end
385
- code
384
+ return code
386
385
  end
387
386
 
388
387
  # Return string with code to cache array in Getopt::Declare's cache
@@ -408,14 +407,14 @@ EOS
408
407
 
409
408
  # Return regex that matches this punctuation
410
409
  def matcher(g)
411
- Arg::negflagpat() + Regexp::quote(@text)
410
+ Arg::negflagpat + Regexp::quote(@text)
412
411
  end
413
412
 
414
413
  # Return string with code to process punctuation
415
414
  def code(*t)
416
415
 
417
416
  if t[0]
418
- pos1 = t[0].to_s()
417
+ pos1 = t[0].to_s
419
418
  else
420
419
  pos1 = '0'
421
420
  end
@@ -430,7 +429,9 @@ EOS
430
429
  if itemcount > 1
431
430
  " @cache['#{ownerflag}']['#{@text}'] = _PUNCT_['#{@text}']\n"
432
431
  else
433
- " @cache['#{ownerflag}'] = _PUNCT_['#{@text}'] || 1\n"
432
+ " unless @cache['#{ownerflag}']\n" +
433
+ " @cache['#{ownerflag}'] = _PUNCT_['#{@text}'] || 1\n" +
434
+ " end\n"
434
435
  end
435
436
  end
436
437
 
@@ -442,7 +443,7 @@ EOS
442
443
  # Helps build regex that matches parameters of flags
443
444
  # Wraps parameter passed for #$1, etc. matching
444
445
  def ows(g)
445
- return '(?:\s|\0)*(' + g + ')' unless @nows
446
+ return '[\s\0]*(' + g + ')' unless @nows
446
447
  '(' + g + ')'
447
448
  end #ows
448
449
 
@@ -466,7 +467,7 @@ EOS
466
467
 
467
468
  # Create regex of help flags based on help shortcuts left
468
469
  def Arg.helppat
469
- @@helpcmdH.keys().join('|')
470
+ @@helpcmdH.keys.join('|')
470
471
  end
471
472
 
472
473
 
@@ -481,7 +482,7 @@ EOS
481
482
 
482
483
  # Create regex of version flags based on help shortcuts left
483
484
  def Arg.versionpat
484
- @@versioncmdH.keys().join('|')
485
+ @@versioncmdH.keys.join('|')
485
486
  end
486
487
 
487
488
  @@flags = []
@@ -518,7 +519,8 @@ EOS
518
519
 
519
520
 
520
521
  @@nextid += 1
521
- @flag = ''
522
+ @flag = nil
523
+ @foundid = nil
522
524
  @args = []
523
525
  @actions = []
524
526
  @ditto = dittoflag
@@ -556,7 +558,8 @@ EOS
556
558
  arg =~ /\A(\s*)(<)([a-zA-Z]\w*)(:[^>]+|)>/ or
557
559
  raise "Error: bad Getopt::Declare parameter variable specification near '#{arg}'\n"
558
560
 
559
- details = [ "#$3", "#$4", !first && !nows.length ] # NAME,TYPE,NOW
561
+ # NAME,TYPE,NOW
562
+ details = [ "#$3", "#$4", !first && !(nows.length>0) ]
560
563
 
561
564
  if spec && spec.sub!( /\A\.\.\./, "") # ARRAY ARG
562
565
  @args.push( ArrayArg.new(*details) )
@@ -567,11 +570,13 @@ EOS
567
570
  next
568
571
 
569
572
  # PUNCTUATION
570
- elsif spec.sub!( /\A(\s*)((\\.|[^\] \t\n\[<])+)/, "" )
573
+ elsif spec.sub!( /\A(\s*)((\\.|[^\] \t\n\[<])+)/, '' )
571
574
  ows, punct = $1, $2
572
575
  punct.gsub!( /\\(?!\\)(.)/, '\1' )
573
576
 
574
- if first == 1
577
+ if first
578
+ spec =~ /\A(\S+)/
579
+ @foundid = "#{punct}#{$1}"
575
580
  @flag = punct
576
581
  @@flags.push( punct )
577
582
  else
@@ -583,7 +588,7 @@ EOS
583
588
  break
584
589
  end # if arg/spec.sub
585
590
  ensure
586
- first = 0
591
+ first = nil
587
592
  end
588
593
  end # while
589
594
 
@@ -608,8 +613,8 @@ EOS
608
613
  nocasei = ((Getopt::Declare::nocase || @nocase) ? 'i' : '')
609
614
 
610
615
  code << " catch(:paramout) do\n"
611
- code += (!@repeatable) ? " while !_FOUND_['" + name() + "']" :
612
- " while 1"
616
+ code += !@repeatable? " while !_FOUND_['" + @foundid + "']" :
617
+ " while 1"
613
618
  if (flag && (clump==1 && flag !~ /\A[^a-z0-9]+[a-z0-9]\Z/i ||
614
619
  (clump<3 && @args )))
615
620
  code << " && !_lastprefix"
@@ -630,7 +635,7 @@ EOS
630
635
  boundary = '(\s+|\Z)' if flag =~ /^(--|-|\+|\+\+)$/
631
636
 
632
637
  code << '
633
- _args && _pos = gindex( _args, /\G(?:\s|\0)*' +
638
+ _args && _pos = gindex( _args, /\G[\s|\0]*' +
634
639
  Regexp::quote(flag) + boundary + '/' + nocasei + ", _pos) or throw(:paramout)
635
640
  unless @_errormsg
636
641
  @_errormsg = %q|incorrect specification of '" + flag + "' parameter|
@@ -641,13 +646,13 @@ EOS
641
646
  end
642
647
 
643
648
 
644
- code << "\n _PARAM_ = '" + self.name() + "'\n"
649
+ code << "\n _PARAM_ = '" + self.name + "'\n"
645
650
 
646
651
 
647
652
  trailer = []
648
- i = argcount = @args.length()-1
653
+ i = @args.size-1
649
654
  while i > 0
650
- trailer[i-1] = @args[i].trailer()
655
+ trailer[i-1] = @args[i].trailer
651
656
  trailer[i-1] = trailer[i] unless trailer[i-1]
652
657
  i -= 1
653
658
  end # while i
@@ -656,16 +661,18 @@ EOS
656
661
  if @args
657
662
  code << "\n"+' _args && _pos = gindex( _args, /\G'
658
663
 
659
- 0.upto( argcount ) { |i|
660
- code << @args[i].ows(@args[i].matcher(trailer[i]))
664
+ @args.each_with_index { |arg, i|
665
+ code << arg.ows(arg.matcher(trailer[i]))
661
666
  }
662
667
 
668
+ code << '\b'
669
+
663
670
  code << '/x' + nocasei + ", _pos ) or throw(:paramout)\n"
664
671
  end # if @args
665
672
 
666
- 0.upto( argcount ) { |i|
667
- code << @args[i].code(i,mod) #, $flag ????
668
- }
673
+ @args.each_with_index { |arg, i|
674
+ code << arg.code(i,mod) #, $flag ????
675
+ }
669
676
 
670
677
  if flag
671
678
  mutexlist = owner.mutex[flag] ?
@@ -699,9 +706,9 @@ EOS
699
706
  end
700
707
 
701
708
  if @items > 1
702
- code << " @cache['#{self.name}'] = {} unless @cache['#{self.name}']\n"
709
+ code << " @cache['#{self.name}'] = {} unless @cache['#{self.name}'].kind_of?(Hash)\n"
703
710
  if @ditto
704
- code << "\n @cache['#{@ditto.name}'] = {} unless @cache['#{@ditto.name}']\n"
711
+ code << "\n @cache['#{@ditto.name}'] = {} unless @cache['#{@ditto.name}'].kind_of?(Hash)\n"
705
712
  end
706
713
  end
707
714
 
@@ -719,9 +726,9 @@ EOS
719
726
  end
720
727
 
721
728
  code << "
722
- _FOUND_['"+ self.name() + "'] = 1
729
+ _FOUND_['"+ self.foundid + "'] = 1
723
730
  throw :arg if _pos > 0
724
- _nextpos = _args.length()
731
+ _nextpos = _args.size
725
732
  throw :alldone
726
733
  end # catch(:param)
727
734
  end # begin
@@ -734,13 +741,12 @@ EOS
734
741
 
735
742
  # Return name of argument, which can be flag's name or variable's name
736
743
  def name
737
- if flag.nil? || flag.empty?
738
- i = 0
739
- i += 1 while !defined?(args[i].name)
740
- "<#{(@args[i]).name}>"
741
- else
742
- @flag
743
- end
744
+ return @flag || "<#{@args[0].name}>"
745
+ end
746
+
747
+ # Return foundid of argument, which can be flag's name or variable's name
748
+ def foundid
749
+ return @foundid || '<#{@args[0].name}>'
744
750
  end
745
751
 
746
752
  end # Arg
@@ -767,7 +773,7 @@ EOS
767
773
  def gindex(str, re, pos)
768
774
  @@m.clear()
769
775
  if pos = str.index( re, pos )
770
- l = $&.length() # length of match
776
+ l = $&.size # length of match
771
777
  if l > 0
772
778
  @@m[0] = "#$1"
773
779
  @@m[1] = "#$2"
@@ -790,7 +796,7 @@ EOS
790
796
  when Array
791
797
  return val.map{ |i| flatten(i,1) }.join(" ")
792
798
  when Hash
793
- return val.keys().map{ |i| nested ||
799
+ return val.keys.map{ |i| nested ||
794
800
  i =~ /^-/ ? [i, flatten(val[i],1)] :
795
801
  [flatten(val[i],1)] }.join(" ")
796
802
  else
@@ -852,9 +858,11 @@ EOS
852
858
 
853
859
  # Check parameter description for special options
854
860
  def _infer(desc, arg, mutex)
855
- _mutex(mutex, "#$1".split(' ')) while desc.sub!(/\[mutex:\s*(.*?)\]/i,"")
861
+ while desc.sub!(/\[\s*mutex:\s*(.*?)\]/i,"")
862
+ _mutex(mutex, "#$1".split(' '))
863
+ end
856
864
 
857
- if desc =~ /\[no\s*case\]/i
865
+ if desc =~ /\[\s*no\s*case\s*\]/i
858
866
  if arg
859
867
  arg.nocase = true
860
868
  else
@@ -863,20 +871,20 @@ EOS
863
871
  end
864
872
 
865
873
  if !arg.nil?
866
- if desc =~ /.*\[excludes:\s*(.*?)\]/i
874
+ if desc =~ /.*\[\s*excludes:\s*(.*?)\]/i
867
875
  _exclude(mutex, arg.name, ("#$1".split(' ')))
868
876
  end
869
877
 
870
- if desc =~ /.*\[requires:\s*(.*?)\]/i
878
+ if desc =~ /.*\[\s*requires:\s*(.*?)\]/i
871
879
  arg.requires = "#$1"
872
880
  end
873
881
 
874
- arg.required = ( desc =~ /\[required\]/i )
882
+ arg.required = ( desc =~ /\[\s*required\s*\]/i )
875
883
 
876
- arg.repeatable = ( desc =~ /\[repeatable\]/i )
884
+ arg.repeatable = ( desc =~ /\[\s*repeatable\s*\]/i )
877
885
  end
878
886
 
879
- _typedef(desc) while desc.sub!(/.*?\[pvtype:\s*/,"")
887
+ _typedef(desc) while desc.sub!(/.*?\[\s*pvtype:\s*/,"")
880
888
 
881
889
  end
882
890
 
@@ -886,7 +894,7 @@ EOS
886
894
  # of standard types
887
895
  def _typedef(desc)
888
896
  se = DelimScanner::new( desc )
889
- tmp = se.scanQuotelike()
897
+ tmp = se.scanQuotelike
890
898
 
891
899
  name = nil
892
900
  name, desc = tmp[:delimText], tmp[:suffix] if tmp
@@ -915,7 +923,7 @@ EOS
915
923
 
916
924
 
917
925
  se = DelimScanner::new( desc )
918
- action = se.extractCodeblock() || ''
926
+ action = se.extractCodeblock || ''
919
927
 
920
928
  desc.sub!( Regexp::quote(action).to_re, '' )
921
929
  action = action[1..-2]
@@ -933,7 +941,7 @@ EOS
933
941
  if originaldesc =~ /\n.*\n/
934
942
  originaldesc = "Same as #{originalflag} "
935
943
  else
936
- originaldesc.chomp()
944
+ originaldesc.chomp
937
945
  originaldesc.gsub!(/\S/,'"')
938
946
  while originaldesc.gsub!(/"("+)"/,' \1 ')
939
947
  end
@@ -983,7 +991,7 @@ EOS
983
991
  def initialize(*opts)
984
992
 
985
993
  # HANDLE SHORT-CIRCUITS
986
- return if opts.length()==2 && (!opts[1] || opts[1] == '-SKIP')
994
+ return if opts.size==2 && (!opts[1] || opts[1] == '-SKIP')
987
995
 
988
996
  grammar, source = opts
989
997
 
@@ -1010,7 +1018,7 @@ EOS
1010
1018
  _all_repeatable = false
1011
1019
  _lastdesc = nil
1012
1020
  Getopt::Declare::nocase = false
1013
- Getopt::Declare::ScalarArg::_reset_stdtype()
1021
+ Getopt::Declare::ScalarArg::_reset_stdtype
1014
1022
 
1015
1023
 
1016
1024
  # CONSTRUCT GRAMMAR
@@ -1023,12 +1031,12 @@ EOS
1023
1031
  # TYPE DIRECTIVE:
1024
1032
  se = DelimScanner::new( i )
1025
1033
 
1026
- if i =~ /\A\s*\[pvtype:/
1034
+ if i =~ /\A\s*\[\s*pvtype:/
1027
1035
  _action = se.extractBracketed("[")
1028
1036
  if _action
1029
1037
  i.sub!( Regexp::quote( _action ).to_re, "" ) ### @GGA: added
1030
1038
  i.sub!(/\A[ \t]*\n/,"") ### @GGA: added
1031
- _action.sub!(/.*?\[pvtype:\s*/,"")
1039
+ _action.sub!(/.*?\[\s*pvtype:\s*/,"")
1032
1040
  _typedef(_action)
1033
1041
  next
1034
1042
  end # if
@@ -1050,12 +1058,12 @@ EOS
1050
1058
  "\n\n#{_action}\n\n\n"
1051
1059
  end
1052
1060
 
1053
- if _args.length() == 0
1061
+ if _args.length == 0
1054
1062
  raise "Error: unattached action in Getopt::Declare specification:\n#{_action}\n" +
1055
1063
  "\t(did you forget the tab after the preceding parameter specification?)\n"
1056
1064
  end
1057
1065
 
1058
- _args.last().actions.push( _action )
1066
+ _args.last.actions.push( _action )
1059
1067
  next
1060
1068
  elsif i =~ /\A(\s*[{].*)/
1061
1069
  raise "Error: incomplete action in Getopt::Declare specification:\n$1.....\n" +
@@ -1067,14 +1075,14 @@ EOS
1067
1075
  if i.sub!(re_argument,"")
1068
1076
  spec = "#$1".strip
1069
1077
  desc = "#$2"
1070
- _strict ||= desc =~ /\[strict\]/
1078
+ _strict ||= desc =~ /\[\s*strict\s*\]/
1071
1079
 
1072
1080
  while i.sub!(re_more_desc,"")
1073
1081
  desc += "#$1"
1074
1082
  end
1075
1083
 
1076
1084
  ditto = nil
1077
- if _lastdesc and desc.sub!(/\A\s*\[ditto\]/,_lastdesc)
1085
+ if _lastdesc and desc.sub!(/\A\s*\[\s*ditto\s*\]/,_lastdesc)
1078
1086
  ditto = arg
1079
1087
  else
1080
1088
  _lastdesc = desc
@@ -1101,13 +1109,13 @@ EOS
1101
1109
  end
1102
1110
 
1103
1111
  # OTHERWISE: DECORATION
1104
- i.sub!(/((?:(?!\[pvtype:).)*)(\n|(?=\[pvtype:))/,"")
1112
+ i.sub!(/((?:(?!\[\s*pvtype:).)*)(\n|(?=\[\s*pvtype:))/,"")
1105
1113
  decorator = "#$1"
1106
- _strict ||= decorator =~ /\[strict\]/
1114
+ _strict ||= decorator =~ /\[\s*strict\s*\]/
1107
1115
  _infer(decorator, nil, _mutex)
1108
1116
 
1109
- _all_repeatable = true if decorator =~ /\[repeatable\]/
1110
- @@debug = true if decorator =~ /\[debug\]/
1117
+ _all_repeatable = true if decorator =~ /\[\s*repeatable\s*\]/
1118
+ @@debug = true if decorator =~ /\[\s*debug\s*\]/
1111
1119
 
1112
1120
  end # while i.length
1113
1121
 
@@ -1126,18 +1134,15 @@ EOS
1126
1134
  end
1127
1135
 
1128
1136
  # Sort flags based on criteria described in docs
1129
- _args = _args.sort() { |a,b|
1130
- ( b.flag.length() <=> a.flag.length() ) or
1131
- ( b.flag == a.flag and ( b.args.length() <=> a.args.length() ) ) or
1132
- ( a.id <=> b.id )
1133
- }
1137
+ _args = _args.sort_by { |a| [a.flag.size, a.flag, a.args.size, a.id] }
1138
+
1134
1139
 
1135
1140
  # Handle clump
1136
- clump = (@usage =~ /\[cluster:\s*none\s*\]/i) ? 0 :
1137
- (@usage =~ /\[cluster:\s*singles?\s*\]/i) ? 1 :
1138
- (@usage =~ /\[cluster:\s*flags?\s*\]/i) ? 2 :
1139
- (@usage =~ /\[cluster:\s*any\s*\]/i) ? 3 :
1140
- (@usage =~ /\[cluster:(.*)\s*\]/i) ? "r" : 3
1141
+ clump = (@usage =~ /\[\s*cluster:\s*none\s*\]/i) ? 0 :
1142
+ (@usage =~ /\[\s*cluster:\s*singles?\s*\]/i) ? 1 :
1143
+ (@usage =~ /\[\s*cluster:\s*flags?\s*\]/i) ? 2 :
1144
+ (@usage =~ /\[\s*cluster:\s*any\s*\]/i) ? 3 :
1145
+ (@usage =~ /\[\s*cluster:(.*)\s*\]/i) ? "r" : 3
1141
1146
  raise "Error: unknown clustering mode: [cluster:#$1]\n" if clump == "r"
1142
1147
 
1143
1148
  # CONSTRUCT OBJECT ITSELF
@@ -1149,7 +1154,7 @@ EOS
1149
1154
  @strict = _strict
1150
1155
  @clump = clump
1151
1156
  @source = ''
1152
- @tight = @usage =~ /\[tight\]/i
1157
+ @tight = @usage =~ /\[\s*tight\s*\]/i
1153
1158
  @caller = caller()
1154
1159
 
1155
1160
  # VESTIGAL DEBUGGING CODE
@@ -1318,7 +1323,7 @@ EOS
1318
1323
  desc += "#$1".expand_tabs!
1319
1324
  end
1320
1325
 
1321
- next if desc =~ /\[undocumented\]/i
1326
+ next if desc =~ /\[\s*undocumented\s*\]/i
1322
1327
 
1323
1328
  uoff = 0
1324
1329
  spec.gsub!(/(<[a-zA-Z]\w*):([^>]+)>/e) { |i|
@@ -1404,7 +1409,7 @@ EOS
1404
1409
 
1405
1410
 
1406
1411
  # Return list of used parameters (after parsing)
1407
- def used()
1412
+ def used
1408
1413
  used = @cache.each_key { |i| [ i, @cache[i] ] }
1409
1414
  return (used.map { |i| flatten(i) } ).join(' ')
1410
1415
  end
@@ -1481,7 +1486,7 @@ begin
1481
1486
  _pos = _nextpos if _args
1482
1487
 
1483
1488
  usage(0) if _args && gindex(_args,/\G(% + @helppat + %q%)(\s|\0|\Z)/,_pos)
1484
- version(0) if _args && _args =~ /(% + @verspat + %q%)(\s|\0|\Z)/
1489
+ version(0) if _args && _args =~ /\G(% + @verspat + %q%)(\s|\0|\Z)/
1485
1490
  %
1486
1491
 
1487
1492
  for arg in @args
@@ -1498,7 +1503,7 @@ begin
1498
1503
 
1499
1504
  _pos = _nextpos
1500
1505
 
1501
- _args && _pos = gindex( _args, /\G(?:\s|\0)*(\S+)/, _pos ) or throw(:alldone)
1506
+ _args && _pos = gindex( _args, /\G[\s|\0]*(\S+)/, _pos ) or throw(:alldone)
1502
1507
 
1503
1508
  if @_errormsg
1504
1509
  $stderr.puts( "Error#{source}: #{@_errormsg}\n" )
metadata CHANGED
@@ -3,7 +3,7 @@ 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.20"
6
+ version: "1.21"
7
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:
@@ -58,6 +58,8 @@ rdoc_options: []
58
58
  extra_rdoc_files:
59
59
  - Declare.rdoc
60
60
  - HISTORY.txt
61
+ - lib/Getopt/Declare.rb
62
+ - lib/Getopt/DelimScanner.rb
61
63
  executables: []
62
64
 
63
65
  extensions: []