getopt 1.3.8 → 1.3.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,4 +1,12 @@
1
- == 6-Jan-2008 - 1.3.8
1
+ == 1.3.9 - 29-Jul-2009
2
+ * Now compatible with Ruby 1.9.x.
3
+ * Gemspec updates, including a license change to Artistic 2.0.
4
+ * Added individual rake tasks for testing Getopt::Long and Getopt::Std.
5
+ * Changed the 'release - date' format of this file.
6
+ * The test-unit library was switched from a standard dependency to a
7
+ development dependency.
8
+
9
+ == 1.3.8 - 6-Jan-2008
2
10
  * Fixed RF bug #23477 - Getopt::Std inadvertently raises an error if you
3
11
  pass a letter (without a hyphen) as an argument to a switch that matches
4
12
  that letter, e.g. "-a a" should be legal. Thanks go to an anonymous user
@@ -6,7 +14,7 @@
6
14
  * Added tests for RF bug #23477.
7
15
  * Added Test::Unit 2.x as a prerequisite.
8
16
 
9
- == 27-Jul-2008 - 1.3.7
17
+ == 1.3.7 - 27-Jul-2008
10
18
  * Fixed a potential infinite hash recursion bug in ARGV processing. This
11
19
  was smoked out as the result of the alternate hash implementations in
12
20
  JRuby and Ruby 1.9.
@@ -14,56 +22,56 @@
14
22
  * Removed the ts_all.rb file, and renamed the other test files. The Rakefile
15
23
  test task was updated accordingly.
16
24
 
17
- == 8-Aug-2007 - 1.3.6
25
+ == 1.3.6 - 8-Aug-2007
18
26
  * The Getopt::StdError class is now Getopt::Std::Error.
19
27
  * The Getopt::LongError class is now Getopt::Long::Error.
20
28
  * Added some inline rdoc documentation to the source code.
21
29
  * Added a Rakefile with tasks for installation and testing.
22
30
  * Removed the install.rb file - use the 'rake install' task instead.
23
31
 
24
- == 5-Jul-2006 - 1.3.5
32
+ == 1.3.5 - 5-Jul-2006
25
33
  * Fixed a bug where multiple long switches with the same first character
26
34
  could cause invalid results. Thanks go to Michael Campbell for the spot.
27
35
  * Added documentation to the README file that explains what happens if you
28
36
  specify multiple long switches with the same first character and no short
29
37
  switch alias.
30
38
 
31
- == 7-Mar-2006 - 1.3.4
39
+ == 1.3.4 - 7-Mar-2006
32
40
  * Fixed Getopt::Long so that it can handle embedded hyphens in the long
33
41
  form, e.g. --foo-bar. Thanks go to Mark Meves for the spot.
34
42
  * Corresponding test suite additions.
35
43
  * Added example to the 'example_long.rb' file that uses long form with
36
44
  embedded hyphens.
37
45
 
38
- == 22-Feb-2006 - 1.3.3
46
+ == 1.3.3 - 22-Feb-2006
39
47
  * Bug fix for the two argument form of Getopt::Long.getopts.
40
48
  * Corresponding test suite additions.
41
49
 
42
- == 13-Feb-2006 - 1.3.2
50
+ == 1.3.2 - 13-Feb-2006
43
51
  * Improved error message if an option is passed without a preceding switch.
44
52
  * Minor documentation fixes and clarifications.
45
53
 
46
- == 18-Nov-2005 - 1.3.1
54
+ == 1.3.1 - 18-Nov-2005
47
55
  * Added support for compressed switches with getopt/long.
48
56
  * More tests.
49
57
  * Fixed a bug in the gemspec.
50
58
 
51
- == 4-Nov-2005 - 1.3.0
52
- * Added the Getopt::Long class (long.rb). This is a complete revamp of the
59
+ == 1.3.0 - 4-Nov-2005
60
+ * Added the Getopt::Long class (long.rb). This is a complete revamp of the
53
61
  old getoptlong package, with ideas tossed in from Perl's Getopt::Long
