getopt 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ == 1.4.1 - 17-Jul-2011
2
+ * Now works with Ruby 1.9.x. Thanks go to Shura for the patch.
3
+ * Refactored the gemspec. Gem building code is now handled by Rake tasks.
4
+ * Refactored the Rakefile. Added a default task, removed the old install
5
+ task, and namespaced the gem related tasks.
6
+
1
7
  == 1.4.0 - 5-Sep-2009
2
8
  * Fixed a packaging bug where the libs weren't actually being included! Gah!
3
9
  Thanks go to Steven Hilton for the spot.
data/README CHANGED
@@ -1,183 +1,192 @@
1
- == Description
2
- Implements a simple Getopt::Std class for command line parsing, as well
3
- as a Getopt::Long class for more advanced command line parsing.
1
+ = Description
2
+ Implements a simple Getopt::Std class for command line parsing, as well
3
+ as a Getopt::Long class for more advanced command line parsing.
4
4
 
5
- == Prerequisites
6
- Ruby 1.8.0 or later.
7
-
8
- == Installation
9
- rake test (optional)
10
- rake install (non-gem) or rake install_gem (gem)
5
+ = Installation
6
+
7
+ gem install getopt
11
8
 
12
- == Synopsis
13
- === Getopt::Std
14
- require 'getopt/std'
9
+ = Synopsis
10
+ == Getopt::Std
11
+
12
+ require 'getopt/std'
15
13
 
16
- # Look for -o with argument, and -I and -D boolean arguments
17
- opt = Getopt::Std.getopts("o:ID")
14
+ # Look for -o with argument, and -I and -D boolean arguments
15
+ opt = Getopt::Std.getopts("o:ID")
18
16
 
19
- if opt["I"]
20
- # Do something if -I passed
17
+ if opt["I"]
18
+ # Do something if -I passed
21
19
 
22
- if opt["D"]
23
- # Do something if -D passed
20
+ if opt["D"]
21
+ # Do something if -D passed
24
22
 
25
- if opt["o"]
26
- case opt["o"]
27
- # blah, blah, blah
28
- end
29
- end
30
-
31
- === Getopt::Long
32
- require 'getopt/long'
33
-
34
- opt = Getopt::Long.getopts(
35
- ["--foo", "-f", Getopt::BOOLEAN],
36
- ["--bar", "-b", Getopt::REQUIRED]
37
- )
23
+ if opt["o"]
24
+ case opt["o"]
25
+ # blah, blah, blah
26
+ end
27
+ end
28
+
29
+ == Getopt::Long
30
+
31
+ require 'getopt/long'
32
+
33
+ opt = Getopt::Long.getopts(
34
+ ["--foo", "-f", Getopt::BOOLEAN],
35
+ ["--bar", "-b", Getopt::REQUIRED]
36
+ )
38
37
 
39
- # Or, to save your fingers some typing:
40
- #
41
- # require "getopt/long"
42
- # include Getopt
43
- # opt = Long.getopts(
44
- # ["--foo", "-f", BOOLEAN],
45
- # ["--bar", "-b", REQUIRED]
46
- # )
47
-
48
- if opt["foo"]
49
- # Do something if --foo or -f passed
50
-
51
- if opt["b"]
52
- # Do something if --bar or -b passed
53
-
54
- == Class Methods
38
+ # Or, to save your fingers some typing:
39
+ #
40
+ # require "getopt/long"
41
+ # include Getopt
42
+ # opt = Long.getopts(
43
+ # ["--foo", "-f", BOOLEAN],
44
+ # ["--bar", "-b", REQUIRED]
45
+ # )
46
+
47
+ if opt["foo"]
48
+ # Do something if --foo or -f passed
49
+
50
+ if opt["b"]
51
+ # Do something if --bar or -b passed
52
+
53
+ = Class Methods
54
+
55
55
  Std.getopts(switches)
56
- Takes a series of single character switches that can be accepted on the
57
- command line. Those characters followed by a ':' require an argument. The
58
- rest are considered boolean switches. Returns a hash, with the switches
59
- as the key (sans the leading '-'). For boolean switches, the value is
60
- either true or false. Switches that were not passed on the command line
61
- do not appear in the hash.
62
56
 
