command_kit 0.1.0.pre2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +15 -0
- data/.rubocop.yml +141 -0
- data/ChangeLog.md +98 -2
- data/Gemfile +3 -0
- data/README.md +189 -117
- data/Rakefile +3 -2
- data/command_kit.gemspec +4 -4
- data/examples/command.rb +1 -1
- data/gemspec.yml +10 -2
- data/lib/command_kit/arguments/argument.rb +2 -0
- data/lib/command_kit/arguments/argument_value.rb +2 -0
- data/lib/command_kit/arguments.rb +23 -4
- data/lib/command_kit/colors.rb +253 -45
- data/lib/command_kit/command.rb +6 -1
- data/lib/command_kit/command_name.rb +9 -0
- data/lib/command_kit/commands/auto_load.rb +24 -1
- data/lib/command_kit/commands/auto_require.rb +16 -0
- data/lib/command_kit/commands/command.rb +3 -0
- data/lib/command_kit/commands/help.rb +5 -2
- data/lib/command_kit/commands/parent_command.rb +7 -0
- data/lib/command_kit/commands/subcommand.rb +13 -1
- data/lib/command_kit/commands.rb +54 -9
- data/lib/command_kit/description.rb +12 -1
- data/lib/command_kit/env/home.rb +9 -0
- data/lib/command_kit/env/path.rb +16 -1
- data/lib/command_kit/env.rb +4 -0
- data/lib/command_kit/examples.rb +12 -1
- data/lib/command_kit/exception_handler.rb +4 -0
- data/lib/command_kit/help/man.rb +26 -30
- data/lib/command_kit/help.rb +7 -1
- data/lib/command_kit/inflector.rb +49 -17
- data/lib/command_kit/interactive.rb +248 -0
- data/lib/command_kit/main.rb +18 -9
- data/lib/command_kit/man.rb +44 -0
- data/lib/command_kit/open_app.rb +69 -0
- data/lib/command_kit/options/option.rb +3 -6
- data/lib/command_kit/options/option_value.rb +5 -2
- data/lib/command_kit/options/parser.rb +46 -19
- data/lib/command_kit/options/quiet.rb +3 -0
- data/lib/command_kit/options/verbose.rb +5 -0
- data/lib/command_kit/options/version.rb +6 -0
- data/lib/command_kit/options.rb +32 -7
- data/lib/command_kit/os/linux.rb +157 -0
- data/lib/command_kit/os.rb +165 -11
- data/lib/command_kit/package_manager.rb +200 -0
- data/lib/command_kit/pager.rb +80 -11
- data/lib/command_kit/printing/indent.rb +27 -4
- data/lib/command_kit/printing.rb +35 -1
- data/lib/command_kit/program_name.rb +7 -0
- data/lib/command_kit/stdio.rb +24 -0
- data/lib/command_kit/sudo.rb +40 -0
- data/lib/command_kit/terminal.rb +159 -0
- data/lib/command_kit/usage.rb +14 -0
- data/lib/command_kit/version.rb +1 -1
- data/lib/command_kit/xdg.rb +13 -0
- data/lib/command_kit.rb +1 -0
- data/spec/arguments/argument_spec.rb +2 -2
- data/spec/arguments_spec.rb +53 -27
- data/spec/colors_spec.rb +277 -13
- data/spec/command_name_spec.rb +1 -1
- data/spec/command_spec.rb +79 -5
- data/spec/commands/auto_load/subcommand_spec.rb +1 -1
- data/spec/commands/auto_load_spec.rb +34 -3
- data/spec/commands/auto_require_spec.rb +2 -2
- data/spec/commands/help_spec.rb +1 -1
- data/spec/commands/parent_command_spec.rb +1 -1
- data/spec/commands/subcommand_spec.rb +1 -1
- data/spec/commands_spec.rb +103 -29
- data/spec/description_spec.rb +1 -25
- data/spec/env/home_spec.rb +1 -1
- data/spec/env/path_spec.rb +7 -1
- data/spec/examples_spec.rb +1 -25
- data/spec/exception_handler_spec.rb +1 -1
- data/spec/help/man_spec.rb +45 -58
- data/spec/help_spec.rb +0 -25
- data/spec/inflector_spec.rb +71 -9
- data/spec/interactive_spec.rb +415 -0
- data/spec/main_spec.rb +7 -7
- data/spec/man_spec.rb +46 -0
- data/spec/open_app_spec.rb +85 -0
- data/spec/options/option_spec.rb +5 -5
- data/spec/options/option_value_spec.rb +56 -1
- data/spec/options_spec.rb +283 -1
- data/spec/os/linux_spec.rb +164 -0
- data/spec/os_spec.rb +201 -14
- data/spec/package_manager_spec.rb +806 -0
- data/spec/pager_spec.rb +76 -11
- data/spec/printing/indent_spec.rb +8 -6
- data/spec/printing_spec.rb +33 -3
- data/spec/program_name_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -3
- data/spec/sudo_spec.rb +51 -0
- data/spec/{console_spec.rb → terminal_spec.rb} +65 -35
- data/spec/usage_spec.rb +2 -2
- data/spec/xdg_spec.rb +1 -1
- metadata +26 -8
- data/lib/command_kit/console.rb +0 -141
data/spec/colors_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'command_kit/colors'
|
3
3
|
|
4
|
-
describe Colors do
|
4
|
+
describe CommandKit::Colors do
|
5
5
|
module TestColors
|
6
6
|
class TestCommand
|
7
7
|
include CommandKit::Colors
|
@@ -11,10 +11,10 @@ describe Colors do
|
|
11
11
|
let(:command_class) { TestColors::TestCommand }
|
12
12
|
subject { command_class.new }
|
13
13
|
|
14
|
-
it { expect(described_class).to include(Stdio) }
|
15
|
-
it { expect(described_class).to include(Env) }
|
14
|
+
it { expect(described_class).to include(CommandKit::Stdio) }
|
15
|
+
it { expect(described_class).to include(CommandKit::Env) }
|
16
16
|
|
17
|
-
describe Colors::ANSI do
|
17
|
+
describe CommandKit::Colors::ANSI do
|
18
18
|
subject { described_class }
|
19
19
|
|
20
20
|
describe "RESET" do
|
@@ -65,6 +65,38 @@ describe Colors do
|
|
65
65
|
it { expect(subject::WHITE).to eq("\e[37m") }
|
66
66
|
end
|
67
67
|
|
68
|
+
describe "ON_BLACK" do
|
69
|
+
it { expect(subject::ON_BLACK).to eq("\e[40m") }
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "ON_RED" do
|
73
|
+
it { expect(subject::ON_RED).to eq("\e[41m") }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "ON_GREEN" do
|
77
|
+
it { expect(subject::ON_GREEN).to eq("\e[42m") }
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "ON_YELLOW" do
|
81
|
+
it { expect(subject::ON_YELLOW).to eq("\e[43m") }
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "ON_BLUE" do
|
85
|
+
it { expect(subject::ON_BLUE).to eq("\e[44m") }
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "ON_MAGENTA" do
|
89
|
+
it { expect(subject::ON_MAGENTA).to eq("\e[45m") }
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "ON_CYAN" do
|
93
|
+
it { expect(subject::ON_CYAN).to eq("\e[46m") }
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "ON_WHITE" do
|
97
|
+
it { expect(subject::ON_WHITE).to eq("\e[47m") }
|
98
|
+
end
|
99
|
+
|
68
100
|
describe "RESET_COLOR" do
|
69
101
|
it { expect(subject::RESET_COLOR).to eq("\e[39m") }
|
70
102
|
end
|
@@ -186,9 +218,105 @@ describe Colors do
|
|
186
218
|
it { expect(subject.white).to eq("\e[37m") }
|
187
219
|
end
|
188
220
|
end
|
221
|
+
|
222
|
+
describe ".on_black" do
|
223
|
+
context "when given a string" do
|
224
|
+
it "must wrap the string with \\e[40m and \\e[39m" do
|
225
|
+
expect(subject.on_black(str)).to eq("\e[40m#{str}\e[49m")
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
context "when given no arguments" do
|
230
|
+
it { expect(subject.on_black).to eq("\e[40m") }
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe ".on_red" do
|
235
|
+
context "when given a string" do
|
236
|
+
it "must wrap the string with \\e[41m and \\e[39m" do
|
237
|
+
expect(subject.on_red(str)).to eq("\e[41m#{str}\e[49m")
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context "when given no arguments" do
|
242
|
+
it { expect(subject.on_red).to eq("\e[41m") }
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe ".on_green" do
|
247
|
+
context "when given a string" do
|
248
|
+
it "must wrap the string with \\e[42m and \\e[39m" do
|
249
|
+
expect(subject.on_green(str)).to eq("\e[42m#{str}\e[49m")
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
context "when given no arguments" do
|
254
|
+
it { expect(subject.on_green).to eq("\e[42m") }
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
describe ".on_yellow" do
|
259
|
+
context "when given a string" do
|
260
|
+
it "must wrap the string with \\e[43m and \\e[39m" do
|
261
|
+
expect(subject.on_yellow(str)).to eq("\e[43m#{str}\e[49m")
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context "when given no arguments" do
|
266
|
+
it { expect(subject.on_yellow).to eq("\e[43m") }
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
describe ".on_blue" do
|
271
|
+
context "when given a string" do
|
272
|
+
it "must wrap the string with \\e[44m and \\e[39m" do
|
273
|
+
expect(subject.on_blue(str)).to eq("\e[44m#{str}\e[49m")
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context "when given no arguments" do
|
278
|
+
it { expect(subject.on_blue).to eq("\e[44m") }
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
describe ".on_magenta" do
|
283
|
+
context "when given a string" do
|
284
|
+
it "must wrap the string with \\e[45m and \\e[39m" do
|
285
|
+
expect(subject.on_magenta(str)).to eq("\e[45m#{str}\e[49m")
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
context "when given no arguments" do
|
290
|
+
it { expect(subject.on_magenta).to eq("\e[45m") }
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
describe ".on_cyan" do
|
295
|
+
context "when given a string" do
|
296
|
+
it "must wrap the string with \\e[46m and \\e[39m" do
|
297
|
+
expect(subject.on_cyan(str)).to eq("\e[46m#{str}\e[49m")
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
context "when given no arguments" do
|
302
|
+
it { expect(subject.on_cyan).to eq("\e[46m") }
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
describe ".on_white" do
|
307
|
+
context "when given a string" do
|
308
|
+
it "must wrap the string with \\e[47m and \\e[39m" do
|
309
|
+
expect(subject.on_white(str)).to eq("\e[47m#{str}\e[49m")
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
context "when given no arguments" do
|
314
|
+
it { expect(subject.on_white).to eq("\e[47m") }
|
315
|
+
end
|
316
|
+
end
|
189
317
|
end
|
190
318
|
|
191
|
-
describe Colors::PlainText do
|
319
|
+
describe CommandKit::Colors::PlainText do
|
192
320
|
subject { described_class }
|
193
321
|
|
194
322
|
let(:str) { 'foo' }
|
@@ -241,6 +369,38 @@ describe Colors do
|
|
241
369
|
it { expect(subject::WHITE).to eq('') }
|
242
370
|
end
|
243
371
|
|
372
|
+
describe "ON_BLACK" do
|
373
|
+
it { expect(subject::ON_BLACK).to eq('') }
|
374
|
+
end
|
375
|
+
|
376
|
+
describe "ON_RED" do
|
377
|
+
it { expect(subject::ON_RED).to eq('') }
|
378
|
+
end
|
379
|
+
|
380
|
+
describe "ON_GREEN" do
|
381
|
+
it { expect(subject::ON_GREEN).to eq('') }
|
382
|
+
end
|
383
|
+
|
384
|
+
describe "ON_YELLOW" do
|
385
|
+
it { expect(subject::ON_YELLOW).to eq('') }
|
386
|
+
end
|
387
|
+
|
388
|
+
describe "ON_BLUE" do
|
389
|
+
it { expect(subject::ON_BLUE).to eq('') }
|
390
|
+
end
|
391
|
+
|
392
|
+
describe "ON_MAGENTA" do
|
393
|
+
it { expect(subject::ON_MAGENTA).to eq('') }
|
394
|
+
end
|
395
|
+
|
396
|
+
describe "ON_CYAN" do
|
397
|
+
it { expect(subject::ON_CYAN).to eq('') }
|
398
|
+
end
|
399
|
+
|
400
|
+
describe "ON_WHITE" do
|
401
|
+
it { expect(subject::ON_WHITE).to eq('') }
|
402
|
+
end
|
403
|
+
|
244
404
|
describe "RESET_COLOR" do
|
245
405
|
it { expect(subject::RESET_COLOR).to eq('') }
|
246
406
|
end
|
@@ -360,6 +520,102 @@ describe Colors do
|
|
360
520
|
it { expect(subject.white).to eq('') }
|
361
521
|
end
|
362
522
|
end
|
523
|
+
|
524
|
+
describe ".on_black" do
|
525
|
+
context "when given a string" do
|
526
|
+
it "must return that string" do
|
527
|
+
expect(subject.on_black(str)).to eq(str)
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
531
|
+
context "when given no arguments" do
|
532
|
+
it { expect(subject.on_black).to eq('') }
|
533
|
+
end
|
534
|
+
end
|
535
|
+
|
536
|
+
describe ".on_red" do
|
537
|
+
context "when given a string" do
|
538
|
+
it "must return that string" do
|
539
|
+
expect(subject.on_red(str)).to eq(str)
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
context "when given no arguments" do
|
544
|
+
it { expect(subject.on_red).to eq('') }
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
describe ".on_green" do
|
549
|
+
context "when given a string" do
|
550
|
+
it "must return that string" do
|
551
|
+
expect(subject.on_green(str)).to eq(str)
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
context "when given no arguments" do
|
556
|
+
it { expect(subject.on_green).to eq('') }
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
describe ".on_yellow" do
|
561
|
+
context "when given a string" do
|
562
|
+
it "must return that string" do
|
563
|
+
expect(subject.on_yellow(str)).to eq(str)
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
567
|
+
context "when given no arguments" do
|
568
|
+
it { expect(subject.on_yellow).to eq('') }
|
569
|
+
end
|
570
|
+
end
|
571
|
+
|
572
|
+
describe ".on_blue" do
|
573
|
+
context "when given a string" do
|
574
|
+
it "must return that string" do
|
575
|
+
expect(subject.on_blue(str)).to eq(str)
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
context "when given no arguments" do
|
580
|
+
it { expect(subject.on_blue).to eq('') }
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
describe ".on_magenta" do
|
585
|
+
context "when given a string" do
|
586
|
+
it "must return that string" do
|
587
|
+
expect(subject.on_magenta(str)).to eq(str)
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
591
|
+
context "when given no arguments" do
|
592
|
+
it { expect(subject.on_magenta).to eq('') }
|
593
|
+
end
|
594
|
+
end
|
595
|
+
|
596
|
+
describe ".on_cyan" do
|
597
|
+
context "when given a string" do
|
598
|
+
it "must return that string" do
|
599
|
+
expect(subject.on_cyan(str)).to eq(str)
|
600
|
+
end
|
601
|
+
end
|
602
|
+
|
603
|
+
context "when given no arguments" do
|
604
|
+
it { expect(subject.on_cyan).to eq('') }
|
605
|
+
end
|
606
|
+
end
|
607
|
+
|
608
|
+
describe ".on_white" do
|
609
|
+
context "when given a string" do
|
610
|
+
it "must return that string" do
|
611
|
+
expect(subject.on_white(str)).to eq(str)
|
612
|
+
end
|
613
|
+
end
|
614
|
+
|
615
|
+
context "when given no arguments" do
|
616
|
+
it { expect(subject.on_white).to eq('') }
|
617
|
+
end
|
618
|
+
end
|
363
619
|
end
|
364
620
|
|
365
621
|
describe "#ansi?" do
|
@@ -409,13 +665,15 @@ describe Colors do
|
|
409
665
|
|
410
666
|
before { allow(stdout).to receive(:tty?).and_return(true) }
|
411
667
|
|
412
|
-
it
|
668
|
+
it do
|
669
|
+
expect(subject.colors).to be(described_class::ANSI)
|
670
|
+
end
|
413
671
|
|
414
672
|
context "when a block is given" do
|
415
673
|
it do
|
416
674
|
expect { |b|
|
417
675
|
subject.colors(&b)
|
418
|
-
}.to yield_with_args(
|
676
|
+
}.to yield_with_args(described_class::ANSI)
|
419
677
|
end
|
420
678
|
end
|
421
679
|
end
|
@@ -424,13 +682,15 @@ describe Colors do
|
|
424
682
|
let(:stdout) { StringIO.new }
|
425
683
|
subject { command_class.new(stdout: stdout) }
|
426
684
|
|
427
|
-
it
|
685
|
+
it do
|
686
|
+
expect(subject.colors).to be(described_class::PlainText)
|
687
|
+
end
|
428
688
|
|
429
689
|
context "when a block is given" do
|
430
690
|
it do
|
431
691
|
expect { |b|
|
432
692
|
subject.colors(&b)
|
433
|
-
}.to yield_with_args(
|
693
|
+
}.to yield_with_args(described_class::PlainText)
|
434
694
|
end
|
435
695
|
end
|
436
696
|
end
|
@@ -441,13 +701,15 @@ describe Colors do
|
|
441
701
|
|
442
702
|
before { allow(stream).to receive(:tty?).and_return(true) }
|
443
703
|
|
444
|
-
it
|
704
|
+
it do
|
705
|
+
expect(subject.colors(stream)).to be(described_class::ANSI)
|
706
|
+
end
|
445
707
|
|
446
708
|
context "when a block is given" do
|
447
709
|
it do
|
448
710
|
expect { |b|
|
449
711
|
subject.colors(stream,&b)
|
450
|
-
}.to yield_with_args(
|
712
|
+
}.to yield_with_args(described_class::ANSI)
|
451
713
|
end
|
452
714
|
end
|
453
715
|
end
|
@@ -455,13 +717,15 @@ describe Colors do
|
|
455
717
|
context "but the alternate stream does not support ANSI" do
|
456
718
|
let(:stream) { StringIO.new }
|
457
719
|
|
458
|
-
it
|
720
|
+
it do
|
721
|
+
expect(subject.colors(stream)).to be(described_class::PlainText)
|
722
|
+
end
|
459
723
|
|
460
724
|
context "when a block is given" do
|
461
725
|
it do
|
462
726
|
expect { |b|
|
463
727
|
subject.colors(stream,&b)
|
464
|
-
}.to yield_with_args(
|
728
|
+
}.to yield_with_args(described_class::PlainText)
|
465
729
|
end
|
466
730
|
end
|
467
731
|
end
|
data/spec/command_name_spec.rb
CHANGED
data/spec/command_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'command_kit/command'
|
3
3
|
|
4
|
-
describe Command do
|
4
|
+
describe CommandKit::Command do
|
5
5
|
it "must include CommandKit::Main" do
|
6
6
|
expect(described_class).to include(CommandKit::Main)
|
7
7
|
end
|
@@ -26,14 +26,14 @@ describe Command do
|
|
26
26
|
expect(described_class).to include(CommandKit::Usage)
|
27
27
|
end
|
28
28
|
|
29
|
-
it "must include CommandKit::Arguments" do
|
30
|
-
expect(described_class).to include(CommandKit::Arguments)
|
31
|
-
end
|
32
|
-
|
33
29
|
it "must include CommandKit::Options" do
|
34
30
|
expect(described_class).to include(CommandKit::Options)
|
35
31
|
end
|
36
32
|
|
33
|
+
it "must include CommandKit::Arguments" do
|
34
|
+
expect(described_class).to include(CommandKit::Arguments)
|
35
|
+
end
|
36
|
+
|
37
37
|
it "must include CommandKit::Examples" do
|
38
38
|
expect(described_class).to include(CommandKit::Examples)
|
39
39
|
end
|
@@ -46,4 +46,78 @@ describe Command do
|
|
46
46
|
expect(described_class).to include(CommandKit::ExceptionHandler)
|
47
47
|
end
|
48
48
|
|
49
|
+
it "must include FileUtils" do
|
50
|
+
expect(described_class).to include(FileUtils)
|
51
|
+
end
|
52
|
+
|
53
|
+
module TestCommandClass
|
54
|
+
class TestCommand < CommandKit::Command
|
55
|
+
|
56
|
+
usage '[OPTIONS] ARG1 [ARG2]'
|
57
|
+
|
58
|
+
option :option1, short: '-a',
|
59
|
+
value: {
|
60
|
+
type: Integer,
|
61
|
+
default: 1
|
62
|
+
},
|
63
|
+
desc: "Option 1"
|
64
|
+
|
65
|
+
option :option2, short: '-b',
|
66
|
+
value: {
|
67
|
+
type: String,
|
68
|
+
usage: 'FILE'
|
69
|
+
},
|
70
|
+
desc: "Option 2"
|
71
|
+
|
72
|
+
argument :argument1, required: true,
|
73
|
+
usage: 'ARG1',
|
74
|
+
desc: "Argument 1"
|
75
|
+
|
76
|
+
argument :argument2, required: false,
|
77
|
+
usage: 'ARG2',
|
78
|
+
desc: "Argument 2"
|
79
|
+
|
80
|
+
examples [
|
81
|
+
'-a 42 foo/bar/baz',
|
82
|
+
'-a 42 -b bar.txt baz qux'
|
83
|
+
]
|
84
|
+
|
85
|
+
description 'Example command'
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
let(:command_class) { TestCommandClass::TestCommand }
|
91
|
+
subject { command_class.new }
|
92
|
+
|
93
|
+
describe "#help" do
|
94
|
+
let(:option1) { command_class.options[:option1] }
|
95
|
+
let(:option2) { command_class.options[:option2] }
|
96
|
+
let(:argument1) { command_class.arguments[:argument1] }
|
97
|
+
let(:argument2) { command_class.arguments[:argument2] }
|
98
|
+
|
99
|
+
it "must print the usage, options, arguments, examples, and description" do
|
100
|
+
expect { subject.help }.to output(
|
101
|
+
[
|
102
|
+
"Usage: #{subject.usage}",
|
103
|
+
'',
|
104
|
+
'Options:',
|
105
|
+
" #{option1.usage.join(', ').ljust(33 - 1)} #{option1.desc}",
|
106
|
+
" #{option2.usage.join(', ').ljust(33 - 1)} #{option2.desc}",
|
107
|
+
' -h, --help Print help information',
|
108
|
+
'',
|
109
|
+
"Arguments:",
|
110
|
+
" #{argument1.usage.ljust(33)}#{argument1.desc}",
|
111
|
+
" #{argument2.usage.ljust(33)}#{argument2.desc}",
|
112
|
+
'',
|
113
|
+
"Examples:",
|
114
|
+
" #{subject.command_name} #{command_class.examples[0]}",
|
115
|
+
" #{subject.command_name} #{command_class.examples[1]}",
|
116
|
+
'',
|
117
|
+
command_class.description,
|
118
|
+
''
|
119
|
+
].join($/)
|
120
|
+
).to_stdout
|
121
|
+
end
|
122
|
+
end
|
49
123
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'command_kit/commands/auto_load/subcommand'
|
3
3
|
|
4
|
-
describe Commands::AutoLoad::Subcommand do
|
4
|
+
describe CommandKit::Commands::AutoLoad::Subcommand do
|
5
5
|
let(:fixtures_dir) { File.expand_path('../../fixtures',__FILE__) }
|
6
6
|
|
7
7
|
let(:file) { 'test1.rb' }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'command_kit/commands/auto_load'
|
3
3
|
|
4
|
-
describe Commands::AutoLoad do
|
4
|
+
describe CommandKit::Commands::AutoLoad do
|
5
5
|
let(:fixtures_dir) { File.expand_path('../fixtures',__FILE__) }
|
6
6
|
|
7
7
|
let(:dir) { File.join(fixtures_dir,'test_auto_load','cli','commands') }
|
@@ -54,16 +54,27 @@ describe Commands::AutoLoad do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
module TestAutoLoad
|
57
|
-
class
|
57
|
+
class TestCommand
|
58
58
|
include CommandKit::Commands
|
59
59
|
include CommandKit::Commands::AutoLoad.new(
|
60
60
|
dir: File.expand_path('../fixtures/test_auto_load/cli/commands',__FILE__),
|
61
61
|
namespace: "#{self}::Commands"
|
62
62
|
)
|
63
63
|
end
|
64
|
+
|
65
|
+
class TestCommandWithBlock
|
66
|
+
include CommandKit::Commands
|
67
|
+
include(CommandKit::Commands::AutoLoad.new(
|
68
|
+
dir: File.expand_path('../fixtures/test_auto_load/cli/commands',__FILE__),
|
69
|
+
namespace: "#{self}::Commands"
|
70
|
+
) { |autoload|
|
71
|
+
autoload.command 'test-1', 'Test1', 'test1.rb', aliases: %w[test_1]
|
72
|
+
autoload.command 'test-2', 'Test2', 'test2.rb', aliases: %w[test_2]
|
73
|
+
})
|
74
|
+
end
|
64
75
|
end
|
65
76
|
|
66
|
-
let(:command_class) { TestAutoLoad::
|
77
|
+
let(:command_class) { TestAutoLoad::TestCommand }
|
67
78
|
let(:autoload_module) { command_class.included_modules.first }
|
68
79
|
|
69
80
|
describe "#included" do
|
@@ -76,6 +87,26 @@ describe Commands::AutoLoad do
|
|
76
87
|
it "must merge the module's #commands into the class'es #commands" do
|
77
88
|
expect(command_class.commands).to include(autoload_module.commands)
|
78
89
|
end
|
90
|
+
|
91
|
+
context "when CommandKit::Commands::AutoLoad has an explicit mapping" do
|
92
|
+
let(:command_class) { TestAutoLoad::TestCommandWithBlock }
|
93
|
+
|
94
|
+
it "must merge the module's #commands into the class'es #commands" do
|
95
|
+
expect(command_class.commands).to include(autoload_module.commands)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "must also merge the any aliases into the class'es #command_aliases" do
|
99
|
+
expected_command_aliases = {}
|
100
|
+
|
101
|
+
autoload_module.commands.each do |name,subcommand|
|
102
|
+
subcommand.aliases.each do |alias_name|
|
103
|
+
expected_command_aliases[alias_name] = name
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
expect(command_class.command_aliases).to include(expected_command_aliases)
|
108
|
+
end
|
109
|
+
end
|
79
110
|
end
|
80
111
|
|
81
112
|
describe "#join" do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'command_kit/commands/auto_require'
|
3
3
|
|
4
|
-
describe Commands::AutoRequire do
|
4
|
+
describe CommandKit::Commands::AutoRequire do
|
5
5
|
let(:fixtures_dir) { File.expand_path('../fixtures',__FILE__) }
|
6
6
|
let(:lib_dir) { File.join(fixtures_dir,'test_auto_require','lib') }
|
7
7
|
let(:dir) { File.join('test_auto_require','cli','commands') }
|
@@ -126,7 +126,7 @@ describe Commands::AutoRequire do
|
|
126
126
|
|
127
127
|
it "the .commands.default_proc must auto-require commands and return a Subcommand" do
|
128
128
|
expect(command_class.commands[command_name]).to_not be(nil)
|
129
|
-
expect(command_class.commands[command_name]).to be_kind_of(Commands::Subcommand)
|
129
|
+
expect(command_class.commands[command_name]).to be_kind_of(CommandKit::Commands::Subcommand)
|
130
130
|
expect(command_class.commands[command_name].command).to eq(TestAutoRequire::CLI::Commands::Test1)
|
131
131
|
end
|
132
132
|
|
data/spec/commands/help_spec.rb
CHANGED