command_kit 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +18 -3
  3. data/.rubocop.yml +141 -0
  4. data/ChangeLog.md +165 -0
  5. data/Gemfile +3 -0
  6. data/README.md +186 -118
  7. data/Rakefile +3 -2
  8. data/command_kit.gemspec +4 -4
  9. data/examples/command.rb +1 -1
  10. data/gemspec.yml +7 -0
  11. data/lib/command_kit/arguments/argument.rb +2 -2
  12. data/lib/command_kit/arguments.rb +36 -7
  13. data/lib/command_kit/colors.rb +702 -53
  14. data/lib/command_kit/command.rb +2 -3
  15. data/lib/command_kit/commands/auto_load.rb +8 -1
  16. data/lib/command_kit/commands/help.rb +3 -2
  17. data/lib/command_kit/commands/subcommand.rb +1 -1
  18. data/lib/command_kit/commands.rb +24 -9
  19. data/lib/command_kit/env/path.rb +1 -1
  20. data/lib/command_kit/file_utils.rb +46 -0
  21. data/lib/command_kit/help/man.rb +17 -33
  22. data/lib/command_kit/inflector.rb +47 -17
  23. data/lib/command_kit/interactive.rb +9 -0
  24. data/lib/command_kit/main.rb +7 -9
  25. data/lib/command_kit/man.rb +44 -0
  26. data/lib/command_kit/open_app.rb +69 -0
  27. data/lib/command_kit/options/option.rb +41 -27
  28. data/lib/command_kit/options/option_value.rb +3 -2
  29. data/lib/command_kit/options/parser.rb +17 -22
  30. data/lib/command_kit/options.rb +102 -14
  31. data/lib/command_kit/os/linux.rb +157 -0
  32. data/lib/command_kit/os.rb +159 -11
  33. data/lib/command_kit/package_manager.rb +200 -0
  34. data/lib/command_kit/pager.rb +46 -4
  35. data/lib/command_kit/printing/indent.rb +4 -4
  36. data/lib/command_kit/printing.rb +14 -3
  37. data/lib/command_kit/program_name.rb +9 -0
  38. data/lib/command_kit/sudo.rb +40 -0
  39. data/lib/command_kit/terminal.rb +5 -0
  40. data/lib/command_kit/version.rb +1 -1
  41. data/spec/arguments/argument_spec.rb +1 -1
  42. data/spec/arguments_spec.rb +84 -1
  43. data/spec/colors_spec.rb +357 -70
  44. data/spec/command_spec.rb +77 -6
  45. data/spec/commands/auto_load_spec.rb +33 -2
  46. data/spec/commands_spec.rb +101 -29
  47. data/spec/env/path_spec.rb +6 -0
  48. data/spec/exception_handler_spec.rb +1 -1
  49. data/spec/file_utils_spec.rb +59 -0
  50. data/spec/fixtures/template.erb +5 -0
  51. data/spec/help/man_spec.rb +54 -57
  52. data/spec/inflector_spec.rb +70 -8
  53. data/spec/man_spec.rb +46 -0
  54. data/spec/open_app_spec.rb +85 -0
  55. data/spec/options/option_spec.rb +38 -2
  56. data/spec/options/option_value_spec.rb +55 -0
  57. data/spec/options/parser_spec.rb +0 -10
  58. data/spec/options_spec.rb +328 -0
  59. data/spec/os/linux_spec.rb +164 -0
  60. data/spec/os_spec.rb +200 -13
  61. data/spec/package_manager_spec.rb +806 -0
  62. data/spec/pager_spec.rb +71 -6
  63. data/spec/printing/indent_spec.rb +7 -5
  64. data/spec/printing_spec.rb +23 -1
  65. data/spec/program_name_spec.rb +8 -0
  66. data/spec/sudo_spec.rb +51 -0
  67. data/spec/terminal_spec.rb +30 -0
  68. data/spec/usage_spec.rb +1 -1
  69. metadata +23 -4
data/spec/colors_spec.rb CHANGED
@@ -65,6 +65,106 @@ describe CommandKit::Colors do
65
65
  it { expect(subject::WHITE).to eq("\e[37m") }
66
66
  end
67
67
 
