getopt 1.3.5 → 1.3.6

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
+ == 8-Aug-2007 - 1.3.6
2
+ * The Getopt::StdError class is now Getopt::Std::Error.
3
+ * The Getopt::LongError class is now Getopt::Long::Error.
4
+ * Added some inline rdoc documentation to the source code.
5
+ * Added a Rakefile with tasks for installation and testing.
6
+ * Removed the install.rb file - use the 'rake install' task instead.
7
+
1
8
  == 5-Jul-2006 - 1.3.5
2
9
  * Fixed a bug where multiple long switches with the same first character
3
10
  could cause invalid results. Thanks go to Michael Campbell for the spot.
data/MANIFEST CHANGED
@@ -1,15 +1,12 @@
1
- CHANGES
2
- MANIFEST
3
- README
4
- install.rb
5
- getopt.gemspec
6
-
7
- examples/example_std.rb
8
- examples/example_long.rb
9
-
10
- lib/getopt/std.rb
11
- lib/getopt/long.rb
12
-
13
- test/tc_getopt_std.rb
14
- test/tc_getopt_long.rb
15
- test/ts_all.rb
1
+ * CHANGES
2
+ * MANIFEST
3
+ * README
4
+ * Rakefile
5
+ * getopt.gemspec
6
+ * examples/example_std.rb
7
+ * examples/example_long.rb
8
+ * lib/getopt/std.rb
9
+ * lib/getopt/long.rb
10
+ * test/tc_getopt_std.rb
11
+ * test/tc_getopt_long.rb
12
+ * test/ts_all.rb
data/README CHANGED
@@ -6,18 +6,12 @@
6
6
  Ruby 1.8.0 or later.
7
7
 
8
8
  == Installation
9
- === Standard Installation
10
- ruby test/ts_all.rb
11
- ruby install.rb
12
-
13
- === Gem Installation
14
- ruby test/ts_all.rb
15
- ruby getopt.gemspec
16
- gem install getopt-x-y-z.gem # Where x-y-z is a version
9
+ rake test (optional)
10
+ rake install (non-gem) or rake install_gem (gem)
17
11
 
18
12
  == Synopsis
19
13
  === Getopt::Std
20
- require "getopt/std"
14
+ require 'getopt/std'
21
15
 
22
16
  # Look for -o with argument, and -I and -D boolean arguments
23
17
  opt = Getopt::Std.getopts("o:ID")
@@ -35,7 +29,8 @@
35
29
  end
36
30
 
37
31
  === Getopt::Long
