getopt 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,10 @@
1
+ == 7-Mar-2006 - 1.3.4
2
+ * Fixed Getopt::Long so that it can handle embedded hyphens in the long
3
+ form, e.g. --foo-bar. Thanks go to Mark Meves for the spot.
4
+ * Corresponding test suite additions.
5
+ * Added example to the 'example_long.rb' file that uses long form with
6
+ embedded hyphens.
7
+
1
8
  == 22-Feb-2006 - 1.3.3
2
9
  * Bug fix for the two argument form of Getopt::Long.getopts.
3
10
  * Corresponding test suite additions.
data/README CHANGED
@@ -70,8 +70,9 @@ Std.getopts(switches)
70
70
 
71
71
  Long.getopts(switches)
72
72
  Takes an array of switches beginning with "--" followed by one or more
73
- characters, or "-w" followed by a single character. The type of argument,
74
- if any, can be specified as BOOLEAN, OPTIONAL, REQUIRED or INCREMENT.
73
+ alphanumeric or hyphen characters, or "-" followed by a single character.
74
+ The type of argument, if any, can be specified as BOOLEAN, OPTIONAL,
75
+ REQUIRED or INCREMENT.
75
76
 
76
77
  The array should be in the form:
77
78
 
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.3"
12
+ VERSION = "1.3.4"
13
13
 
14
14
  # Takes an array of switches. Each array consists of three elements.
15
15
  def self.getopts(*switches)
@@ -54,9 +54,9 @@ module Getopt
54
54
  }
55
55
  }
56
56
 
57
- re_long = /^(--\w+)$/
57
+ re_long = /^(--\w+[-\w+]*)?$/
58
58
  re_short = /^(-\w)$/
59
- re_long_eq = /^(--\w+?)=(.*?)$|^(-\w?)=(.*?)$/
59
+ re_long_eq = /^(--\w+[-\w+]*)?=(.*?)$|(-\w?)=(.*?)$/
60
60
  re_short_sq = /^(-\w)(\S+?)$/
61
61
 
62
62
  ARGV.each_with_index{ |opt, index|
@@ -196,7 +196,11 @@ module Getopt
196
196
 
197
197
  # Get rid of leading "--" and "-" to make it easier to reference
198
198
  hash.each{ |key, value|
199
- nkey = key.tr("-","")
199
+ if key[0,2] == '--'
200
+ nkey = key.sub('--', '')
201
+ else
202
+ nkey = key.sub('-', '')
203
+ end
200
204
  hash.delete(key)
201
205
  hash[nkey] = value
202
206
  }
data/lib/getopt/std.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Getopt
2
2
  class StdError < StandardError; end
3
3
  class Std
4
- VERSION = "1.3.3"
4
+ VERSION = "1.3.4"
5
5
 
6
6
  # Processes single character command line options with option
7
7
  # clustering. This information is parsed from ARGV and returned
@@ -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.3", Long::VERSION)
24
+ assert_equal("1.3.4", Long::VERSION)
25
25
  end
26
26
 
27
27
  def test_constants
@@ -63,6 +63,34 @@ class TC_Getopt_Long < Test::Unit::TestCase
63
63
  assert_equal("world", @opts["bar"])
64
64
  assert_equal("world", @opts["b"])
65
65
  end
66
+
67
+ def test_getopts_long_embedded_hyphens
68
+ ARGV.push('--foo-bar', 'hello', '--test1-test2-test3', 'world')
69
+ assert_nothing_raised{
70
+ @opts = Long.getopts(
71
+ ['--foo-bar', '-f', REQUIRED],
72
+ ['--test1-test2-test3', '-t', REQUIRED]
73
+ )
74
+ }
75
+ assert_equal('hello', @opts['foo-bar'])
76
+ assert_equal('hello', @opts['f'])
77
+ assert_equal('world', @opts['test1-test2-test3'])
78
+ assert_equal('world', @opts['t'])
79
+ end
80
+
81
+ def test_getopts_long_embedded_hyphens_using_equals_sign
82
+ ARGV.push('--foo-bar=hello', '--test1-test2-test3=world')
83
+ assert_nothing_raised{
84
+ @opts = Long.getopts(
85
+ ['--foo-bar', '-f', REQUIRED],
86
+ ['--test1-test2-test3', '-t', REQUIRED]
87
+ )
88
+ }
89
+ assert_equal('hello', @opts['foo-bar'])
90
+ assert_equal('hello', @opts['f'])
91
+ assert_equal('world', @opts['test1-test2-test3'])
92
+ assert_equal('world', @opts['t'])
93
+ end
66
94
 
67
95
  def test_getopts_short_switch_squished
68
96
  ARGV.push("-f", "hello", "-bworld")
@@ -18,7 +18,7 @@ include Getopt
18
18
  class TC_Getopt_Std < Test::Unit::TestCase
19
19
 
20
20
  def test_version
21
- assert_equal("1.3.2", Std::VERSION)
21
+ assert_equal("1.3.4", Std::VERSION)
22
22
  end
23
23
 
24
24
  def test_getopts_basic
metadata CHANGED
@@ -3,15 +3,15 @@ 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.3
7
- date: 2006-02-22 00:00:00 -07:00
8
- summary: Getopt::Std for Ruby
6
+ version: 1.3.4
7
+ date: 2006-03-07 00:00:00 -07:00
8
+ summary: Getopt::Std and Getopt::Long option parsers for Ruby
9
9
  require_paths:
10
10
  - lib
11
11
  email: djberg96@gmail.com
12
12
  homepage: http://www.rubyforge.org/projects/shards
13
13
  rubyforge_project:
14
- description: Getopt::Std for Ruby
14
+ description: Getopt::Std and Getopt::Long option parsers for Ruby
15
15
  autorequire:
16
16
  default_executable:
17
17
  bindir: bin