68
+ describe "BRIGHT_BLACK" do
69
+ it { expect(subject::BRIGHT_BLACK).to eq("\e[90m") }
70
+ end
71
+
72
+ describe "BRIGHT_RED" do
73
+ it { expect(subject::BRIGHT_RED).to eq("\e[91m") }
74
+ end
75
+
76
+ describe "BRIGHT_GREEN" do
77
+ it { expect(subject::BRIGHT_GREEN).to eq("\e[92m") }
78
+ end
79
+
80
+ describe "BRIGHT_YELLOW" do
81
+ it { expect(subject::BRIGHT_YELLOW).to eq("\e[93m") }
82
+ end
83
+
84
+ describe "BRIGHT_BLUE" do
85
+ it { expect(subject::BRIGHT_BLUE).to eq("\e[94m") }
86
+ end
87
+
88
+ describe "BRIGHT_MAGENTA" do
89
+ it { expect(subject::BRIGHT_MAGENTA).to eq("\e[95m") }
90
+ end
91
+
92
+ describe "BRIGHT_CYAN" do
93
+ it { expect(subject::BRIGHT_CYAN).to eq("\e[96m") }
94
+ end
95
+
96
+ describe "BRIGHT_WHITE" do
97
+ it { expect(subject::BRIGHT_WHITE).to eq("\e[97m") }
98
+ end
99
+
100
+ describe "ON_BLACK" do
101
+ it { expect(subject::ON_BLACK).to eq("\e[40m") }
102
+ end
103
+
104
+ describe "ON_RED" do
105
+ it { expect(subject::ON_RED).to eq("\e[41m") }
106
+ end
107
+
108
+ describe "ON_GREEN" do
109
+ it { expect(subject::ON_GREEN).to eq("\e[42m") }
110
+ end
111
+
112
+ describe "ON_YELLOW" do
113
+ it { expect(subject::ON_YELLOW).to eq("\e[43m") }
114
+ end
115
+
116
+ describe "ON_BLUE" do
117
+ it { expect(subject::ON_BLUE).to eq("\e[44m") }
118
+ end
119
+
120
+ describe "ON_MAGENTA" do
121
+ it { expect(subject::ON_MAGENTA).to eq("\e[45m") }
122
+ end
123
+
124
+ describe "ON_CYAN" do
125
+ it { expect(subject::ON_CYAN).to eq("\e[46m") }
126
+ end
127
+
128
+ describe "ON_WHITE" do
129
+ it { expect(subject::ON_WHITE).to eq("\e[47m") }
130
+ end
131
+
132
+ describe "ON_BRIGHT_BLACK" do
133
+ it { expect(subject::ON_BRIGHT_BLACK).to eq("\e[100m") }
134
+ end
135
+
136
+ describe "ON_BRIGHT_RED" do
137
+ it { expect(subject::ON_BRIGHT_RED).to eq("\e[101m") }
138
+ end
139
+
140
+ describe "ON_BRIGHT_GREEN" do
141
+ it { expect(subject::ON_BRIGHT_GREEN).to eq("\e[102m") }
142
+ end
143
+
144
+ describe "ON_BRIGHT_YELLOW" do
145
+ it { expect(subject::ON_BRIGHT_YELLOW).to eq("\e[103m") }
146
+ end
147
+
148
+ describe "ON_BRIGHT_BLUE" do
149
+ it { expect(subject::ON_BRIGHT_BLUE).to eq("\e[104m") }
150
+ end
151
+
152
+ describe "ON_BRIGHT_MAGENTA" do
153
+ it { expect(subject::ON_BRIGHT_MAGENTA).to eq("\e[105m") }
154
+ end
155
+
156
+ describe "ON_BRIGHT_CYAN" do
157
+ it { expect(subject::ON_BRIGHT_CYAN).to eq("\e[106m") }
158
+ end
159
+
160
+ describe "ON_BRIGHT_WHITE" do
161
+ it { expect(subject::ON_BRIGHT_WHITE).to eq("\e[107m") }
162
+ end
163
+
164
+ describe "RESET_FG" do
165
+ it { expect(subject::RESET_FG).to eq("\e[39m") }
166
+ end
167
+
68
168
  describe "RESET_COLOR" do
69
169
  it { expect(subject::RESET_COLOR).to eq("\e[39m") }
70
170
  end
@@ -186,178 +286,365 @@ describe CommandKit::Colors do
186
286
  it { expect(subject.white).to eq("\e[37m") }
187
287
  end
188
288
  end
189
- end
190
289
 
