command_kit 0.1.0.rc1 → 0.2.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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +17 -3
  3. data/.rubocop.yml +141 -0
  4. data/ChangeLog.md +102 -1
  5. data/Gemfile +3 -0
  6. data/README.md +187 -116
  7. data/Rakefile +3 -2
  8. data/command_kit.gemspec +4 -4
  9. data/examples/command.rb +1 -1
  10. data/gemspec.yml +8 -1
  11. data/lib/command_kit/arguments/argument.rb +2 -0
  12. data/lib/command_kit/arguments/argument_value.rb +2 -0
  13. data/lib/command_kit/arguments.rb +25 -6
  14. data/lib/command_kit/colors.rb +253 -45
  15. data/lib/command_kit/command.rb +6 -1
  16. data/lib/command_kit/command_name.rb +9 -0
  17. data/lib/command_kit/commands/auto_load.rb +24 -1
  18. data/lib/command_kit/commands/auto_require.rb +16 -0
  19. data/lib/command_kit/commands/command.rb +3 -0
  20. data/lib/command_kit/commands/help.rb +5 -2
  21. data/lib/command_kit/commands/parent_command.rb +7 -0
  22. data/lib/command_kit/commands/subcommand.rb +13 -1
  23. data/lib/command_kit/commands.rb +54 -9
  24. data/lib/command_kit/description.rb +12 -1
  25. data/lib/command_kit/env/home.rb +9 -0
  26. data/lib/command_kit/env/path.rb +16 -1
  27. data/lib/command_kit/env.rb +4 -0
  28. data/lib/command_kit/examples.rb +12 -1
  29. data/lib/command_kit/exception_handler.rb +4 -0
  30. data/lib/command_kit/help/man.rb +28 -31
  31. data/lib/command_kit/help.rb +7 -1
  32. data/lib/command_kit/inflector.rb +49 -17
  33. data/lib/command_kit/interactive.rb +71 -1
  34. data/lib/command_kit/main.rb +18 -9
  35. data/lib/command_kit/man.rb +44 -0
  36. data/lib/command_kit/open_app.rb +69 -0
  37. data/lib/command_kit/options/option.rb +3 -6
  38. data/lib/command_kit/options/option_value.rb +5 -2
  39. data/lib/command_kit/options/parser.rb +46 -19
  40. data/lib/command_kit/options/quiet.rb +3 -0
  41. data/lib/command_kit/options/verbose.rb +5 -0
  42. data/lib/command_kit/options/version.rb +6 -0
  43. data/lib/command_kit/options.rb +32 -7
  44. data/lib/command_kit/os/linux.rb +157 -0
  45. data/lib/command_kit/os.rb +165 -11
  46. data/lib/command_kit/package_manager.rb +200 -0
  47. data/lib/command_kit/pager.rb +73 -4
  48. data/lib/command_kit/printing/indent.rb +27 -4
  49. data/lib/command_kit/printing.rb +35 -1
  50. data/lib/command_kit/program_name.rb +7 -0
  51. data/lib/command_kit/stdio.rb +24 -0
  52. data/lib/command_kit/sudo.rb +40 -0
  53. data/lib/command_kit/terminal.rb +17 -0
  54. data/lib/command_kit/usage.rb +14 -0
  55. data/lib/command_kit/version.rb +1 -1
  56. data/lib/command_kit/xdg.rb +13 -0
  57. data/lib/command_kit.rb +1 -0
  58. data/spec/arguments/argument_spec.rb +2 -2
  59. data/spec/arguments_spec.rb +54 -28
  60. data/spec/colors_spec.rb +277 -13
  61. data/spec/command_name_spec.rb +1 -1
  62. data/spec/command_spec.rb +79 -5
  63. data/spec/commands/auto_load/subcommand_spec.rb +1 -1
  64. data/spec/commands/auto_load_spec.rb +34 -3
  65. data/spec/commands/auto_require_spec.rb +2 -2
  66. data/spec/commands/help_spec.rb +1 -1
  67. data/spec/commands/parent_command_spec.rb +1 -1
  68. data/spec/commands/subcommand_spec.rb +1 -1
  69. data/spec/commands_spec.rb +102 -30
  70. data/spec/description_spec.rb +1 -25
  71. data/spec/env/home_spec.rb +1 -1
  72. data/spec/env/path_spec.rb +7 -1
  73. data/spec/examples_spec.rb +1 -25
  74. data/spec/exception_handler_spec.rb +1 -1
  75. data/spec/help/man_spec.rb +55 -58
  76. data/spec/help_spec.rb +0 -25
  77. data/spec/inflector_spec.rb +71 -9
  78. data/spec/main_spec.rb +7 -7
  79. data/spec/man_spec.rb +46 -0
  80. data/spec/open_app_spec.rb +85 -0
  81. data/spec/options/option_spec.rb +5 -5
  82. data/spec/options/option_value_spec.rb +56 -1
  83. data/spec/options_spec.rb +283 -1
  84. data/spec/os/linux_spec.rb +164 -0
  85. data/spec/os_spec.rb +201 -14
  86. data/spec/package_manager_spec.rb +806 -0
  87. data/spec/pager_spec.rb +72 -7
  88. data/spec/printing/indent_spec.rb +8 -6
  89. data/spec/printing_spec.rb +33 -3
  90. data/spec/program_name_spec.rb +1 -1
  91. data/spec/spec_helper.rb +0 -3
  92. data/spec/sudo_spec.rb +51 -0
  93. data/spec/terminal_spec.rb +31 -1
  94. data/spec/usage_spec.rb +2 -2
  95. data/spec/xdg_spec.rb +1 -1
  96. metadata +21 -5
