getopt 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,6 +1,11 @@
1
+ == 13-Feb-2006 - 1.3.2
2
+ * Improved error message if an option is passed without a preceding switch.
3
+ * Minor documentation fixes and clarifications.
4
+
1
5
  == 18-Nov-2005 - 1.3.1
2
6
  * Added support for compressed switches with getopt/long.
3
7
  * More tests.
8
+ * Fixed a bug in the gemspec.
4
9
 
5
10
  == 4-Nov-2005 - 1.3.0
6
11
  * Added the Getopt::Long class (long.rb). This is a complete revamp of the
data/README CHANGED
@@ -37,9 +37,18 @@
37
37
  === Getopt::Long
38
38
  require "getopt/long"
39
39
  opt = Getopt::Long.getopts(
40
- ["--foo", "-f", BOOLEAN],
41
- ["--bar", "-b", REQUIRED]
40
+ ["--foo", "-f", Getopt::BOOLEAN],
41
+ ["--bar", "-b", Getopt::REQUIRED]
42
42
  )
43
+
44
+ # Or, to save your fingers some typing:
45
+ #
46
+ # require "getopt/long"
47
+ # include Getopt
48
+ # opt = Long.getopts(
49
+ # ["--foo", "-f", BOOLEAN],
50
+ # ["--bar", "-b", REQUIRED]
51
+ # )
43
52
 
44
53
  if opt["foo"]
45
54
  # Do something if --foo or -f passed
@@ -66,7 +75,7 @@ Long.getopts(switches)
66
75
 
67
76
  The array should be in the form:
68
77
 
69
- ["--long", "-l", OPTION]
78
+ ["--long", "-l", Getopt::OPTION]
70
79
 
71
80
  Note that only the long form is required. If the short switch is not
72
81
  specified, it will automatically be set to the first letter of the long
@@ -86,7 +95,7 @@ REQUIRED
86
95
  switch appears multiple times, the values are collected into an array.
87
96
 
88
97
  BOOLEAN
89
- If the option is specified on the command line, it's value is set to true.
98
+ If the option is specified on the command line, its value is set to true.
90
99
  It must not be followed by a non-blank argument, excluding other switches.
91
100
  Attempting to pass a boolean switch more than once will raise an error.
92
101
 
@@ -153,6 +162,11 @@ INCREMENT
153
162
  There are a few extra things I plan to add (see the 'Future Plans' above) but
154
163
  I do not plan on this library ever becoming as feature rich as, say, Perl's
155
164
  Getopt::Long module.
165
+
166
+ If you plan to write a full fledged command line application, e.g. you plan
167
+ on implementing a full help system, gobs of command line options and tons of
168
+ switches, consider Jim Freeze's 'commandline' package, available on
169
+ RubyForge.
156
170
 
157
171
  == Warranty
158
172
  This package is provided "as is" and without any express or
@@ -163,7 +177,7 @@ INCREMENT
163
177
  Ruby's
164
178
 
165
179
  == Copyright
166
- (C) 2005, Daniel J. Berger
180
+ (C) 2005-2006, Daniel J. Berger
167
181
  All Rights Reserved
168
182
 
169
183
  == Author
@@ -9,19 +9,19 @@ module Getopt
9
9
  class LongError < StandardError; end
10
10
 
11
11
  class Long
12
- VERSION = "1.3.1"
12
+ VERSION = "1.3.2"
13
13
 
14
- # takes an array of switches. Each array consists of three elements.
14
+ # Takes an array of switches. Each array consists of three elements.
15
15
  def self.getopts(*switches)
16
+ if switches.empty?
17
+ raise ArgumentError, "no switches provided"
18
+ end
19
+
16
20
  hash = {} # Hash returned to user
17
21
  valid = [] # Tracks valid switches
18
22
  types = {} # Tracks argument types
19
23
  syns = {} # Tracks long and short arguments, or multiple shorts
20
24
 
21
- if switches.empty?
22
- raise ArgumentError, "no switches provided"
23
- end
24
-
25
25
  # If a string is passed, split it and convert it to an array of arrays
26
26
  if switches.first.kind_of?(String)
27
27
  switches = switches.join.split
@@ -56,7 +56,7 @@ module Getopt
56
56
 
57
57
  ARGV.each_with_index{ |opt, index|
58
58
 
59
- # Allow either -x -v or -xv style for sing char args
59
+ # Allow either -x -v or -xv style for single char args
60
60
  if re_short_sq.match(opt)
61
61
  chars = opt.split("")[1..-1].map{ |s| s = "-#{s}" }
62
62
 
@@ -110,8 +110,11 @@ module Getopt
110
110
  next
111
111
  end
112
112
 
113
- # Make sure that all the switches are valid
113
+ # Make sure that all the switches are valid. If 'switch' isn't
114
+ # defined at this point, it means an option was passed without
115
+ # a preceding switch, e.g. --option foo bar.
114
116
  unless valid.include?(switch)
117
+ switch ||= opt
115
118
  raise LongError, "invalid switch '#{switch}'"
116
119
  end
117
120
 
@@ -1,7 +1,7 @@
1
1
  module Getopt
2
2
  class StdError < StandardError; end
3
3
  class Std
4
- VERSION = "1.3.0"
4
+ VERSION = "1.3.2"
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.1", Long::VERSION)
24
+ assert_equal("1.3.2", Long::VERSION)
25
25
  end
26
26
 
27
27
  def test_constants
@@ -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.0", Std::VERSION)
21
+ assert_equal("1.3.2", Std::VERSION)
22
22
  end
23
23
 
24
24
  def test_getopts_basic
metadata CHANGED
@@ -3,11 +3,11 @@ 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.1
7
- date: 2005-11-18 00:00:00 -07:00
6
+ version: 1.3.2
7
+ date: 2006-02-13 00:00:00 -07:00
8
8
  summary: Getopt::Std for Ruby
9
9
  require_paths:
10
- - lib
10
+ - lib
11
11
  email: djberg96@gmail.com
12
12
  homepage: http://www.rubyforge.org/projects/shards
13
13
  rubyforge_project:
@@ -18,34 +18,36 @@ bindir: bin
18
18
  has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
25
24
  version:
26
25
  platform: ruby
27
26
  signing_key:
28
27
  cert_chain:
29
28
  authors:
30
- - Daniel J. Berger
29
+ - Daniel J. Berger
31
30
  files:
32
- - lib/getopt/long.rb
33
- - lib/getopt/std.rb
34
- - CHANGES
35
- - MANIFEST
36
- - README
37
- - CVS
38
- - test/tc_getopt_long.rb
39
- - test/tc_getopt_std.rb
40
- - test/ts_all.rb
41
- - test/CVS
31
+ - lib/getopt/long.rb
32
+ - lib/getopt/std.rb
33
+ - CHANGES
34
+ - MANIFEST
35
+ - README
36
+ - test/tc_getopt_long.rb
37
+ - test/tc_getopt_std.rb
38
+ - test/ts_all.rb
42
39
  test_files:
43
- - test/ts_all.rb
40
+ - test/ts_all.rb
44
41
  rdoc_options: []
42
+
45
43
  extra_rdoc_files:
46
- - README
47
- - CHANGES
44
+ - README
45
+ - CHANGES
48
46
  executables: []
47
+
49
48
  extensions: []
49
+
50
50
  requirements: []
51
- dependencies: []
51
+
52
+ dependencies: []
53
+