191
- describe CommandKit::Colors::PlainText do
192
- subject { described_class }
290
+ describe ".bright_black" do
291
+ context "when given a string" do
292
+ it "must wrap the string with \\e[90m and \\e[39m" do
293
+ expect(subject.bright_black(str)).to eq("\e[90m#{str}\e[39m")
294
+ end
295
+ end
193
296
 
194
- let(:str) { 'foo' }
297
+ context "when given no arguments" do
298
+ it { expect(subject.bright_black).to eq("\e[90m") }
299
+ end
300
+ end
195
301
 
196
- describe "RESET" do
197
- it { expect(subject::RESET).to eq('') }
302
+ describe ".gray" do
303
+ context "when given a string" do
304
+ it "must wrap the string with \\e[90m and \\e[39m" do
305
+ expect(subject.gray(str)).to eq("\e[90m#{str}\e[39m")
306
+ end
307
+ end
308
+
309
+ context "when given no arguments" do
310
+ it { expect(subject.gray).to eq("\e[90m") }
311
+ end
198
312
  end
199
313
 
200
- describe "CLEAR" do
201
- it { expect(subject::CLEAR).to eq('') }
314
+ describe ".bright_red" do
315
+ context "when given a string" do
316
+ it "must wrap the string with \\e[91m and \\e[39m" do
317
+ expect(subject.bright_red(str)).to eq("\e[91m#{str}\e[39m")
318
+ end
319
+ end
320
+
321
+ context "when given no arguments" do
322
+ it { expect(subject.bright_red).to eq("\e[91m") }
323
+ end
202
324
  end
203
325
 
204
- describe "BOLD" do
205
- it { expect(subject::BOLD).to eq('') }
326
+ describe ".bright_green" do
327
+ context "when given a string" do
328
+ it "must wrap the string with \\e[92m and \\e[39m" do
329
+ expect(subject.bright_green(str)).to eq("\e[92m#{str}\e[39m")
330
+ end
331
+ end
332
+
333
+ context "when given no arguments" do
334
+ it { expect(subject.bright_green).to eq("\e[92m") }
335
+ end
206
336
  end
207
337
 
208
- describe "RESET_INTENSITY" do
209
- it { expect(subject::RESET_INTENSITY).to eq('') }
338
+ describe ".bright_yellow" do
339
+ context "when given a string" do
340
+ it "must wrap the string with \\e[93m and \\e[39m" do
341
+ expect(subject.bright_yellow(str)).to eq("\e[93m#{str}\e[39m")
342
+ end
343
+ end
344
+
345
+ context "when given no arguments" do
346
+ it { expect(subject.bright_yellow).to eq("\e[93m") }
347
+ end
210
348
  end
211
349
 
212
- describe "BLACK" do
213
- it { expect(subject::BLACK).to eq('') }
350
+ describe ".bright_blue" do
351
+ context "when given a string" do
352
+ it "must wrap the string with \\e[94m and \\e[39m" do
353
+ expect(subject.bright_blue(str)).to eq("\e[94m#{str}\e[39m")
354
+ end
355
+ end
356
+
357
+ context "when given no arguments" do
358
+ it { expect(subject.bright_blue).to eq("\e[94m") }
359
+ end
214
360
  end
215
361
 
216
- describe "RED" do
217
- it { expect(subject::RED).to eq('') }
362
+ describe ".bright_magenta" do
363
+ context "when given a string" do
364
+ it "must wrap the string with \\e[95m and \\e[39m" do
365
+ expect(subject.bright_magenta(str)).to eq("\e[95m#{str}\e[39m")
366
+ end
367
+ end
368
+
369
+ context "when given no arguments" do
370
+ it { expect(subject.bright_magenta).to eq("\e[95m") }
371
+ end
218
372
  end
219
373
 
220
- describe "GREEN" do
221
- it { expect(subject::GREEN).to eq('') }
374
+ describe ".bright_cyan" do
375
+ context "when given a string" do
376
+ it "must wrap the string with \\e[96m and \\e[39m" do
377
+ expect(subject.bright_cyan(str)).to eq("\e[96m#{str}\e[39m")
378
+ end
379
+ end
380
+
381
+ context "when given no arguments" do
382
+ it { expect(subject.bright_cyan).to eq("\e[96m") }
383
+ end
222
384
  end
223
385
 