38
- require "getopt/long"
32
+ require 'getopt/long'
33
+
39
34
  opt = Getopt::Long.getopts(
40
35
  ["--foo", "-f", Getopt::BOOLEAN],
41
36
  ["--bar", "-b", Getopt::REQUIRED]
@@ -181,10 +176,10 @@ INCREMENT
181
176
  Ruby's
182
177
 
183
178
  == Copyright
184
- (C) 2005-2006, Daniel J. Berger
179
+ (C) 2005-2007, Daniel J. Berger
185
180
  All Rights Reserved
186
181
 
187
182
  == Author
188
183
  Daniel J. Berger
189
- djberg96 at gmail.com
184
+ djberg96 at nospam at gmail.com
190
185
  imperator on IRC (freenode)
data/Rakefile ADDED
@@ -0,0 +1,23 @@
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.libs << 'lib'
21
+ t.warning = true
22
+ t.test_files = FileList['test/ts_all.rb']
23
+ end
data/lib/getopt/long.rb CHANGED
@@ -7,12 +7,30 @@ module Getopt
7
7
  NEGATABLE = 4
8
8
  NUMERIC = 5
9
9
 
10
- class LongError < StandardError; end
11
-
12
10
  class Long
13
- VERSION = '1.3.5'
14
-
15
- # Takes an array of switches. Each array consists of three elements.
11
+ class Error < StandardError; end
12
+
13
+ VERSION = '1.3.6'
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
+ #
16
34
  def self.getopts(*switches)
17
35
  if switches.empty?
18
36
  raise ArgumentError, "no switches provided"
@@ -69,7 +87,7 @@ module Getopt
69
87
 
70
88
  chars.each_with_index{ |char, i|
71
89
  unless valid.include?(char)
72
- raise LongError, "invalid switch '#{char}'"
90
+ raise Error, "invalid switch '#{char}'"
73
91
  end
74
92
 
75
93
  # Grab the next arg if the switch takes a required arg
@@ -83,7 +101,7 @@ module Getopt
83
101
  arg = ARGV.delete_at(index+1)
84
102
  if arg.nil? || valid.include?(arg) # Minor cheat here
85
103
  err = "no value provided for required argument '#{char}'"
86
- raise LongError, err
104
+ raise Error, err
87
105
  end
88
106
  ARGV.push(char, arg)
89
107
  end
@@ -122,7 +140,7 @@ module Getopt
122
140
  # a preceding switch, e.g. --option foo bar.
123
141
  unless valid.include?(switch)
124
142
  switch ||= opt
125
- raise LongError, "invalid switch '#{switch}'"
143
+ raise Error, "invalid switch '#{switch}'"
126
144
  end
127
145
 
128
146
  # Required arguments
@@ -132,13 +150,13 @@ module Getopt
132
150
  # Make sure there's a value for mandatory arguments
133
151
  if nextval.nil?
134
152
  err = "no value provided for required argument '#{switch}'"
135
- raise LongError, err
153
+ raise Error, err
136
154
  end
137
155
 
138
156
  # If there is a value, make sure it's not another switch
139
157
  if valid.include?(nextval)
140
158
  err = "cannot pass switch '#{nextval}' as an argument"
141
- raise LongError, err
159
+ raise Error, err
142
160
  end
143
161
 
144
162
  # If the same option appears more than once, put the values
@@ -154,7 +172,7 @@ module Getopt
154
172
  # For boolean arguments set the switch's value to true.
155
173
  if types[switch] == BOOLEAN
156
174
  if hash.has_key?(switch)
157
- raise LongError, "boolean switch already set"
175
+ raise Error, "boolean switch already set"
158
176
  end
159
177
  hash[switch] = true
160
178
  end
data/lib/getopt/std.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  module Getopt
2
- class StdError < StandardError; end
3
2
  class Std
4
- VERSION = "1.3.4"
3
+ class Error < StandardError; end
4
+
5
+ VERSION = '1.3.6'
5
6
 
6
7
  # Processes single character command line options with option
7
8
  # clustering. This information is parsed from ARGV and returned
@@ -24,7 +25,7 @@ module Getopt
24
25
 
25
26
  # Switches on the command line must appear among the characters
26
27
  # declared in +switches+.
27
- raise StdError, "invalid option '#{first}'" unless pos
28
+ raise Error, "invalid option '#{first}'" unless pos
28
29
 
29
30
  if args[pos+1] == ":"
30
31
  ARGV.shift
@@ -34,7 +35,7 @@ module Getopt
34
35
  # Ensure that switches requiring arguments actually
35
36
  # receive a (non-switch) argument.
36
37
  if rest.nil? || rest.empty?
37
- raise StdError, "missing argument for '-#{args[pos]}'"
38
+ raise Error, "missing argument for '-#{args[pos]}'"
38
39
  end
39
40
 
40
41
  # Do not permit switches that require arguments to be
@@ -42,7 +43,7 @@ module Getopt
42
43
  if args.include?(rest) || args.include?(rest[1..-1])
43
44
  err = "cannot use switch '#{rest}' as argument "
44
45
  err += "to another switch"
45
- raise StdError, err
46
+ raise Error, err
46
47
  end
47
48
 
48
49
  # For non boolean switches, arguments that appear multiple
@@ -59,7 +60,7 @@ module Getopt
59
60
  if args.include?(rest) || args.include?(rest[1..-1])
60
61
  err = "cannot use switch '#{rest}' as argument "
61
62
  err += "to another switch"
62
- raise StdError, err
63
+ raise Error, err
63
64
  end
64
65
  end
65
66
  else
@@ -1,18 +1,11 @@
1
- #######################################################
1
+ #####################################################################
2
2
  # tc_getopt_long.rb
3
3
  #
4
- # Test suite for the getopt-long package.
5
- #######################################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" || base =~ /getopt/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
11
- Dir.chdir("test") rescue nil
12
- end
13
-
14
- require "test/unit"
15
- require "getopt/long"
4
+ # Test suite for the getopt-long package. You should run this test
5
+ # via the 'rake test' rake task.
6
+ #####################################################################
7
+ require 'test/unit'
8
+ require 'getopt/long'
16
9
  include Getopt
17
10
 
18
11
  class TC_Getopt_Long < Test::Unit::TestCase
@@ -21,7 +14,7 @@ class TC_Getopt_Long < Test::Unit::TestCase
21
14
  end
22
15
 
23
16
  def test_version
24
- assert_equal('1.3.5', Long::VERSION)
17
+ assert_equal('1.3.6', Long::VERSION)
25
18
  end
26
19
 
27
20
  def test_constants
@@ -1,24 +1,17 @@
1
- ########################################################
1
+ ###################################################################
2
2
  # tc_getopt_std.rb
3
3
  #
4
- # Test suite for the Getopt::Std class.
5
- ########################################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" || base =~ /getopt/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
11
- Dir.chdir("test") rescue nil
12
- end
13
-
14
- require "test/unit"
15
- require "getopt/std"
4
+ # Test suite for the Getopt::Std class. You should run this test
5
+ # via the 'rake test' task.
6
+ ###################################################################
7
+ require 'test/unit'
8
+ require 'getopt/std'
16
9
  include Getopt
17
10
 
18
11
  class TC_Getopt_Std < Test::Unit::TestCase
19
12
 
20
13
  def test_version
21
- assert_equal("1.3.4", Std::VERSION)
14
+ assert_equal('1.3.6', Std::VERSION)
22
15
  end
23
16
 
24
17
  def test_getopts_basic
@@ -56,18 +49,18 @@ class TC_Getopt_Std < Test::Unit::TestCase
56
49
 
57
50
  def test_getopts_expected_errors_missing_arg
58
51
  ARGV.push("-ID")
59
- assert_raises(StdError){ Std.getopts("I:D") }
52
+ assert_raises(Std::Error){ Std.getopts("I:D") }
60
53
 
61
54
  ARGV.push("-ID")
62
- assert_raises(StdError){ Std.getopts("ID:") }
55
+ assert_raises(Std::Error){ Std.getopts("ID:") }
63
56
  end
64
57
 
65
58
  def test_getopts_expected_errors_extra_arg
66
59
  ARGV.push("-I", "-D", "-X")
67
- assert_raises(StdError){ Std.getopts("ID") }
60
+ assert_raises(Std::Error){ Std.getopts("ID") }
68
61
 
69
62
  ARGV.push("-IDX")
70
- assert_raises(StdError){ Std.getopts("ID") }
63
+ assert_raises(Std::Error){ Std.getopts("ID") }
71
64
  end
72
65
 
73
66
  # If a switch that accepts an argument appears more than once, the values
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: getopt
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.3.5
7
- date: 2006-07-05 00:00:00 -06:00
6
+ version: 1.3.6
7
+ date: 2007-08-08 00:00:00 -06:00
8
8
  summary: Getopt::Std and Getopt::Long option parsers for Ruby
9
9
  require_paths:
10
10
  - lib
@@ -34,6 +34,7 @@ files:
34
34
  - CHANGES
35
35
  - MANIFEST
36
36
  - README
37
+ - Rakefile
37
38
  - test/tc_getopt_long.rb
38
39
  - test/tc_getopt_std.rb
39
40
  - test/ts_all.rb