getopt 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +7 -0
- data/README +5 -2
- data/lib/getopt/long.rb +7 -5
- data/test/tc_getopt_long.rb +15 -1
- metadata +5 -3
data/CHANGES
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 5-Jul-2006 - 1.3.5
|
2
|
+
* Fixed a bug where multiple long switches with the same first character
|
3
|
+
could cause invalid results. Thanks go to Michael Campbell for the spot.
|
4
|
+
* Added documentation to the README file that explains what happens if you
|
5
|
+
specify multiple long switches with the same first character and no short
|
6
|
+
switch alias.
|
7
|
+
|
1
8
|
== 7-Mar-2006 - 1.3.4
|
2
9
|
* Fixed Getopt::Long so that it can handle embedded hyphens in the long
|
3
10
|
form, e.g. --foo-bar. Thanks go to Mark Meves for the spot.
|
data/README
CHANGED
@@ -76,11 +76,14 @@ Long.getopts(switches)
|
|
76
76
|
|
77
77
|
The array should be in the form:
|
78
78
|
|
79
|
+
# long form, short form (alias), option type
|
79
80
|
["--long", "-l", Getopt::OPTION]
|
80
81
|
|
81
|
-
Note that only the long form is required. If the short
|
82
|
+
Note that only the long form is required. If the short form is not
|
82
83
|
specified, it will automatically be set to the first letter of the long
|
83
|
-
switch.
|
84
|
+
switch. If multiple long switches with the same first character are
|
85
|
+
listed without short switches, only the first long switch gets the short
|
86
|
+
switch alias.
|
84
87
|
|
85
88
|
If the argument type is not specified, the default is BOOLEAN.
|
86
89
|
|
data/lib/getopt/long.rb
CHANGED
@@ -5,11 +5,12 @@ module Getopt
|
|
5
5
|
OPTIONAL = 2
|
6
6
|
INCREMENT = 3
|
7
7
|
NEGATABLE = 4
|
8
|
+
NUMERIC = 5
|
8
9
|
|
9
10
|
class LongError < StandardError; end
|
10
11
|
|
11
12
|
class Long
|
12
|
-
VERSION =
|
13
|
+
VERSION = '1.3.5'
|
13
14
|
|
14
15
|
# Takes an array of switches. Each array consists of three elements.
|
15
16
|
def self.getopts(*switches)
|
@@ -33,8 +34,6 @@ module Getopt
|
|
33
34
|
valid.push(switch[0]) # Set valid long switches
|
34
35
|
|
35
36
|
# Set type for long switch, default to BOOLEAN.
|
36
|
-
# Create synonym hash. Default to first char of long switch for
|
37
|
-
# short switch, e.g. "--verbose" creates a "-v" synonym.
|
38
37
|
if switch[1].kind_of?(Fixnum)
|
39
38
|
switch[2] = switch[1]
|
40
39
|
types[switch[0]] = switch[2]
|
@@ -45,8 +44,11 @@ module Getopt
|
|
45
44
|
switch[1] ||= switch[0][1..2]
|
46
45
|
end
|
47
46
|
|
48
|
-
|
49
|
-
|
47
|
+
# Create synonym hash. Default to first char of long switch for
|
48
|
+
# short switch, e.g. "--verbose" creates a "-v" synonym. The same
|
49
|
+
# synonym can only be used once - first one wins.
|
50
|
+
syns[switch[0]] = switch[1] unless syns[switch[1]]
|
51
|
+
syns[switch[1]] = switch[0] unless syns[switch[1]]
|
50
52
|
|
51
53
|
switch[1].each{ |char|
|
52
54
|
types[char] = switch[2] # Set type for short switch
|
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(
|
24
|
+
assert_equal('1.3.5', Long::VERSION)
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_constants
|
@@ -249,6 +249,20 @@ class TC_Getopt_Long < Test::Unit::TestCase
|
|
249
249
|
)
|
250
250
|
}
|
251
251
|
end
|
252
|
+
|
253
|
+
def test_multiple_similar_long_switches_with_no_short_switches
|
254
|
+
ARGV.push('--to','1','--too','2','--tooo','3')
|
255
|
+
assert_nothing_raised{
|
256
|
+
@opts = Long.getopts(
|
257
|
+
["--to", REQUIRED],
|
258
|
+
["--too", REQUIRED],
|
259
|
+
["--tooo", REQUIRED]
|
260
|
+
)
|
261
|
+
}
|
262
|
+
assert_equal('1', @opts['to'])
|
263
|
+
assert_equal('2', @opts['too'])
|
264
|
+
assert_equal('3', @opts['tooo'])
|
265
|
+
end
|
252
266
|
|
253
267
|
def teardown
|
254
268
|
@opts = nil
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: getopt
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.3.
|
7
|
-
date: 2006-
|
6
|
+
version: 1.3.5
|
7
|
+
date: 2006-07-05 00:00:00 -06:00
|
8
8
|
summary: Getopt::Std and Getopt::Long option parsers for Ruby
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -25,6 +25,7 @@ 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
|
- Daniel J. Berger
|
30
31
|
files:
|
@@ -43,6 +44,7 @@ rdoc_options: []
|
|
43
44
|
extra_rdoc_files:
|
44
45
|
- README
|
45
46
|
- CHANGES
|
47
|
+
- MANIFEST
|
46
48
|
executables: []
|
47
49
|
|
48
50
|
extensions: []
|