@@ -1,4 +1,4 @@
1
1
  module CommandKit
2
2
  # command_kit version
3
- VERSION = "0.1.0.rc1"
3
+ VERSION = "0.2.2"
4
4
  end
@@ -24,6 +24,9 @@ module CommandKit
24
24
  include CommandName
25
25
  include Env::Home
26
26
 
27
+ #
28
+ # @api private
29
+ #
27
30
  module ModuleMethods
28
31
  #
29
32
  # Extends {ClassMethods} or {ModuleMethods}, depending on whether {XDG} is
@@ -61,6 +64,8 @@ module CommandKit
61
64
  # {CommandName::ClassMethods#command_name} if no {#xdg_namespace} has
62
65
  # been defined.
63
66
  #
67
+ # @api public
68
+ #
64
69
  def xdg_namespace(new_namespace=nil)
65
70
  if new_namespace
66
71
  @xdg_namespace = new_namespace.to_s
@@ -77,16 +82,22 @@ module CommandKit
77
82
  # The `~/.config/<xdg_namespace>` directory.
78
83
  #
79
84
  # @return [String]
85
+ #
86
+ # @api public
80
87
  attr_reader :config_dir
81
88
 
82
89
  # The `~/.local/share/<xdg_namespace>` directory.
83
90
  #
84
91
  # @return [String]
92
+ #
93
+ # @api public
85
94
  attr_reader :local_share_dir
86
95
 
87
96
  # The `~/.cache/<xdg_namespace>` directory.
88
97
  #
89
98
  # @return [String]
99
+ #
100
+ # @api public
90
101
  attr_reader :cache_dir
91
102
 
92
103
  #
@@ -138,6 +149,8 @@ module CommandKit
138
149
  #
139
150
  # @see ClassMethods#xdg_namespace
140
151
  #
152
+ # @api semipublic
153
+ #
141
154
  def xdg_namespace
142
155
  self.class.xdg_namespace
143
156
  end
data/lib/command_kit.rb CHANGED
@@ -1 +1,2 @@
1
+ require 'command_kit/command'
1
2
  require 'command_kit/version'
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/arguments/argument'
3
3
 
4
- describe Arguments::Argument do
4
+ describe CommandKit::Arguments::Argument do
5
5
  let(:name) { :foo }
6
6
  let(:usage) { 'FOO' }
7
7
  let(:required) { true }
@@ -126,7 +126,7 @@ describe Arguments::Argument do
126
126
  let(:repeats) { false }
127
127
 
128
128
  it "must return the usage name unchanged" do
129
- expect(subject.usage).to eq("#{usage}")
129
+ expect(subject.usage).to eq(usage)
130
130
  end
131
131
  end
132
132
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/arguments'
3
3
 
4
- describe Arguments do
4
+ describe CommandKit::Arguments do
5
5
  module TestArguments
6
6
  class ImplicitCmd