63
- In the event that a switch that accepts an argument appears multiple times
64
- the value for that key becomes an array of values.
57
+ Takes a series of single character switches that can be accepted on the
58
+ command line. Those characters followed by a ':' require an argument. The
59
+ rest are considered boolean switches. Returns a hash, with the switches
60
+ as the key (sans the leading '-'). For boolean switches, the value is
61
+ either true or false. Switches that were not passed on the command line
62
+ do not appear in the hash.
63
+
64
+ In the event that a switch that accepts an argument appears multiple times
65
+ the value for that key becomes an array of values.
65
66
 
66
67
  Long.getopts(switches)
67
- Takes an array of switches beginning with "--" followed by one or more
68
- alphanumeric or hyphen characters, or "-" followed by a single character.
69
- The type of argument, if any, can be specified as BOOLEAN, OPTIONAL,
70
- REQUIRED or INCREMENT.
71
68
 
72
- The array should be in the form:
69
+ Takes an array of switches beginning with "--" followed by one or more
70
+ alphanumeric or hyphen characters, or "-" followed by a single character.
71
+ The type of argument, if any, can be specified as BOOLEAN, OPTIONAL,
72
+ REQUIRED or INCREMENT.
73
+
74
+ The array should be in the form:
73
75
 
74
- # long form, short form (alias), option type
75
- ["--long", "-l", Getopt::OPTION]
76
+ # long form, short form (alias), option type
77
+ ["--long", "-l", Getopt::OPTION]
76
78
 
77
- Note that only the long form is required. If the short form is not
78
- specified, it will automatically be set to the first letter of the long
79
- switch. If multiple long switches with the same first character are
80
- listed without short switches, only the first long switch gets the short
81
- switch alias.
79
+ Note that only the long form is required. If the short form is not
80
+ specified, it will automatically be set to the first letter of the long
81
+ switch. If multiple long switches with the same first character are
82
+ listed without short switches, only the first long switch gets the short
83
+ switch alias.
82
84
 
83
- If the argument type is not specified, the default is BOOLEAN.
85
+ If the argument type is not specified, the default is BOOLEAN.
84
86
 
85
- For the truly lazy, you can also pass a string of long switches (with
86
- no short switches or argument types).
87
+ For the truly lazy, you can also pass a string of long switches (with
88
+ no short switches or argument types).
87
89
 
88
- See the 'examples' directory for more examples.
90
+ See the 'examples' directory for more examples.
91
+
92
+ = Getopt::Long argument types
89
93
 
90
- == Getopt::Long argument types
91
94
  REQUIRED
92
- If the option is specified on the command line, it must be followed by
93
- a non-blank argument. This argument cannot be another switch. If this
94
- switch appears multiple times, the values are collected into an array.
95
+ If the option is specified on the command line, it must be followed by
96
+ a non-blank argument. This argument cannot be another switch. If this
97
+ switch appears multiple times, the values are collected into an array.
95
98
 
96
99
  BOOLEAN
97
- If the option is specified on the command line, its value is set to true.
98
- It must not be followed by a non-blank argument, excluding other switches.
99
- Attempting to pass a boolean switch more than once will raise an error.
100
+ If the option is specified on the command line, its value is set to true.
101
+ It must not be followed by a non-blank argument, excluding other switches.
102
+ Attempting to pass a boolean switch more than once will raise an error.
100
103
 
101
104
  OPTIONAL
102
- If the option is specified on the command line, it may or may not accept
103
- an argument, excluding other valid switches. If an argument is present,
104
- it's value is set to that argument. If an argument is not present, it's
105
- value is set to nil.
105
+ If the option is specified on the command line, it may or may not accept
106
+ an argument, excluding other valid switches. If an argument is present,
107
+ it's value is set to that argument. If an argument is not present, it's
108
+ value is set to nil.
106
109
 
107
110
  INCREMENT
