getopt 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES +4 -0
- data/README +7 -8
- data/Rakefile +7 -2
- data/examples/example_long.rb +4 -1
- data/examples/example_std.rb +0 -8
- data/getopt.gemspec +3 -5
- data/lib/getopt/long.rb +5 -5
- data/lib/getopt/std.rb +4 -4
- data/test/test_getopt_long.rb +6 -9
- data/test/test_getopt_std.rb +3 -6
- metadata +43 -59
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f54f1e6653d0a5c7be3fe5980cd54dbadb36ee6a
|
4
|
+
data.tar.gz: 18ee08f16d15ad19931458fbd3146257adeb84aa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 450e1d25c05e828390a3b333e5d39eb474ab2c63b26643b8cddf71efa9ff548498d7340115c651099fc84b545dffd10902279e8013671fccc91df38bb4b9fe14
|
7
|
+
data.tar.gz: cccc37509314d516557763cd97615f8562afca023311374ca704c0a03f3690dc00a23a83cd3d83f3e74f1c0ef975f2df2ed4dd11550a871cf4073f007c1cbeee
|
data/CHANGES
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== 1.4.2 - 12-Oct-2014
|
2
|
+
* Updated Rakefile, README and gemspec.
|
3
|
+
* Minor updates to the test file and examples.
|
4
|
+
|
1
5
|
== 1.4.1 - 17-Jul-2011
|
2
6
|
* Now works with Ruby 1.9.x. Thanks go to Shura for the patch.
|
3
7
|
* Refactored the gemspec. Gem building code is now handled by Rake tasks.
|
data/README
CHANGED
@@ -122,7 +122,7 @@ INCREMENT
|
|
122
122
|
Allow shortcut characters for the option types, e.g. "?" for BOOLEAN, "+"
|
123
123
|
for INCREMENT, etc.
|
124
124
|
|
125
|
-
= Known
|
125
|
+
= Known Issues
|
126
126
|
|
127
127
|
== Getopt::Std
|
128
128
|
|
@@ -137,12 +137,12 @@ INCREMENT
|
|
137
137
|
the optional switch will be set to true instead of nil if it separated
|
138
138
|
from the compressed switches.
|
139
139
|
|
140
|
-
== Reporting
|
140
|
+
== Reporting Issues
|
141
141
|
|
142
|
-
If you find any other
|
143
|
-
page at
|
142
|
+
If you find any other issues, please log them on the project
|
143
|
+
page at https://github.com/djberg96/getopt.
|
144
144
|
|
145
|
-
= Other
|
145
|
+
= Other Stuff
|
146
146
|
|
147
147
|
Neither class attempts to be POSIX compliant in any way, shape or form.
|
148
148
|
And I don't care!
|
@@ -173,8 +173,7 @@ INCREMENT
|
|
173
173
|
|
174
174
|
If you plan to write a full fledged command line application, e.g. you plan
|
175
175
|
on implementing a full help system, gobs of command line options and tons of
|
176
|
-
switches, consider Jim Freeze's 'commandline'
|
177
|
-
RubyForge.
|
176
|
+
switches, consider Jim Freeze's 'commandline' gem.
|
178
177
|
|
179
178
|
= Warranty
|
180
179
|
This package is provided "as is" and without any express or
|
@@ -185,7 +184,7 @@ INCREMENT
|
|
185
184
|
Artistic 2.0
|
186
185
|
|
187
186
|
= Copyright
|
188
|
-
(C) 2005-
|
187
|
+
(C) 2005-2014, Daniel J. Berger
|
189
188
|
All Rights Reserved
|
190
189
|
|
191
190
|
= Author
|
data/Rakefile
CHANGED
@@ -8,13 +8,18 @@ namespace :gem do
|
|
8
8
|
desc "Create the getopt gem"
|
9
9
|
task :create => [:clean] do
|
10
10
|
spec = eval(IO.read('getopt.gemspec'))
|
11
|
-
Gem::
|
11
|
+
if Gem::VERSION < "2.0"
|
12
|
+
Gem::Builder.new(spec).build
|
13
|
+
else
|
14
|
+
require 'rubygems/package'
|
15
|
+
Gem::Package.build(spec)
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
19
|
desc "Install the getopt gem"
|
15
20
|
task :install => [:create] do
|
16
21
|
file = Dir["*.gem"].first
|
17
|
-
sh "gem install #{file}"
|
22
|
+
sh "gem install -l #{file}"
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
data/examples/example_long.rb
CHANGED
@@ -5,11 +5,12 @@
|
|
5
5
|
# handle command line options.
|
6
6
|
##########################################################################
|
7
7
|
require "getopt/long"
|
8
|
+
include Getopt
|
8
9
|
|
9
10
|
# The truly lazy way. This creates two valid command line switches,
|
10
11
|
# automatically creates single letter switches (-f, -b), and sets each
|
11
12
|
# switch type to BOOLEAN.
|
12
|
-
opts = Getopt::Long.getopts("--foo --bar")
|
13
|
+
#opts = Getopt::Long.getopts("--foo --bar")
|
13
14
|
|
14
15
|
# Here's a comprehensive example that uses all types and options.
|
15
16
|
opts = Getopt::Long.getopts(
|
@@ -22,6 +23,8 @@ opts = Getopt::Long.getopts(
|
|
22
23
|
["--my-name", "-x", REQUIRED] # --my-name, -x, REQUIRED
|
23
24
|
)
|
24
25
|
|
26
|
+
p opts
|
27
|
+
|
25
28
|
# Using the above example:
|
26
29
|
|
27
30
|
# User passes "-f"
|
data/examples/example_std.rb
CHANGED
@@ -3,14 +3,6 @@
|
|
3
3
|
#
|
4
4
|
# Some samples of how to use the Getopt::Std class.
|
5
5
|
#####################################################
|
6
|
-
base = File.basename(Dir.pwd)
|
7
|
-
|
8
|
-
if base == "examples" || base =~ /getopt/
|
9
|
-
Dir.chdir("..") if base == "examples"
|
10
|
-
$LOAD_PATH.unshift(Dir.pwd + "/lib")
|
11
|
-
Dir.chdir("examples") rescue nil
|
12
|
-
end
|
13
|
-
|
14
6
|
require "getopt/std"
|
15
7
|
include Getopt
|
16
8
|
|
data/getopt.gemspec
CHANGED
@@ -2,20 +2,18 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'getopt'
|
5
|
-
spec.version = '1.4.
|
5
|
+
spec.version = '1.4.2'
|
6
6
|
spec.author = 'Daniel J. Berger'
|
7
7
|
spec.license = 'Artistic 2.0'
|
8
8
|
spec.email = 'djberg96@gmail.com'
|
9
|
-
spec.homepage = '
|
10
|
-
spec.platform = Gem::Platform::RUBY
|
9
|
+
spec.homepage = 'https://github.com/djberg96/getopt'
|
11
10
|
spec.summary = 'Getopt::Std and Getopt::Long option parsers for Ruby'
|
12
11
|
spec.test_files = Dir['test/*.rb']
|
13
12
|
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
14
13
|
|
15
|
-
spec.rubyforge_project = 'shards'
|
16
14
|
spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
|
17
15
|
|
18
|
-
spec.add_development_dependency('test-unit', '>= 2.0
|
16
|
+
spec.add_development_dependency('test-unit', '>= 2.5.0')
|
19
17
|
|
20
18
|
spec.description = <<-EOF
|
21
19
|
The getopt library provides two different command line option parsers.
|
data/lib/getopt/long.rb
CHANGED
@@ -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.
|
20
|
+
VERSION = '1.4.2'
|
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
|
@@ -69,7 +69,7 @@ module Getopt
|
|
69
69
|
switch[1] ||= switch[0][1..2]
|
70
70
|
end
|
71
71
|
|
72
|
-
# Create synonym hash. Default to first char of long switch for
|
72
|
+
# Create synonym hash. Default to first char of long switch for
|
73
73
|
# short switch, e.g. "--verbose" creates a "-v" synonym. The same
|
74
74
|
# synonym can only be used once - first one wins.
|
75
75
|
syns[switch[0]] = switch[1] unless syns[switch[1]]
|
@@ -77,7 +77,7 @@ module Getopt
|
|
77
77
|
|
78
78
|
switch[1] = [switch[1]] if RUBY_VERSION.to_f >= 1.9
|
79
79
|
|
80
|
-
switch[1].each{ |char|
|
80
|
+
switch[1].each{ |char|
|
81
81
|
types[char] = switch[2] # Set type for short switch
|
82
82
|
valid.push(char) # Set valid short switches
|
83
83
|
}
|
@@ -95,7 +95,7 @@ module Getopt
|
|
95
95
|
chars = opt.split("")[1..-1].map{ |s| s = "-#{s}" }
|
96
96
|
|
97
97
|
chars.each_with_index{ |char, i|
|
98
|
-
unless valid.include?(char)
|
98
|
+
unless valid.include?(char)
|
99
99
|
raise Error, "invalid switch '#{char}'"
|
100
100
|
end
|
101
101
|
|
@@ -219,7 +219,7 @@ module Getopt
|
|
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|
|
222
|
-
hash[key] = val
|
222
|
+
hash[key] = val
|
223
223
|
}
|
224
224
|
end
|
225
225
|
}
|
data/lib/getopt/std.rb
CHANGED
@@ -6,11 +6,11 @@ module Getopt
|
|
6
6
|
|
7
7
|
# The Getopt::Std::Error class is raised if there are any illegal
|
8
8
|
# command line arguments.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
class Error < StandardError; end
|
11
11
|
|
12
12
|
# The version of the getopt library
|
13
|
-
VERSION = '1.4.
|
13
|
+
VERSION = '1.4.2'
|
14
14
|
|
15
15
|
# Processes single character command line options with option
|
16
16
|
# clustering. This information is parsed from ARGV and returned
|
@@ -41,11 +41,11 @@ module Getopt
|
|
41
41
|
# # Do something
|
42
42
|
# end
|
43
43
|
# end
|
44
|
-
#
|
44
|
+
#
|
45
45
|
def self.getopts(switches)
|
46
46
|
args = switches.split(/ */)
|
47
47
|
hash = {}
|
48
|
-
|
48
|
+
|
49
49
|
while !ARGV.empty? && ARGV.first =~ /^-(.)(.*)/s
|
50
50
|
first, rest = $1, $2
|
51
51
|
pos = switches.index(first)
|
data/test/test_getopt_long.rb
CHANGED
@@ -4,10 +4,7 @@
|
|
4
4
|
# Test suite for the getopt-long package. You should run this test
|
5
5
|
# via the 'rake test' rake task.
|
6
6
|
#####################################################################
|
7
|
-
require '
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
7
|
+
require 'test-unit'
|
11
8
|
require 'getopt/long'
|
12
9
|
include Getopt
|
13
10
|
|
@@ -17,7 +14,7 @@ class TC_Getopt_Long < Test::Unit::TestCase
|
|
17
14
|
end
|
18
15
|
|
19
16
|
def test_version
|
20
|
-
assert_equal('1.4.
|
17
|
+
assert_equal('1.4.2', Long::VERSION)
|
21
18
|
end
|
22
19
|
|
23
20
|
def test_constants
|
@@ -59,7 +56,7 @@ class TC_Getopt_Long < Test::Unit::TestCase
|
|
59
56
|
assert_equal("world", @opts["bar"])
|
60
57
|
assert_equal("world", @opts["b"])
|
61
58
|
end
|
62
|
-
|
59
|
+
|
63
60
|
def test_getopts_long_embedded_hyphens
|
64
61
|
ARGV.push('--foo-bar', 'hello', '--test1-test2-test3', 'world')
|
65
62
|
assert_nothing_raised{
|
@@ -73,7 +70,7 @@ class TC_Getopt_Long < Test::Unit::TestCase
|
|
73
70
|
assert_equal('world', @opts['test1-test2-test3'])
|
74
71
|
assert_equal('world', @opts['t'])
|
75
72
|
end
|
76
|
-
|
73
|
+
|
77
74
|
def test_getopts_long_embedded_hyphens_using_equals_sign
|
78
75
|
ARGV.push('--foo-bar=hello', '--test1-test2-test3=world')
|
79
76
|
assert_nothing_raised{
|
@@ -245,14 +242,14 @@ class TC_Getopt_Long < Test::Unit::TestCase
|
|
245
242
|
)
|
246
243
|
}
|
247
244
|
end
|
248
|
-
|
245
|
+
|
249
246
|
def test_multiple_similar_long_switches_with_no_short_switches
|
250
247
|
ARGV.push('--to','1','--too','2','--tooo','3')
|
251
248
|
assert_nothing_raised{
|
252
249
|
@opts = Long.getopts(
|
253
250
|
["--to", REQUIRED],
|
254
251
|
["--too", REQUIRED],
|
255
|
-
["--tooo", REQUIRED]
|
252
|
+
["--tooo", REQUIRED]
|
256
253
|
)
|
257
254
|
}
|
258
255
|
assert_equal('1', @opts['to'])
|
data/test/test_getopt_std.rb
CHANGED
@@ -4,23 +4,20 @@
|
|
4
4
|
# Test suite for the Getopt::Std class. You should run this test
|
5
5
|
# via the 'rake test' task.
|
6
6
|
###################################################################
|
7
|
-
require '
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
7
|
+
require 'test-unit'
|
11
8
|
require 'getopt/std'
|
12
9
|
include Getopt
|
13
10
|
|
14
11
|
class TC_Getopt_Std < Test::Unit::TestCase
|
15
12
|
|
16
13
|
def test_version
|
17
|
-
assert_equal('1.4.
|
14
|
+
assert_equal('1.4.2', Std::VERSION)
|
18
15
|
end
|
19
16
|
|
20
17
|
def test_getopts_basic
|
21
18
|
assert_respond_to(Std, :getopts)
|
22
19
|
assert_nothing_raised{ Std.getopts("ID") }
|
23
|
-
assert_kind_of(Hash, Std.getopts("ID"))
|
20
|
+
assert_kind_of(Hash, Std.getopts("ID"))
|
24
21
|
end
|
25
22
|
|
26
23
|
def test_getopts_separated_switches
|
metadata
CHANGED
@@ -1,93 +1,77 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: getopt
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 4
|
9
|
-
- 1
|
10
|
-
version: 1.4.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.4.2
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Daniel J. Berger
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-10-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: test-unit
|
22
|
-
|
23
|
-
|
24
|
-
none: false
|
25
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
26
17
|
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 2
|
31
|
-
- 0
|
32
|
-
- 3
|
33
|
-
version: 2.0.3
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.5.0
|
34
20
|
type: :development
|
35
|
-
|
36
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.5.0
|
27
|
+
description: |2
|
28
|
+
The getopt library provides two different command line option parsers.
|
29
|
+
They are meant as easier and more convenient replacements for the
|
30
|
+
command line parsers that ship as part of the Ruby standard library.
|
31
|
+
Please see the README for additional comments.
|
37
32
|
email: djberg96@gmail.com
|
38
33
|
executables: []
|
39
|
-
|
40
34
|
extensions: []
|
41
|
-
|
42
|
-
extra_rdoc_files:
|
35
|
+
extra_rdoc_files:
|
43
36
|
- README
|
44
37
|
- CHANGES
|
45
38
|
- MANIFEST
|
46
|
-
files:
|
39
|
+
files:
|
47
40
|
- CHANGES
|
41
|
+
- MANIFEST
|
42
|
+
- README
|
43
|
+
- Rakefile
|
48
44
|
- examples/example_long.rb
|
49
45
|
- examples/example_std.rb
|
50
46
|
- getopt.gemspec
|
51
47
|
- lib/getopt/long.rb
|
52
48
|
- lib/getopt/std.rb
|
53
|
-
- MANIFEST
|
54
|
-
- Rakefile
|
55
|
-
- README
|
56
49
|
- test/test_getopt_long.rb
|
57
50
|
- test/test_getopt_std.rb
|
58
|
-
homepage:
|
59
|
-
licenses:
|
51
|
+
homepage: https://github.com/djberg96/getopt
|
52
|
+
licenses:
|
60
53
|
- Artistic 2.0
|
54
|
+
metadata: {}
|
61
55
|
post_install_message:
|
62
56
|
rdoc_options: []
|
63
|
-
|
64
|
-
require_paths:
|
57
|
+
require_paths:
|
65
58
|
- lib
|
66
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
-
|
68
|
-
requirements:
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
69
61
|
- - ">="
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
version: "0"
|
75
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
|
-
requirements:
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
78
66
|
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
|
81
|
-
segments:
|
82
|
-
- 0
|
83
|
-
version: "0"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
84
69
|
requirements: []
|
85
|
-
|
86
|
-
|
87
|
-
rubygems_version: 1.8.3
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.4.2
|
88
72
|
signing_key:
|
89
|
-
specification_version:
|
73
|
+
specification_version: 4
|
90
74
|
summary: Getopt::Std and Getopt::Long option parsers for Ruby
|
91
|
-
test_files:
|
75
|
+
test_files:
|
92
76
|
- test/test_getopt_long.rb
|
93
77
|
- test/test_getopt_std.rb
|