getoptions 0.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/{README → README.txt} +0 -0
- data/lib/getoptions.rb +1 -1
- data/test/standard.rb +32 -0
- metadata +44 -35
data/History.txt
ADDED
data/{README → README.txt}
RENAMED
File without changes
|
data/lib/getoptions.rb
CHANGED
@@ -191,7 +191,7 @@ class GetOptions
|
|
191
191
|
|
192
192
|
case
|
193
193
|
when @options.has_key?(sym); @options[sym]
|
194
|
-
when @dict.has_key?(key); nil
|
194
|
+
when @dict.has_key?(key); (@dict[key].option_type == :increment) ? 0 : nil
|
195
195
|
else raise ParseError.new("program tried to access an unknown option: #{key.inspect}")
|
196
196
|
end
|
197
197
|
end
|
data/test/standard.rb
CHANGED
@@ -58,6 +58,20 @@ describe GetOptions do
|
|
58
58
|
opt.flag.should eql(false)
|
59
59
|
end
|
60
60
|
|
61
|
+
# Increment tests
|
62
|
+
it "should treat absense of option as 0 count" do
|
63
|
+
opt = GetOptions.new(%w(incr+), %w())
|
64
|
+
opt.incr.should eql(0)
|
65
|
+
end
|
66
|
+
it "should count options, 1 count" do
|
67
|
+
opt = GetOptions.new(%w(incr+), %w(-i))
|
68
|
+
opt.incr.should eql(1)
|
69
|
+
end
|
70
|
+
it "should count options, 5 count" do
|
71
|
+
opt = GetOptions.new(%w(incr+), %w(-iiiii))
|
72
|
+
opt.incr.should eql(5)
|
73
|
+
end
|
74
|
+
|
61
75
|
# List tests
|
62
76
|
it "should parse a list of strings" do
|
63
77
|
opt = GetOptions.new(%w(list=@s), %w(--list foo bar --li baz -l qux))
|
@@ -90,6 +104,24 @@ describe GetOptions do
|
|
90
104
|
}.should raise_error(GetOptions::ParseError, /expecting float value/)
|
91
105
|
end
|
92
106
|
|
107
|
+
# Each / Enumerable tests
|
108
|
+
it "should be able to use .each to iterate over options" do
|
109
|
+
opt = GetOptions.new(%w(foo bar baz qux), %w(--foo --bar --qux))
|
110
|
+
a = []
|
111
|
+
opt.each do |k,o|
|
112
|
+
a << "#{k},#{o}"
|
113
|
+
end
|
114
|
+
a.should(equ(%w(bar=true qux=true foo=true)))
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should be able to use .collect to collect options matching certain criteria" do
|
118
|
+
opt = GetOptions.new(%w(a+ b+ c+), %w(-aaa -bbbb -ccccc))
|
119
|
+
a = opt.collect do |k,o|
|
120
|
+
(k =~ /a|b/) ? o : 0
|
121
|
+
end
|
122
|
+
a.sort.should equ([0,3,4])
|
123
|
+
end
|
124
|
+
|
93
125
|
# Optional argument tests
|
94
126
|
it "should parse an optional string argument" do
|
95
127
|
opt = GetOptions.new(%w(string:s), %w(--str))
|
metadata
CHANGED
@@ -1,48 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: getoptions
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "0.
|
7
|
-
date: 2007-11-30 00:00:00 -08:00
|
8
|
-
summary: Yet another command line option parser in Ruby, based on Perl's Getopt::Long module.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: dparker @nospam@ liveops.com
|
12
|
-
homepage:
|
13
|
-
rubyforge_project:
|
14
|
-
description:
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: "0.2"
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Delaney Parker
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
- README
|
35
|
-
test_files:
|
36
|
-
- test/standard.rb
|
37
|
-
rdoc_options: []
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
38
11
|
|
39
|
-
|
40
|
-
|
12
|
+
date: 2009-01-14 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: dparker @nospam@ liveops.com
|
41
18
|
executables: []
|
42
19
|
|
43
20
|
extensions: []
|
44
21
|
|
45
|
-
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.txt
|
24
|
+
- History.txt
|
25
|
+
files:
|
26
|
+
- lib/getoptions.rb
|
27
|
+
- test/standard.rb
|
28
|
+
- README.txt
|
29
|
+
- History.txt
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://rubyforge.org/projects/getoptions/
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
46
34
|
|
47
|
-
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
version:
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
requirements: []
|
48
50
|
|
51
|
+
rubyforge_project: http://rubyforge.org/projects/getoptions/
|
52
|
+
rubygems_version: 1.0.1
|
53
|
+
signing_key:
|
54
|
+
specification_version: 2
|
55
|
+
summary: Yet another command line option parser in Ruby, based on Perl's Getopt::Long module.
|
56
|
+
test_files:
|
57
|
+
- test/standard.rb
|