108
- If the option is specified on the command line, its value is incremented
109
- by one for each appearance on the command line, or set to 1 if it appears
110
- only once.
111
-
112
- == Future Plans
113
- Add support for negatable options so that you can do "--no-foo", for
114
- example.
115
-
116
- Add support for numeric types, so that you don't have to manually convert
117
- strings to numbers.
118
-
119
- Allow shortcut characters for the option types, e.g. "?" for BOOLEAN, "+"
120
- for INCREMENT, etc.
121
-
122
- == Known Bugs
123
- === Getopt::Std
124
- You cannot squish switches that require arguments with the argument itself.
125
- For example, if you do Getopt::Std.getopts("o:ID"), it will not parse
126
- "-IDohello" properly. Instead, you must do "-IDo hello". Or, you can just
127
- separate the argument, e.g. "-I -D -o hello".
128
-
129
- === Getopt::Long
130
- If you mix and match compressed switches with separate, optional switches
131
- the optional switch will be set to true instead of nil if it separated
132
- from the compressed switches.
111
+ If the option is specified on the command line, its value is incremented
112
+ by one for each appearance on the command line, or set to 1 if it appears
113
+ only once.
114
+
115
+ = Future Plans
116
+ Add support for negatable options so that you can do "--no-foo", for
117
+ example.
118
+
119
+ Add support for numeric types, so that you don't have to manually convert
120
+ strings to numbers.
121
+
122
+ Allow shortcut characters for the option types, e.g. "?" for BOOLEAN, "+"
123
+ for INCREMENT, etc.
124
+
125
+ = Known Bugs
126
+
127
+ == Getopt::Std
128
+
129
+ You cannot squish switches that require arguments with the argument itself.
130
+ For example, if you do Getopt::Std.getopts("o:ID"), it will not parse
131
+ "-IDohello" properly. Instead, you must do "-IDo hello". Or, you can just
132
+ separate the argument, e.g. "-I -D -o hello".
133
+
134
+ == Getopt::Long
135
+
136
+ If you mix and match compressed switches with separate, optional switches
137
+ the optional switch will be set to true instead of nil if it separated
138
+ from the compressed switches.
133
139
 
134
- === Reporting Bugs
135
- If you find any other bugs, please log them on the project
136
- page at http://www.rubyforge.org/projects/shards.
137
-
138
- == Other Issues
139
- Neither class attempts to be POSIX compliant in any way, shape or form.
140
- And I don't care!
141
-
142
- == Notes From the Author
143
- My main gripe with the getoptlong library currently in the standard library
144
- is that it doesn't return a hash, yet gives you partial hash behavior. This
145
- was both confusing and annoying, since the first thing I do (along with
146
- everyone else) is collect the results into a hash for later processing.
147
-
148
- My main gripe with the optparse library (also in the standard library) is
149
- that it treats command line processing like event processing. It's too
150
- complex, when 90% of the time all you want to do is slurp the command line
151
- options into a hash.
152
-
153
- So, I did something utterly novel with this library. I collected the command
154
- line options ... (wait for it) ... into a hash! Then I give that hash to
155
- you, aliases and all. I did get some ideas from Perl's Getopt::Long library,
156
- but this is in no way a port of that module (which supports POSIX parsing, GNU
157
- parsing, more option types, etc). My goal was to provide the functionality
158
- that I felt would cover the vast majority of common cases, yet still provide
159
- a little extra spice with switch types (REQUIRED, OPTIONAL, etc).
160
-
161
- There are a few extra things I plan to add (see the 'Future Plans' above) but
162
- I do not plan on this library ever becoming as feature rich as, say, Perl's
163
- Getopt::Long module.
140
+ == Reporting Bugs
141
+
142
+ If you find any other bugs, please log them on the project
143
+ page at http://www.rubyforge.org/projects/shards.
144
+
145
+ = Other Issues
146
+
147
+ Neither class attempts to be POSIX compliant in any way, shape or form.
148
+ And I don't care!
149
+
150
+ = Notes From the Author
151
+
152
+ My main gripe with the getoptlong library currently in the standard library
153
+ is that it doesn't return a hash, yet gives you partial hash behavior. This
154
+ was both confusing and annoying, since the first thing I do (along with
155
+ everyone else) is collect the results into a hash for later processing.
156
+
157
+ My main gripe with the optparse library (also in the standard library) is
158
+ that it treats command line processing like event processing. It's too
159
+ complex, when 90% of the time all you want to do is slurp the command line
160
+ options into a hash.
161
+
162
+ So, I did something utterly novel with this library. I collected the command
163
+ line options ... (wait for it) ... into a hash! Then I give that hash to
164
+ you, aliases and all. I did get some ideas from Perl's Getopt::Long library,
165
+ but this is in no way a port of that module (which supports POSIX parsing, GNU
166
+ parsing, more option types, etc). My goal was to provide the functionality
167
+ that I felt would cover the vast majority of common cases, yet still provide
168
+ a little extra spice with switch types (REQUIRED, OPTIONAL, etc).
169
+
170
+ There are a few extra things I plan to add (see the 'Future Plans' above) but
171
+ I do not plan on this library ever becoming as feature rich as, say, Perl's
172
+ Getopt::Long module.
164
173
 