54
- package. See the README and example script for more detail.
62
+ package. See the README and example script for more detail.
55
63
  * Added an example, and renamed the "test_std.rb" example to "example_std.rb".
56
64
  * Added lots of documentation to the README file.
57
65
  * Updated the MANIFEST, test suite, etc.
58
66
 
59
- == 24-Oct-2005 - 1.2.0
67
+ == 1.2.0 - 24-Oct-2005
60
68
  * Altered the way multiple occurrences of the same switch are handled, for
61
69
  those switches that accept arguments.
62
70
 
63
- == 7-Oct-2005 - 1.1.0
71
+ == 1.1.0 - 7-Oct-2005
64
72
  * Changed parser, added a bit stricter enforcement
65
73
  * Now handles squished arguments properly, e.g. "-ID" as well as "-I -D"
66
74
  * Some test suite changes
67
75
 
68
- == 5-Oct-2005 - 1.0.0
76
+ == 1.0.0 - 5-Oct-2005
69
77
  * Initial commit
data/README CHANGED
@@ -173,10 +173,10 @@ INCREMENT
173
173
  warranties of merchantability and fitness for a particular purpose.
174
174
 
175
175
  == License
176
- Ruby's
176
+ Artistic 2.0
177
177
 
178
178
  == Copyright
179
- (C) 2005-2007, Daniel J. Berger
179
+ (C) 2005-2009, Daniel J. Berger
180
180
  All Rights Reserved
181
181
 
182
182
  == Author
@@ -17,7 +17,7 @@ class TC_Getopt_Long < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  def test_version
20
- assert_equal('1.3.7', Long::VERSION)
20
+ assert_equal('1.3.9', Long::VERSION)
21
21
  end
22
22
 
23
23
  def test_constants
@@ -14,7 +14,7 @@ include Getopt
14
14
  class TC_Getopt_Std < Test::Unit::TestCase
15
15
 
16
16
  def test_version
17
- assert_equal('1.3.8', Std::VERSION)
17
+ assert_equal('1.3.9', Std::VERSION)
18
18
  end
19
19
 
20
20
  def test_getopts_basic
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getopt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.8
4
+ version: 1.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,20 +9,20 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-06 00:00:00 -07:00
12
+ date: 2009-07-29 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: test-unit
17
- type: :runtime
17
+ type: :development
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 2.0.2
23
+ version: 2.0.3
24
24
  version:
25
- description: Getopt::Std and Getopt::Long option parsers for Ruby
25
+ description: " The getopt library provides two different command line option parsers.\n They are meant as easier and more convenient replacements for the\n command line parsers that ship as part of the Ruby standard library.\n Please see the README for additional comments.\n"
26
26
  email: djberg96@gmail.com
27
27
  executables: []
28
28
 
@@ -33,18 +33,17 @@ extra_rdoc_files:
33
33
  - CHANGES
34
34
  - MANIFEST
35
35
  files:
36
- - lib/getopt/long.rb
37
- - lib/getopt/std.rb
38
- - CHANGES
39
- - MANIFEST
40
- - Rakefile
41
- - README
42
- - test/test_getopt_long.rb
43
- - test/test_getopt_std.rb
44
36
  - examples/example_long.rb
45
37
  - examples/example_std.rb
38
+ - test/test_getopt_long.rb
39
+ - test/test_getopt_std.rb
40
+ - README
41
+ - CHANGES
42
+ - MANIFEST
46
43
  has_rdoc: true
47
44
  homepage: http://www.rubyforge.org/projects/shards
45
+ licenses:
46
+ - Artistic 2.0
48
47
  post_install_message:
49
48
  rdoc_options: []
50
49
 
@@ -65,9 +64,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
64
  requirements: []
66
65
 
67
66
  rubyforge_project: shards
68
- rubygems_version: 1.2.0
67
+ rubygems_version: 1.3.5
69
68
  signing_key:
