clamp 1.3.2 → 1.3.3
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.
- checksums.yaml +4 -4
- data/.editorconfig +1 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +12 -8
- data/.travis.yml +2 -1
- data/CHANGES.md +4 -0
- data/CODEOWNERS +1 -0
- data/Gemfile +8 -5
- data/Guardfile +2 -2
- data/Rakefile +1 -3
- data/clamp.gemspec +2 -1
- data/lib/clamp/attribute/declaration.rb +1 -0
- data/lib/clamp/attribute/definition.rb +4 -2
- data/lib/clamp/attribute/instance.rb +2 -1
- data/lib/clamp/help.rb +4 -5
- data/lib/clamp/messages.rb +3 -3
- data/lib/clamp/option/declaration.rb +2 -0
- data/lib/clamp/option/definition.rb +10 -5
- data/lib/clamp/option/parsing.rb +8 -3
- data/lib/clamp/parameter/declaration.rb +3 -0
- data/lib/clamp/parameter/definition.rb +8 -5
- data/lib/clamp/parameter/parsing.rb +4 -6
- data/lib/clamp/subcommand/declaration.rb +3 -1
- data/lib/clamp/subcommand/execution.rb +2 -0
- data/lib/clamp/subcommand/parsing.rb +1 -0
- data/lib/clamp/truthy.rb +1 -1
- data/lib/clamp/version.rb +1 -1
- data/spec/clamp/command_group_spec.rb +64 -45
- data/spec/clamp/{option_module_spec.rb → command_option_module_spec.rb} +2 -1
- data/spec/clamp/{option_reordering_spec.rb → command_option_reordering_spec.rb} +3 -3
- data/spec/clamp/command_spec.rb +364 -148
- data/spec/clamp/{help_spec.rb → help/builder_spec.rb} +22 -4
- data/spec/clamp/messages_spec.rb +11 -6
- data/spec/clamp/option/definition_spec.rb +92 -40
- data/spec/clamp/parameter/definition_spec.rb +120 -50
- data/spec/spec_helper.rb +5 -6
- metadata +14 -21
@@ -29,17 +29,27 @@ describe Clamp::Command do
|
|
29
29
|
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
describe "flip command" do
|
33
|
+
before do
|
34
|
+
command.run(["flip"])
|
35
|
+
end
|
33
36
|
|
34
|
-
|
35
|
-
|
37
|
+
it "delegates to sub-commands" do
|
38
|
+
expect(stdout).to match(/FLIPPED/)
|
39
|
+
end
|
40
|
+
end
|
36
41
|
|
37
|
-
|
38
|
-
|
42
|
+
describe "flop command" do
|
43
|
+
before do
|
44
|
+
command.run(["flop"])
|
45
|
+
end
|
39
46
|
|
47
|
+
it "delegates to sub-commands" do
|
48
|
+
expect(stdout).to match(/FLOPPED/)
|
49
|
+
end
|
40
50
|
end
|
41
51
|
|
42
|
-
context "executed with no subcommand" do
|
52
|
+
context "when executed with no subcommand" do
|
43
53
|
|
44
54
|
it "triggers help" do
|
45
55
|
expect do
|
@@ -56,10 +66,7 @@ describe Clamp::Command do
|
|
56
66
|
end
|
57
67
|
|
58
68
|
it "lists subcommands" do
|
59
|
-
help
|
60
|
-
expect(help).to match(/Subcommands:/)
|
61
|
-
expect(help).to match(/flip +flip it/)
|
62
|
-
expect(help).to match(/flop +flop it/)
|
69
|
+
expect(command.help).to match(/Subcommands:\n +flip +flip it\n +flop +flop it/)
|
63
70
|
end
|
64
71
|
|
65
72
|
it "handles new lines in subcommand descriptions" do
|
@@ -95,13 +102,27 @@ describe Clamp::Command do
|
|
95
102
|
|
96
103
|
end
|
97
104
|
|
98
|
-
|
105
|
+
describe "the first alias" do
|
106
|
+
|
107
|
+
before do
|
108
|
+
command.run(["say", "boo"])
|
109
|
+
end
|
110
|
+
|
111
|
+
it "responds to it" do
|
112
|
+
expect(stdout).to match(/boo/)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "the second alias" do
|
99
118
|
|
100
|
-
|
101
|
-
|
119
|
+
before do
|
120
|
+
command.run(["talk", "jive"])
|
121
|
+
end
|
102
122
|
|
103
|
-
|
104
|
-
|
123
|
+
it "responds to it" do
|
124
|
+
expect(stdout).to match(/jive/)
|
125
|
+
end
|
105
126
|
|
106
127
|
end
|
107
128
|
|
@@ -167,7 +188,7 @@ describe Clamp::Command do
|
|
167
188
|
|
168
189
|
end
|
169
190
|
|
170
|
-
context "executed with no subcommand" do
|
191
|
+
context "when executed with no subcommand" do
|
171
192
|
|
172
193
|
it "invokes the default subcommand" do
|
173
194
|
command.run([])
|
@@ -192,7 +213,7 @@ describe Clamp::Command do
|
|
192
213
|
|
193
214
|
end
|
194
215
|
|
195
|
-
context "executed with no subcommand" do
|
216
|
+
context "when executed with no subcommand" do
|
196
217
|
|
197
218
|
it "invokes the default subcommand" do
|
198
219
|
command.run([])
|
@@ -203,24 +224,26 @@ describe Clamp::Command do
|
|
203
224
|
|
204
225
|
end
|
205
226
|
|
206
|
-
context "declaring a default subcommand after subcommands" do
|
227
|
+
context "when declaring a default subcommand after subcommands" do
|
207
228
|
|
208
|
-
|
229
|
+
let(:command) do
|
230
|
+
Class.new(Clamp::Command) do
|
209
231
|
|
210
|
-
|
211
|
-
Class.new(Clamp::Command) do
|
232
|
+
subcommand "status", "Show status" do
|
212
233
|
|
213
|
-
|
234
|
+
def execute
|
235
|
+
puts "All good!"
|
236
|
+
end
|
214
237
|
|
215
|
-
|
216
|
-
puts "All good!"
|
217
|
-
end
|
238
|
+
end
|
218
239
|
|
219
|
-
|
240
|
+
end
|
241
|
+
end
|
220
242
|
|
221
|
-
|
243
|
+
it "is not supported" do
|
222
244
|
|
223
|
-
|
245
|
+
expect do
|
246
|
+
command.default_subcommand = "status"
|
224
247
|
end.to raise_error(/default_subcommand must be defined before subcommands/)
|
225
248
|
|
226
249
|
end
|
@@ -251,20 +274,18 @@ describe Clamp::Command do
|
|
251
274
|
|
252
275
|
it "allows the parameter to be specified first" do
|
253
276
|
command.run(["dummy", "spit"])
|
254
|
-
expect(stdout.strip).to
|
277
|
+
expect(stdout.strip).to eq "spat the dummy"
|
255
278
|
end
|
256
279
|
|
257
280
|
it "passes the parameter down the stack" do
|
258
281
|
command.run(["money", "say", "loud"])
|
259
|
-
expect(stdout.strip).to
|
282
|
+
expect(stdout.strip).to eq "MONEY"
|
260
283
|
end
|
261
284
|
|
262
285
|
it "shows parameter in usage help" do
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
expect(e.command.invocation_path).to eql("with THING say loud")
|
267
|
-
end
|
286
|
+
command.run(["stuff", "say", "loud", "--help"])
|
287
|
+
rescue Clamp::HelpWanted => e
|
288
|
+
expect(e.command.invocation_path).to eq "with THING say loud"
|
268
289
|
end
|
269
290
|
|
270
291
|
end
|
@@ -275,6 +296,7 @@ describe Clamp::Command do
|
|
275
296
|
|
276
297
|
speed_options = Module.new do
|
277
298
|
extend Clamp::Option::Declaration
|
299
|
+
|
278
300
|
option "--speed", "SPEED", "how fast", default: "slowly"
|
279
301
|
end
|
280
302
|
|
@@ -338,7 +360,7 @@ describe Clamp::Command do
|
|
338
360
|
|
339
361
|
it "only parses options once" do
|
340
362
|
command.run(["--json", '{"a":"b"}', "woohoohoo"])
|
341
|
-
expect(stdout).to
|
363
|
+
expect(stdout).to eq "parsing!"
|
342
364
|
end
|
343
365
|
|
344
366
|
end
|
@@ -378,19 +400,16 @@ describe Clamp::Command do
|
|
378
400
|
command_class.new("foo")
|
379
401
|
end
|
380
402
|
|
381
|
-
it "
|
382
|
-
expect { command.run(["foo"]) }.to raise_error(Clamp::UsageError
|
383
|
-
expect(exception.message).to eq "No such sub-command 'foo'"
|
384
|
-
end
|
403
|
+
it "signals no such subcommand usage error" do
|
404
|
+
expect { command.run(["foo"]) }.to raise_error(Clamp::UsageError, "No such sub-command 'foo'")
|
385
405
|
end
|
386
406
|
|
387
|
-
it "
|
407
|
+
it "executes the subcommand missing method" do
|
388
408
|
command.extend subcommand_missing
|
389
|
-
expect { command.run(["foo"]) }.to raise_error(SystemExit)
|
390
|
-
expect(stderr).to match(/there is no such thing/)
|
409
|
+
expect { command.run(["foo"]) }.to raise_error(SystemExit, /there is no such thing/)
|
391
410
|
end
|
392
411
|
|
393
|
-
it "
|
412
|
+
it "uses the subcommand class returned from subcommand_missing" do
|
394
413
|
command.extend subcommand_missing_with_return
|
395
414
|
command.run(["foo"])
|
396
415
|
expect(stdout).to match(/known subcommand/)
|
@@ -411,7 +430,7 @@ describe Clamp::Command do
|
|
411
430
|
|
412
431
|
it "allows options after the subcommand" do
|
413
432
|
command.run(%w[hop --direction south])
|
414
|
-
expect(stdout).to
|
433
|
+
expect(stdout).to eq "Hopping south\n"
|
415
434
|
end
|
416
435
|
|
417
436
|
end
|
@@ -12,6 +12,7 @@ describe Clamp::Command do
|
|
12
12
|
|
13
13
|
shared_options = Module.new do
|
14
14
|
extend Clamp::Option::Declaration
|
15
|
+
|
15
16
|
option "--size", "SIZE", default: 4
|
16
17
|
end
|
17
18
|
|
@@ -31,7 +32,7 @@ describe Clamp::Command do
|
|
31
32
|
|
32
33
|
it "accepts options from included module" do
|
33
34
|
command.run(["--size", "42"])
|
34
|
-
expect(stdout).to
|
35
|
+
expect(stdout).to eq "size = 42\n"
|
35
36
|
end
|
36
37
|
|
37
38
|
end
|
@@ -40,17 +40,17 @@ describe Clamp::Command do
|
|
40
40
|
|
41
41
|
it "still works" do
|
42
42
|
command.run(%w[say foo])
|
43
|
-
expect(stdout).to
|
43
|
+
expect(stdout).to eq "foo\n"
|
44
44
|
end
|
45
45
|
|
46
46
|
it "honours options after positional arguments" do
|
47
47
|
command.run(%w[say blah --verbose])
|
48
|
-
expect(stdout).to
|
48
|
+
expect(stdout).to eq "blahblahblah\n"
|
49
49
|
end
|
50
50
|
|
51
51
|
it "honours options declared on subcommands" do
|
52
52
|
command.run(%w[say --loud blah])
|
53
|
-
expect(stdout).to
|
53
|
+
expect(stdout).to eq "BLAH\n"
|
54
54
|
end
|
55
55
|
|
56
56
|
end
|