getopt-declare 1.26 → 1.27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/HISTORY.txt +5 -0
  2. data/lib/Getopt/Declare.rb +17 -13
  3. metadata +2 -2
data/HISTORY.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.27
2
+ * Fixed a bug with the sorting of arguments, which could sometimes
3
+ lead to strange parsing.
4
+ * Made required argument parsing more strict.
5
+
1
6
  == 1.26
2
7
  * Stripping of usage was making help lines that were not
3
8
  parameters look bad. Fixed.
@@ -4,7 +4,7 @@
4
4
  # Ruby port of Perl's Getopt::Declare, version 1.21,
5
5
  # released May 21, 1999.
6
6
  #
7
- # $Release Version: 1.26 $
7
+ # $Release Version: 1.27 $
8
8
  # $Date: 2007/01/15 10:53:09 $
9
9
  # by Gonzalo Garramu�o
10
10
  #
@@ -70,7 +70,7 @@ module Getopt
70
70
  # Main Class
71
71
  class Declare
72
72
 
73
- VERSION = '1.26'
73
+ VERSION = '1.27'
74
74
 
75
75
  # For debugging, use [debug] and it will output the ruby code as .CODE.rb
76
76
  @@debug = false
@@ -616,7 +616,6 @@ EOS
616
616
  end
617
617
  end # while
618
618
 
619
-
620
619
  @@helpcmdH.delete(@flag) if @@helpcmdH.key?(@flag)
621
620
  @@versioncmdH.delete(@flag) if @@versioncmdH.key?(@flag)
622
621
  end # initialize
@@ -635,12 +634,15 @@ EOS
635
634
  i = 0
636
635
  nocasei = ((Getopt::Declare::nocase || @nocase) ? 'i' : '')
637
636
 
638
- code << " catch(:paramout) do\n"
639
- code += !@repeatable? " while !_FOUND_['" + self.foundid + "']" :
640
- " while true"
637
+ code << " catch(:paramout) do\n while "
638
+ if @requires
639
+ code << requires << ' and '
640
+ end
641
+ code += !@repeatable? "!_FOUND_['" + self.foundid + "']" : "true"
642
+
641
643
  if (flag && (clump==1 && flag !~ /\A[^a-z0-9]+[a-z0-9]\Z/i ||
642
644
  (clump<3 && @args.size > 0 )))
643
- code << ' && !_lastprefix'
645
+ code << ' and !_lastprefix'
644
646
  end
645
647
 
646
648
  code << '
@@ -1130,6 +1132,7 @@ EOS
1130
1132
  end # while i.length
1131
1133
 
1132
1134
 
1135
+
1133
1136
  _lastactions = nil
1134
1137
  for i in _args
1135
1138
  if _lastactions && i.ditto && i.actions.size == 0
@@ -1145,13 +1148,14 @@ EOS
1145
1148
 
1146
1149
  # Sort flags based on criteria described in docs
1147
1150
  # Sadly, this cannot be reduced to sort_by
1148
- _args = _args.sort() { |a,b|
1149
- ( b.flag.length() <=> a.flag.length() ) or
1150
- ( b.flag == a.flag and ( b.args.length() <=> a.args.length() ) ) or
1151
- ( a.id <=> b.id )
1151
+ _args = _args.sort() { |a,b|
1152
+ cond1 = ( b.flag.size <=> a.flag.size )
1153
+ cond2 = ( b.flag == a.flag and ( b.args.size <=> a.args.size ) )
1154
+ cond3 = ( a.id <=> b.id )
1155
+ cond1 = nil if cond1 == 0
1156
+ cond2 = nil if cond2 == 0
1157
+ cond1 or cond2 or cond3
1152
1158
  }
1153
- # _args = _args.sort_by { |a| [a.flag.size, a.flag, a.args.size, a.id] }
1154
-
1155
1159
 
1156
1160
  # Handle clump
1157
1161
  clump = (@usage =~ /\[\s*cluster:\s*none\s*\]/i) ? 0 :
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.1
3
3
  specification_version: 1
4
4
  name: getopt-declare
5
5
  version: !ruby/object:Gem::Version
6
- version: "1.26"
7
- date: 2007-06-17 00:00:00 -03:00
6
+ version: "1.27"
7
+ date: 2007-06-23 00:00:00 -03:00
8
8
  summary: Getopt-Declare is a command-line argument parser.
9
9
  require_paths:
10
10
  - lib