7
7
  include CommandKit::Arguments
@@ -13,8 +13,8 @@ describe Arguments do
13
13
  describe ".included" do
14
14
  subject { command_class }
15
15
 
16
- it { expect(subject).to include(Main) }
17
- it { expect(subject).to include(Help) }
16
+ it { expect(subject).to include(CommandKit::Main) }
17
+ it { expect(subject).to include(CommandKit::Help) }
18
18
  end
19
19
 
20
20
  describe ".arguments" do
@@ -137,6 +137,56 @@ describe Arguments do
137
137
 
138
138
  subject { command_class.new }
139
139
 
140
+ describe "#main" do
141
+ module TestArguments
142
+ class TestCommand
143
+
144
+ include CommandKit::Arguments
145
+
146
+ argument :argument1, required: true,
147
+ usage: 'ARG1',
148
+ desc: "Argument 1"
149
+
150
+ argument :argument2, required: false,
151
+ usage: 'ARG2',
152
+ desc: "Argument 2"
153
+
154
+ end
155
+ end
156
+
157
+ let(:command_class) { TestArguments::TestCommand }
158
+
159
+ context "when given the correct number of arguments" do
160
+ let(:argv) { %w[arg1 arg2] }
161
+
162
+ it "must parse options before validating the number of arguments" do
163
+ expect {
164
+ expect(subject.main(argv)).to eq(0)
165
+ }.to_not output.to_stderr
166
+ end
167
+ end
168
+
169
+ context "when given fewer than the required number of arguments" do
170
+ let(:argv) { %w[] }
171
+
172
+ it "must print an error message and return 1" do
173
+ expect {
174
+ expect(subject.main(argv)).to eq(1)
175
+ }.to output("#{subject.command_name}: insufficient number of arguments.#{$/}").to_stderr
176
+ end
177
+ end
178
+
179
+ context "when given more than the total number of arguments" do
180
+ let(:argv) { %w[foo bar baz] }
181
+
182
+ it "must print an error message and return 1" do
183
+ expect {
184
+ expect(subject.main(argv)).to eq(1)
185
+ }.to output("#{subject.command_name}: too many arguments given.#{$/}").to_stderr
186
+ end
187
+ end
188
+ end
189
+
140
190
  describe "#help_arguments" do
141
191
  context "when #arguments returns {}" do
142
192
  module TestArguments
@@ -153,7 +203,7 @@ describe Arguments do
153
203
  end
154
204
  end
155
205
 
156
- context "when #arguments returns an Array" do
206
+ context "when #arguments returns a Hash" do
157
207
  module TestArguments
158
208
  class MultipleArguments
159
209
  include CommandKit::Arguments
@@ -192,29 +242,5 @@ describe Arguments do
192
242
 
193
243
  subject.help
194
244
  end
195
-
196
- context "when the superclass defines it's own #help method" do
197
- module TestDescription
198
- class SuperclassHelpMethod
199
- def help
200
- puts 'superclass'
201
- end
202
- end
203
-
204
- class InheritedHelpMethod < SuperclassHelpMethod
205
- include CommandKit::Arguments
206
- end
207
- end
208
-
209
- let(:super_command_class) { TestDescription::SuperclassHelpMethod }
210
- let(:command_class) { TestDescription::InheritedHelpMethod }
211
-
212
- it "must call the superclass'es #help method first" do
213
- expect_any_instance_of(super_command_class).to receive(:help)
214
- expect(subject).to receive(:help_arguments)
215
-
216
- subject.help
217
- end
218
- end
219
245
  end
220
246
  end
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 { expect(subject.colors).to be(Colors::ANSI) }
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(Colors::ANSI)
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 { expect(subject.colors).to be(Colors::PlainText) }
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(Colors::PlainText)
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 { expect(subject.colors(stream)).to be(Colors::ANSI) }
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(Colors::ANSI)
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 { expect(subject.colors(stream)).to be(Colors::PlainText) }
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(Colors::PlainText)
728
+ }.to yield_with_args(described_class::PlainText)
465
729
  end
466
730
  end
467
731
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/command_name'
3
3
 
4
- describe CommandName do
4
+ describe CommandKit::CommandName do
5
5
  module TestCommandName
6
6
  class ImplicitCmd
7
7
  include CommandKit::CommandName
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' }