clamp 0.1.4 → 0.1.5
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/README.markdown +1 -1
- data/lib/clamp/option/parsing.rb +9 -0
- data/lib/clamp/version.rb +1 -1
- data/spec/clamp/command_spec.rb +42 -3
- metadata +4 -4
data/README.markdown
CHANGED
@@ -203,7 +203,7 @@ All Clamp commands support a "`--help`" option, which outputs brief usage docume
|
|
203
203
|
|
204
204
|
Options:
|
205
205
|
--loud say it loud
|
206
|
-
-n, --iterations N say it N times
|
206
|
+
-n, --iterations N say it N times (default: 1)
|
207
207
|
--help print help
|
208
208
|
|
209
209
|
Contributing to Clamp
|
data/lib/clamp/option/parsing.rb
CHANGED
@@ -11,6 +11,15 @@ module Clamp
|
|
11
11
|
switch = remaining_arguments.shift
|
12
12
|
break if switch == "--"
|
13
13
|
|
14
|
+
case switch
|
15
|
+
when /^(-\w)(.+)$/ # combined short options
|
16
|
+
switch = $1
|
17
|
+
remaining_arguments.unshift("-#{$2}")
|
18
|
+
when /^(--[^=]+)=(.*)/
|
19
|
+
switch = $1
|
20
|
+
remaining_arguments.unshift($2)
|
21
|
+
end
|
22
|
+
|
14
23
|
option = find_option(switch)
|
15
24
|
value = option.extract_value(switch, remaining_arguments)
|
16
25
|
|
data/lib/clamp/version.rb
CHANGED
data/spec/clamp/command_spec.rb
CHANGED
@@ -122,9 +122,9 @@ describe Clamp::Command do
|
|
122
122
|
describe "with options declared" do
|
123
123
|
|
124
124
|
before do
|
125
|
-
@command.class.option "--flavour", "FLAVOUR", "Flavour of the month"
|
126
|
-
@command.class.option "--color", "COLOR", "Preferred hue"
|
127
|
-
@command.class.option "--[no-]nuts", :flag, "Nuts (or not)"
|
125
|
+
@command.class.option ["-f", "--flavour"], "FLAVOUR", "Flavour of the month"
|
126
|
+
@command.class.option ["-c", "--color"], "COLOR", "Preferred hue"
|
127
|
+
@command.class.option ["-n", "--[no-]nuts"], :flag, "Nuts (or not)"
|
128
128
|
@command.class.parameter "[ARG] ...", "extra arguments", :attribute_name => :arguments
|
129
129
|
end
|
130
130
|
|
@@ -154,6 +154,45 @@ describe Clamp::Command do
|
|
154
154
|
|
155
155
|
end
|
156
156
|
|
157
|
+
describe "with short options" do
|
158
|
+
|
159
|
+
before do
|
160
|
+
@command.parse(%w(-f strawberry -c blue))
|
161
|
+
end
|
162
|
+
|
163
|
+
it "recognises short options as aliases" do
|
164
|
+
@command.flavour.should == "strawberry"
|
165
|
+
@command.color.should == "blue"
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "with combined short options" do
|
171
|
+
|
172
|
+
before do
|
173
|
+
@command.parse(%w(-nf strawberry))
|
174
|
+
end
|
175
|
+
|
176
|
+
it "works as though the options were separate" do
|
177
|
+
@command.flavour.should == "strawberry"
|
178
|
+
@command.nuts?.should == true
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "with option arguments attached using equals sign" do
|
184
|
+
|
185
|
+
before do
|
186
|
+
@command.parse(%w(--flavour=strawberry --color=blue))
|
187
|
+
end
|
188
|
+
|
189
|
+
it "works as though the option arguments were separate" do
|
190
|
+
@command.flavour.should == "strawberry"
|
191
|
+
@command.color.should == "blue"
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
157
196
|
describe "with option-like things beyond the arguments" do
|
158
197
|
|
159
198
|
it "treats them as positional arguments" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mike Williams
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-02 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|