224
- describe "YELLOW" do
225
- it { expect(subject::YELLOW).to eq('') }
386
+ describe ".bright_white" do
387
+ context "when given a string" do
388
+ it "must wrap the string with \\e[97m and \\e[39m" do
389
+ expect(subject.bright_white(str)).to eq("\e[97m#{str}\e[39m")
390
+ end
391
+ end
392
+
393
+ context "when given no arguments" do
394
+ it { expect(subject.bright_white).to eq("\e[97m") }
395
+ end
226
396
  end
227
397
 
228
- describe "BLUE" do
229
- it { expect(subject::BLUE).to eq('') }
398
+ describe ".on_black" do
399
+ context "when given a string" do
400
+ it "must wrap the string with \\e[40m and \\e[39m" do
401
+ expect(subject.on_black(str)).to eq("\e[40m#{str}\e[49m")
402
+ end
403
+ end
404
+
405
+ context "when given no arguments" do
406
+ it { expect(subject.on_black).to eq("\e[40m") }
407
+ end
230
408
  end
231
409
 
232
- describe "MAGENTA" do
233
- it { expect(subject::MAGENTA).to eq('') }
410
+ describe ".on_red" do
411
+ context "when given a string" do
412
+ it "must wrap the string with \\e[41m and \\e[39m" do
413
+ expect(subject.on_red(str)).to eq("\e[41m#{str}\e[49m")
414
+ end
415
+ end
416
+
417
+ context "when given no arguments" do
418
+ it { expect(subject.on_red).to eq("\e[41m") }
419
+ end
234
420
  end
235
421
 
236
- describe "CYAN" do
237
- it { expect(subject::CYAN).to eq('') }
422
+ describe ".on_green" do
423
+ context "when given a string" do
424
+ it "must wrap the string with \\e[42m and \\e[39m" do
425
+ expect(subject.on_green(str)).to eq("\e[42m#{str}\e[49m")
426
+ end
427
+ end
428
+
429
+ context "when given no arguments" do
430
+ it { expect(subject.on_green).to eq("\e[42m") }
431
+ end
238
432
  end
239
433
 
240
- describe "WHITE" do
241
- it { expect(subject::WHITE).to eq('') }
434
+ describe ".on_yellow" do
435
+ context "when given a string" do
436
+ it "must wrap the string with \\e[43m and \\e[39m" do
437
+ expect(subject.on_yellow(str)).to eq("\e[43m#{str}\e[49m")
438
+ end
439
+ end
440
+
441
+ context "when given no arguments" do
442
+ it { expect(subject.on_yellow).to eq("\e[43m") }
443
+ end
242
444
  end
243
445
 
244
- describe "RESET_COLOR" do
245
- it { expect(subject::RESET_COLOR).to eq('') }
446
+ describe ".on_blue" do
447
+ context "when given a string" do
448
+ it "must wrap the string with \\e[44m and \\e[39m" do
449
+ expect(subject.on_blue(str)).to eq("\e[44m#{str}\e[49m")
450
+ end
451
+ end
452
+
453
+ context "when given no arguments" do
454
+ it { expect(subject.on_blue).to eq("\e[44m") }
455
+ end
246
456
  end
247
457
 
248
- describe ".reset" do
249
- it { expect(subject.reset).to eq('') }
458
+ describe ".on_magenta" do
459
+ context "when given a string" do
460
+ it "must wrap the string with \\e[45m and \\e[39m" do
461
+ expect(subject.on_magenta(str)).to eq("\e[45m#{str}\e[49m")
462
+ end
463
+ end
464
+
465
+ context "when given no arguments" do
466
+ it { expect(subject.on_magenta).to eq("\e[45m") }
467
+ end
250
468
  end
251
469
 
252
- describe ".clear" do
253
- it { expect(subject.clear).to eq('') }
470
+ describe ".on_cyan" do
471
+ context "when given a string" do
472
+ it "must wrap the string with \\e[46m and \\e[39m" do
473
+ expect(subject.on_cyan(str)).to eq("\e[46m#{str}\e[49m")
474
+ end
475
+ end
476
+
477
+ context "when given no arguments" do
478
+ it { expect(subject.on_cyan).to eq("\e[46m") }
479
+ end
254
480
  end
255
481
 
256
- describe ".bold" do
482
+ describe ".on_white" do
257
483
  context "when given a string" do
258
- it "must return that string" do
259
- expect(subject.bold(str)).to eq(str)
484
+ it "must wrap the string with \\e[47m and \\e[39m" do
485
+ expect(subject.on_white(str)).to eq("\e[47m#{str}\e[49m")
260
486
  end
261
487
  end