165
- If you plan to write a full fledged command line application, e.g. you plan
166
- on implementing a full help system, gobs of command line options and tons of
167
- switches, consider Jim Freeze's 'commandline' package, available on
168
- RubyForge.
174
+ If you plan to write a full fledged command line application, e.g. you plan
175
+ on implementing a full help system, gobs of command line options and tons of
176
+ switches, consider Jim Freeze's 'commandline' package, available on
177
+ RubyForge.
169
178
 
170
- == Warranty
171
- This package is provided "as is" and without any express or
172
- implied warranties, including, without limitation, the implied
173
- warranties of merchantability and fitness for a particular purpose.
179
+ = Warranty
180
+ This package is provided "as is" and without any express or
181
+ implied warranties, including, without limitation, the implied
182
+ warranties of merchantability and fitness for a particular purpose.
174
183
 
175
- == License
176
- Artistic 2.0
184
+ = License
185
+ Artistic 2.0
177
186
 
178
- == Copyright
179
- (C) 2005-2009, Daniel J. Berger
180
- All Rights Reserved
187
+ = Copyright
188
+ (C) 2005-2011, Daniel J. Berger
189
+ All Rights Reserved
181
190
 
182
- == Author
183
- Daniel J. Berger
191
+ = Author
192
+ Daniel J. Berger
data/Rakefile CHANGED
@@ -1,34 +1,40 @@
1
1
  require 'rake'
2
+ require 'rake/clean'
2
3
  require 'rake/testtask'
3
4
 
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
5
+ CLEAN.include("**/*.gem", "**/*.rbc")
6
+
7
+ namespace :gem do
8
+ desc "Create the getopt gem"
9
+ task :create => [:clean] do
10
+ spec = eval(IO.read('getopt.gemspec'))
11
+ Gem::Builder.new(spec).build
12
+ end
11
13
 
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}"
14
+ desc "Install the getopt gem"
15
+ task :install => [:create] do
16
+ file = Dir["*.gem"].first
17
+ sh "gem install #{file}"
18
+ end
17
19
  end
18
20
 
19
21
  Rake::TestTask.new do |t|
20
- t.warning = true
21
- t.verbose = true
22
+ t.warning = true
23
+ t.verbose = true
22
24
  end
23
25
 
24
- Rake::TestTask.new('test_getopt_long') do |t|
25
- t.test_files = 'test/test_getopt_long.rb'
26
- t.warning = true
27
- t.verbose = true
28
- end
26
+ namespace :test do
27
+ Rake::TestTask.new('getopt_long') do |t|
28
+ t.test_files = 'test/test_getopt_long.rb'
29
+ t.warning = true
30
+ t.verbose = true
31
+ end
29
32
 
30
- Rake::TestTask.new('test_getopt_std') do |t|
31
- t.test_files = 'test/test_getopt_std.rb'
32
- t.warning = true
33
- t.verbose = true
33
+ Rake::TestTask.new('getopt_std') do |t|
34
+ t.test_files = 'test/test_getopt_std.rb'
35
+ t.warning = true
36
+ t.verbose = true
37
+ end
34
38
  end
39
+
40
+ task :default => :test
@@ -1,29 +1,26 @@
1
1
  require 'rubygems'
2
2
 
3
- spec = Gem::Specification.new do |gem|
4
- gem.name = 'getopt'
5
- gem.version = '1.4.0'
6
- gem.author = 'Daniel J. Berger'
7
- gem.license = 'Artistic 2.0'
8
- gem.email = 'djberg96@gmail.com'
9
- gem.homepage = 'http://www.rubyforge.org/projects/shards'
10
- gem.platform = Gem::Platform::RUBY
11
- gem.summary = 'Getopt::Std and Getopt::Long option parsers for Ruby'
12
- gem.test_files = Dir['test/*.rb']
13
- gem.has_rdoc = true
14
- gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'getopt'
5
+ spec.version = '1.4.1'
6
+ spec.author = 'Daniel J. Berger'
7
+ spec.license = 'Artistic 2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://www.rubyforge.org/projects/shards'
10
+ spec.platform = Gem::Platform::RUBY
11
+ spec.summary = 'Getopt::Std and Getopt::Long option parsers for Ruby'
12
+ spec.test_files = Dir['test/*.rb']
13
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
15
14
 