70
- specification_version: 2
69
+ specification_version: 3
71
70
  summary: Getopt::Std and Getopt::Long option parsers for Ruby
72
71
  test_files:
73
72
  - test/test_getopt_long.rb
data/Rakefile DELETED
@@ -1,22 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
-
4
- desc "Install the getopt package (non-gem)"
5
- task :install do
6
- dest = File.join(Config::CONFIG['sitelibdir'], 'getopt')
7
- Dir.mkdir(dest) unless File.exists? dest
8
- cp 'lib/getopt/std.rb', dest, :verbose => true
9
- cp 'lib/getopt/long.rb', dest, :verbose => true
10
- end
11
-
12
- desc "Install the getopt package as a gem"
13
- task :install_gem do
14
- ruby 'getopt.gemspec'
15
- file = Dir["*.gem"].first
16
- sh "gem install #{file}"
17
- end
18
-
19
- Rake::TestTask.new do |t|
20
- t.warning = true
21
- t.verbose = true
22
- end
@@ -1,234 +0,0 @@
1
- module Getopt
2
-
3
- REQUIRED = 0
4
- BOOLEAN = 1
5
- OPTIONAL = 2
6
- INCREMENT = 3
7
- NEGATABLE = 4
8
- NUMERIC = 5
9
-
10
- class Long
11
- class Error < StandardError; end
12
-
13
- VERSION = '1.3.7'
14
-
15
- # Takes an array of switches. Each array consists of up to three
16
- # elements that indicate the name and type of switch. Returns a hash
17
- # containing each switch name, minus the '-', as a key. The value
18
- # for each key depends on the type of switch and/or the value provided
19
- # by the user.
20
- #
21
- # The long switch _must_ be provided. The short switch defaults to the
22
- # first letter of the short switch. The default type is BOOLEAN.
23
- #
24
- # Example:
25
- #
26
- # opts = Getopt::Long.getopts(
27
- # ["--debug"],
28
- # ["--verbose", "-v"],
29
- # ["--level", "-l", NUMERIC]
30
- # )
31
- #
32
- # See the README file for more information.
33
- #
34
- def self.getopts(*switches)
35
- if switches.empty?
36
- raise ArgumentError, "no switches provided"
37
- end
38
-
39
- hash = {} # Hash returned to user
40
- valid = [] # Tracks valid switches
41
- types = {} # Tracks argument types
42
- syns = {} # Tracks long and short arguments, or multiple shorts
43
-
44
- # If a string is passed, split it and convert it to an array of arrays
45
- if switches.first.kind_of?(String)
46
- switches = switches.join.split
47
- switches.map!{ |switch| switch = [switch] }
48
- end
49
-
50
- # Set our list of valid switches, and proper types for each switch
51
- switches.each{ |switch|
52
- valid.push(switch[0]) # Set valid long switches
53
-
54
- # Set type for long switch, default to BOOLEAN.
55
- if switch[1].kind_of?(Fixnum)
56
- switch[2] = switch[1]
57
- types[switch[0]] = switch[2]
58
- switch[1] = switch[0][1..2]
59
- else
60
- switch[2] ||= BOOLEAN
61
- types[switch[0]] = switch[2]
62
- switch[1] ||= switch[0][1..2]
63
- end
64
-
65
- # Create synonym hash. Default to first char of long switch for
66
- # short switch, e.g. "--verbose" creates a "-v" synonym. The same
67
- # synonym can only be used once - first one wins.
68
- syns[switch[0]] = switch[1] unless syns[switch[1]]
69
- syns[switch[1]] = switch[0] unless syns[switch[1]]
70
-
71
- switch[1].each{ |char|
72
- types[char] = switch[2] # Set type for short switch
73
- valid.push(char) # Set valid short switches
74
- }
75
- }
76
-
77
- re_long = /^(--\w+[-\w+]*)?$/
78
- re_short = /^(-\w)$/
79
- re_long_eq = /^(--\w+[-\w+]*)?=(.*?)$|(-\w?)=(.*?)$/
80
- re_short_sq = /^(-\w)(\S+?)$/
81
-
82
- ARGV.each_with_index{ |opt, index|
83
-
84
- # Allow either -x -v or -xv style for single char args
85
- if re_short_sq.match(opt)
86
- chars = opt.split("")[1..-1].map{ |s| s = "-#{s}" }
87
-
88
- chars.each_with_index{ |char, i|
89
- unless valid.include?(char)
90
- raise Error, "invalid switch '#{char}'"
91
- end
92
-
93
- # Grab the next arg if the switch takes a required arg
94
- if types[char] == REQUIRED
95
- # Deal with a argument squished up against switch
96
- if chars[i+1]
97
- arg = chars[i+1..-1].join.tr("-","")
98
- ARGV.push(char, arg)
99
- break
100
- else
101
- arg = ARGV.delete_at(index+1)
102
- if arg.nil? || valid.include?(arg) # Minor cheat here
103
- err = "no value provided for required argument '#{char}'"
104
- raise Error, err
105
- end
106
- ARGV.push(char, arg)
107
- end
108
- elsif types[char] == OPTIONAL
109
- if chars[i+1] && !valid.include?(chars[i+1])
110
- arg = chars[i+1..-1].join.tr("-","")
111
- ARGV.push(char, arg)
112
- break
113
- elsif
114
- if ARGV[index+1] && !valid.include?(ARGV[index+1])
115
- arg = ARGV.delete_at(index+1)
116
- ARGV.push(char, arg)
117
- end
118
- else
119
- ARGV.push(char)
120
- end
121
- else
122
- ARGV.push(char)
123
- end
124
- }
125
- next
126
- end
127
-
128
- if match = re_long.match(opt) || match = re_short.match(opt)
129
- switch = match.captures.first
130
- end
131
-
132
- if match = re_long_eq.match(opt)
133
- switch, value = match.captures.compact
134
- ARGV.push(switch, value)
135
- next
136
- end
137
-
138
- # Make sure that all the switches are valid. If 'switch' isn't
139
- # defined at this point, it means an option was passed without
140
- # a preceding switch, e.g. --option foo bar.
141
- unless valid.include?(switch)
142
- switch ||= opt
143
- raise Error, "invalid switch '#{switch}'"
144
- end
145
-
146
- # Required arguments
147
- if types[switch] == REQUIRED
148
- nextval = ARGV[index+1]
149
-
150
- # Make sure there's a value for mandatory arguments
151
- if nextval.nil?
152
- err = "no value provided for required argument '#{switch}'"
153
- raise Error, err
154
- end
155
-
156
- # If there is a value, make sure it's not another switch
157
- if valid.include?(nextval)
158
- err = "cannot pass switch '#{nextval}' as an argument"
159
- raise Error, err
160
- end
161
-
162
- # If the same option appears more than once, put the values
163
- # in array.
164
- if hash[switch]
165
- hash[switch] = [hash[switch], nextval].flatten
166
- else
167
- hash[switch] = nextval
168
- end
169
- ARGV.delete_at(index+1)
170
- end
171
-
172
- # For boolean arguments set the switch's value to true.
173
- if types[switch] == BOOLEAN
174
- if hash.has_key?(switch)
175
- raise Error, "boolean switch already set"
176
- end
177
- hash[switch] = true
178
- end
179
-
180
- # For increment arguments, set the switch's value to 0, or
181
- # increment it by one if it already exists.
182
- if types[switch] == INCREMENT
183
- if hash.has_key?(switch)
184
- hash[switch] += 1
185
- else
186
- hash[switch] = 1
187
- end
188
- end
189
-
190
- # For optional argument, there may be an argument. If so, it
191
- # cannot be another switch. If not, it is set to true.
192
- if types[switch] == OPTIONAL
193
- nextval = ARGV[index+1]
194
- if valid.include?(nextval)
195
- hash[switch] = true
196
- else
197
- hash[switch] = nextval
198
- ARGV.delete_at(index+1)
199
- end
200
- end
201
- }
202
-
203
- # Set synonymous switches to the same value, e.g. if -t is a synonym
204
- # for --test, and the user passes "--test", then set "-t" to the same
205
- # value that "--test" was set to.
206
- #
207
- # This allows users to refer to the long or short switch and get
208
- # the same value
209
- hash.each{ |switch, val|
210
- if syns.keys.include?(switch)
211
- syns[switch].each{ |key|
212
- hash[key] = val
213
- }
214
- end
215
- }
216
-
217
- # Get rid of leading "--" and "-" to make it easier to reference
218
- hash.each{ |key, value|
219
- if key =~ /^-/
220
- if key[0,2] == '--'
221
- nkey = key.sub('--', '')
222
- else
223
- nkey = key.sub('-', '')
224
- end
225
- hash.delete(key)
226
- hash[nkey] = value
227
- end
228
- }
229
-
230
- hash
231
- end
232
-
233
- end
234
- end
@@ -1,87 +0,0 @@
1
- # The Getopt module serves as a namespace only
2
- module Getopt
3
- # The Getopt::Std class serves as a base class for the getopts method.
4
- class Std
5
- # The Getopt::Std::Error class is raised if there are any illegal
6
- # command line arguments.
7
- #
8
- class Error < StandardError; end
9
-
10
- # The version of this library
11
- VERSION = '1.3.8'
12
-
13
- # Processes single character command line options with option
14
- # clustering. This information is parsed from ARGV and returned
15
- # as a hash, with the switch (minus the "-") as the key. The value
16
- # for that key is either true/false (boolean switches) or the argument
17
- # that was passed to the switch.
18
- #
19
- # Characters followed by a ":" require an argument. The rest are
20
- # considered boolean switches. If a switch that accepts an argument
21
- # appears more than once, the value for that key becomes an array
22
- # of values.
23
- #
24
- def self.getopts(switches)
25
- args = switches.split(/ */)
26
- hash = {}
27
-
28
- while !ARGV.empty? && ARGV.first =~ /^-(.)(.*)/s
29
- first, rest = $1, $2
30
- pos = switches.index(first)
31
-
32
- # Switches on the command line must appear among the characters
33
- # declared in +switches+.
34
- raise Error, "invalid option '#{first}'" unless pos
35
-
36
- if args[pos+1] == ":"
37
- ARGV.shift
38
- if rest.empty?
39
- rest = ARGV.shift
40
-
41
- # Ensure that switches requiring arguments actually
42
- # receive a (non-switch) argument.
43
- if rest.nil? || rest.empty?
44
- raise Error, "missing argument for '-#{args[pos]}'"
45
- end
46
-
47
- # Do not permit switches that require arguments to be
48
- # followed immediately by another switch.
49
- temp_args = args.map{ |e| "-#{e}" }
50
-
51
- if temp_args.include?(rest) || temp_args.include?(rest[1..-1])
52
- err = "cannot use switch '#{rest}' as argument "
53
- err << "to another switch"
54
- raise Error, err
55
- end
56
-
57
- # For non boolean switches, arguments that appear multiple
58
- # times are converted to an array (or pushed onto an already
59
- # existant array).
60
- if hash.has_key?(first)
61
- hash[first] = [hash[first], rest].flatten
62
- else
63
- hash[first] = rest
64
- end
65
- else
66
- # Do not permit switches that require arguments to be
67
- # followed immediately by another switch.
68
- if args.include?(rest) || args.include?(rest[1..-1])
69
- err = "cannot use switch '#{rest}' as argument "
70
- err += "to another switch"
71
- raise Error, err
72
- end
73
- end
74
- else
75
- hash[first] = true # Boolean switch
76
- if rest.empty?
77
- ARGV.shift
78
- else
79
- ARGV[0] = "-#{rest}"
80
- end
81
- end
82
- end
83
-
84
- hash
85
- end
86
- end
87
- end