262
488
 
263
489
  context "when given no arguments" do
264
- it { expect(subject.bold).to eq('') }
490
+ it { expect(subject.on_white).to eq("\e[47m") }
265
491
  end
266
492
  end
267
493
 
268
- describe ".black" do
494
+ describe ".on_bright_black" do
269
495
  context "when given a string" do
270
- it "must return that string" do
271
- expect(subject.black(str)).to eq(str)
496
+ it "must wrap the string with \\e[100m and \\e[39m" do
497
+ expect(subject.on_bright_black(str)).to eq("\e[100m#{str}\e[49m")
272
498
  end
273
499
  end
274
500
 
275
501
  context "when given no arguments" do
276
- it { expect(subject.black).to eq('') }
502
+ it { expect(subject.on_bright_black).to eq("\e[100m") }
277
503
  end
278
504
  end
279
505
 
280
- describe ".red" do
506
+ describe ".on_gray" do
281
507
  context "when given a string" do
282
- it "must return that string" do
283
- expect(subject.red(str)).to eq(str)
508
+ it "must wrap the string with \\e[100m and \\e[39m" do
509
+ expect(subject.on_gray(str)).to eq("\e[100m#{str}\e[49m")
284
510
  end
285
511
  end
286
512
 
287
513
  context "when given no arguments" do
288
- it { expect(subject.red).to eq('') }
514
+ it { expect(subject.on_gray).to eq("\e[100m") }
289
515
  end
290
516
  end
291
517
 
292
- describe ".green" do
518
+ describe ".on_bright_red" do
293
519
  context "when given a string" do
294
- it "must return that string" do
295
- expect(subject.green(str)).to eq(str)
520
+ it "must wrap the string with \\e[101m and \\e[39m" do
521
+ expect(subject.on_bright_red(str)).to eq("\e[101m#{str}\e[49m")
296
522
  end
297
523
  end
298
524
 
299
525
  context "when given no arguments" do
300
- it { expect(subject.green).to eq('') }
526
+ it { expect(subject.on_bright_red).to eq("\e[101m") }
301
527
  end
302
528
  end
303
529
 
304
- describe ".yellow" do
530
+ describe ".on_bright_green" do
305
531
  context "when given a string" do
306
- it "must return that string" do
307
- expect(subject.yellow(str)).to eq(str)
532
+ it "must wrap the string with \\e[102m and \\e[39m" do
533
+ expect(subject.on_bright_green(str)).to eq("\e[102m#{str}\e[49m")
308
534
  end
309
535
  end
310
536
 
311
537
  context "when given no arguments" do
312
- it { expect(subject.yellow).to eq('') }
538
+ it { expect(subject.on_bright_green).to eq("\e[102m") }
313
539
  end
314
540
  end
315
541
 
316
- describe ".blue" do
542
+ describe ".on_bright_yellow" do
317
543
  context "when given a string" do
318
- it "must return that string" do
319
- expect(subject.blue(str)).to eq(str)
544
+ it "must wrap the string with \\e[103m and \\e[39m" do
545
+ expect(subject.on_bright_yellow(str)).to eq("\e[103m#{str}\e[49m")
320
546
  end
321
547
  end
322
548
 
323
549
  context "when given no arguments" do
324
- it { expect(subject.blue).to eq('') }
550
+ it { expect(subject.on_bright_yellow).to eq("\e[103m") }
325
551
  end
326
552
  end
327
553
 
328
- describe ".magenta" do
554
+ describe ".on_bright_blue" do
329
555
  context "when given a string" do
330
- it "must return that string" do
331
- expect(subject.magenta(str)).to eq(str)
556
+ it "must wrap the string with \\e[104m and \\e[39m" do
557
+ expect(subject.on_bright_blue(str)).to eq("\e[104m#{str}\e[49m")
332
558
  end
333
559
  end
334
560
 
335
561
  context "when given no arguments" do
336
- it { expect(subject.magenta).to eq('') }
562
+ it { expect(subject.on_bright_blue).to eq("\e[104m") }
337
563
  end
338
564
  end
339
565
 
340
- describe ".cyan" do
566
+ describe ".on_bright_magenta" do
341
567
  context "when given a string" do
342
- it "must return that string" do
343
- expect(subject.cyan(str)).to eq(str)
568
+ it "must wrap the string with \\e[105m and \\e[39m" do
569
+ expect(subject.on_bright_magenta(str)).to eq("\e[105m#{str}\e[49m")
344
570
  end