16
- gem.rubyforge_project = 'shards'
17
- gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
15
+ spec.rubyforge_project = 'shards'
16
+ spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
18
17
 
19
- gem.add_development_dependency('test-unit', '>= 2.0.3')
18
+ spec.add_development_dependency('test-unit', '>= 2.0.3')
20
19
 
21
- gem.description = <<-EOF
22
- The getopt library provides two different command line option parsers.
23
- They are meant as easier and more convenient replacements for the
24
- command line parsers that ship as part of the Ruby standard library.
25
- Please see the README for additional comments.
26
- EOF
20
+ spec.description = <<-EOF
21
+ The getopt library provides two different command line option parsers.
22
+ They are meant as easier and more convenient replacements for the
23
+ command line parsers that ship as part of the Ruby standard library.
24
+ Please see the README for additional comments.
25
+ EOF
27
26
  end
28
-
29
- Gem::Builder.new(spec).build
@@ -17,7 +17,7 @@ module Getopt
17
17
  class Error < StandardError; end
18
18
 
19
19
  # The version of the getopt library
20
- VERSION = '1.4.0'
20
+ VERSION = '1.4.1'
21
21
 
22
22
  # Takes an array of switches. Each array consists of up to three
23
23
  # elements that indicate the name and type of switch. Returns a hash
@@ -215,7 +215,7 @@ module Getopt
215
215
  #
216
216
  # This allows users to refer to the long or short switch and get
217
217
  # the same value
218
- hash.each{ |switch, val|
218
+ hash.dup.each{ |switch, val|
219
219
  if syns.keys.include?(switch)
220
220
  syns[switch] = [syns[switch]] if RUBY_VERSION.to_f >= 1.9
221
221
  syns[switch].each{ |key|
@@ -225,7 +225,7 @@ module Getopt
225
225
  }
226
226
 
227
227
  # Get rid of leading "--" and "-" to make it easier to reference
228
- hash.each{ |key, value|
228
+ hash.dup.each{ |key, value|
229
229
  if key =~ /^-/
230
230
  if key[0,2] == '--'
231
231
  nkey = key.sub('--', '')
@@ -10,7 +10,7 @@ module Getopt
10
10
  class Error < StandardError; end
11
11
 
12
12
  # The version of the getopt library
13
- VERSION = '1.4.0'
13
+ VERSION = '1.4.1'
14
14
 
15
15
  # Processes single character command line options with option
16
16
  # clustering. This information is parsed from ARGV and returned
@@ -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.4.0', Long::VERSION)
20
+ assert_equal('1.4.1', 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.4.0', Std::VERSION)
17
+ assert_equal('1.4.1', Std::VERSION)
18
18
  end
19
19
 
20
20
  def test_getopts_basic
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getopt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ hash: 5
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 4
9
+ - 1
10
+ version: 1.4.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Daniel J. Berger
@@ -9,20 +15,25 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-09-05 00:00:00 -06:00
13
- default_executable:
18
+ date: 2011-07-17 00:00:00 Z
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: test-unit
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ hash: 9
29
+ segments:
30
+ - 2
31
+ - 0
32
+ - 3
23
33
  version: 2.0.3
24
- version:
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"
34
+ type: :development
35
+ version_requirements: *id001
36
+ 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
37
  email: djberg96@gmail.com
27
38
  executables: []
28
39
 
@@ -44,7 +55,6 @@ files:
44
55
  - README
45
56
  - test/test_getopt_long.rb
46
57
  - test/test_getopt_std.rb
47
- has_rdoc: true
48
58
  homepage: http://www.rubyforge.org/projects/shards
49
59
  licenses:
50
60
  - Artistic 2.0
@@ -54,21 +64,27 @@ rdoc_options: []
54
64
  require_paths:
55
65
  - lib
56
66
  required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
57
68
  requirements:
58
69
  - - ">="
59
70
  - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
60
74
  version: "0"
61
- version:
62
75
  required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
63
77
  requirements:
64
78
  - - ">="
65
79
  - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
66
83
  version: "0"
67
- version:
68
84
  requirements: []
69
85
 
70
86
  rubyforge_project: shards
71
- rubygems_version: 1.3.5
87
+ rubygems_version: 1.8.3
72
88
  signing_key:
73
89
  specification_version: 3
74
90
  summary: Getopt::Std and Getopt::Long option parsers for Ruby