getopt 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +4 -0
- data/lib/getopt/long.rb +11 -6
- data/lib/getopt/std.rb +1 -1
- data/test/tc_getopt_long.rb +15 -1
- metadata +2 -2
data/CHANGES
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== 22-Feb-2006 - 1.3.3
|
2
|
+
* Bug fix for the two argument form of Getopt::Long.getopts.
|
3
|
+
* Corresponding test suite additions.
|
4
|
+
|
1
5
|
== 13-Feb-2006 - 1.3.2
|
2
6
|
* Improved error message if an option is passed without a preceding switch.
|
3
7
|
* Minor documentation fixes and clarifications.
|
data/lib/getopt/long.rb
CHANGED
@@ -9,7 +9,7 @@ module Getopt
|
|
9
9
|
class LongError < StandardError; end
|
10
10
|
|
11
11
|
class Long
|
12
|
-
VERSION = "1.3.
|
12
|
+
VERSION = "1.3.3"
|
13
13
|
|
14
14
|
# Takes an array of switches. Each array consists of three elements.
|
15
15
|
def self.getopts(*switches)
|
@@ -32,13 +32,18 @@ module Getopt
|
|
32
32
|
switches.each{ |switch|
|
33
33
|
valid.push(switch[0]) # Set valid long switches
|
34
34
|
|
35
|
-
# Set type for long switch, default to BOOLEAN
|
36
|
-
switch[2] ||= BOOLEAN
|
37
|
-
types[switch[0]] = switch[2]
|
38
|
-
|
35
|
+
# Set type for long switch, default to BOOLEAN.
|
39
36
|
# Create synonym hash. Default to first char of long switch for
|
40
37
|
# short switch, e.g. "--verbose" creates a "-v" synonym.
|
41
|
-
|
38
|
+
if switch[1].kind_of?(Fixnum)
|
39
|
+
switch[2] = switch[1]
|
40
|
+
types[switch[0]] = switch[2]
|
41
|
+
switch[1] = switch[0][1..2]
|
42
|
+
else
|
43
|
+
switch[2] ||= BOOLEAN
|
44
|
+
types[switch[0]] = switch[2]
|
45
|
+
switch[1] ||= switch[0][1..2]
|
46
|
+
end
|
42
47
|
|
43
48
|
syns[switch[0]] = switch[1]
|
44
49
|
syns[switch[1]] = switch[0]
|
data/lib/getopt/std.rb
CHANGED
data/test/tc_getopt_long.rb
CHANGED
@@ -21,7 +21,7 @@ class TC_Getopt_Long < Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_version
|
24
|
-
assert_equal("1.3.
|
24
|
+
assert_equal("1.3.3", Long::VERSION)
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_constants
|
@@ -101,6 +101,20 @@ class TC_Getopt_Long < Test::Unit::TestCase
|
|
101
101
|
assert_equal(true, @opts.has_key?("f"))
|
102
102
|
end
|
103
103
|
|
104
|
+
def test_short_switch_synonyms_with_explicit_types
|
105
|
+
ARGV.push("--verbose", "--test", "hello", "--foo")
|
106
|
+
assert_nothing_raised{
|
107
|
+
@opts = Long.getopts(
|
108
|
+
["--verbose", BOOLEAN],
|
109
|
+
["--test", REQUIRED],
|
110
|
+
["--foo", BOOLEAN]
|
111
|
+
)
|
112
|
+
}
|
113
|
+
assert(@opts.has_key?("v"))
|
114
|
+
assert(@opts.has_key?("t"))
|
115
|
+
assert(@opts.has_key?("f"))
|
116
|
+
end
|
117
|
+
|
104
118
|
def test_switches_with_required_arguments
|
105
119
|
ARGV.push("--foo","1","--bar","hello")
|
106
120
|
assert_nothing_raised{
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: getopt
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.3.
|
7
|
-
date: 2006-02-
|
6
|
+
version: 1.3.3
|
7
|
+
date: 2006-02-22 00:00:00 -07:00
|
8
8
|
summary: Getopt::Std for Ruby
|
9
9
|
require_paths:
|
10
10
|
- lib
|