345
571
  end
346
572
 
347
573
  context "when given no arguments" do
348
- it { expect(subject.cyan).to eq('') }
574
+ it { expect(subject.on_bright_magenta).to eq("\e[105m") }
349
575
  end
350
576
  end
351
577
 
352
- describe ".white" do
578
+ describe ".on_bright_cyan" do
579
+ context "when given a string" do
580
+ it "must wrap the string with \\e[106m and \\e[39m" do
581
+ expect(subject.on_bright_cyan(str)).to eq("\e[106m#{str}\e[49m")
582
+ end
583
+ end
584
+
585
+ context "when given no arguments" do
586
+ it { expect(subject.on_bright_cyan).to eq("\e[106m") }
587
+ end
588
+ end
589
+
590
+ describe ".on_bright_white" do
353
591
  context "when given a string" do
354
- it "must return that string" do
355
- expect(subject.white(str)).to eq(str)
592
+ it "must wrap the string with \\e[107m and \\e[39m" do
593
+ expect(subject.on_bright_white(str)).to eq("\e[107m#{str}\e[49m")
356
594
  end
357
595
  end
358
596
 
359
597
  context "when given no arguments" do
360
- it { expect(subject.white).to eq('') }
598
+ it { expect(subject.on_bright_white).to eq("\e[107m") }
599
+ end
600
+ end
601
+ end
602
+
603
+ describe CommandKit::Colors::PlainText do
604
+ subject { described_class }
605
+
606
+ let(:str) { 'foo' }
607
+
608
+ [
609
+ :RESET, :CLEAR,
610
+ :BOLD, :RESET_INTENSITY,
611
+ :BLACK, :RED, :GREEN, :YELLOW, :BLUE, :MAGENTA, :CYAN, :WHITE,
612
+ :BRIGHT_BLACK, :BRIGHT_RED, :BRIGHT_GREEN, :BRIGHT_YELLOW, :BRIGHT_BLUE, :BRIGHT_MAGENTA, :BRIGHT_CYAN, :BRIGHT_WHITE,
613
+ :RESET_FG, :RESET_COLOR,
614
+ :ON_BLACK, :ON_RED, :ON_GREEN, :ON_YELLOW, :ON_BLUE, :ON_MAGENTA, :ON_CYAN, :ON_WHITE,
615
+ :ON_BRIGHT_BLACK, :ON_BRIGHT_RED, :ON_BRIGHT_GREEN, :ON_BRIGHT_YELLOW, :ON_BRIGHT_BLUE, :ON_BRIGHT_MAGENTA, :ON_BRIGHT_CYAN, :ON_BRIGHT_WHITE,
616
+ :RESET_BG
617
+ ].each do |const_name|
618
+ describe const_name.to_s do
619
+ it { expect(subject.const_get(const_name)).to eq('') }
620
+ end
621
+ end
622
+
623
+ describe ".reset" do
624
+ it { expect(subject.reset).to eq('') }
625
+ end
626
+
627
+ describe ".clear" do
628
+ it { expect(subject.clear).to eq('') }
629
+ end
630
+
631
+ [
632
+ :bold,
633
+ :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white,
634
+ :bright_black, :gray, :bright_red, :bright_green, :bright_yellow, :bright_blue, :bright_magenta, :bright_cyan, :bright_white,
635
+ :on_black, :on_red, :on_green, :on_yellow, :on_blue, :on_magenta, :on_cyan, :on_white,
636
+ :on_bright_black, :on_gray, :on_bright_red, :on_bright_green, :on_bright_yellow, :on_bright_blue, :on_bright_magenta, :on_bright_cyan, :on_bright_white
637
+ ].each do |method_name|
638
+ describe ".#{method_name}" do
639
+ context "when given a string" do
640
+ it "must return that string" do
641
+ expect(subject.send(method_name,str)).to eq(str)
642
+ end
643
+ end
644
+
645
+ context "when given no arguments" do
646
+ it { expect(subject.send(method_name)).to eq('') }
647
+ end
361
648
  end
362
649
  end
363
650
  end
data/spec/command_spec.rb CHANGED
@@ -26,14 +26,14 @@ describe CommandKit::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,7 +46,78 @@ describe CommandKit::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)
49
+ it "must include CommandKit::FileUtils" do
50
+ expect(described_class).to include(CommandKit::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
51
122
  end
52
123
  end