command_kit 0.1.0.rc1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
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
data/Rakefile CHANGED
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'rubygems'
4
2
 
5
3
  begin
@@ -21,3 +19,6 @@ task :default => :spec
21
19
  require 'yard'
22
20
  YARD::Rake::YardocTask.new
23
21
  task :doc => :yard
22
+
23
+ require 'rubocop/rake_task'
24
+ RuboCop::RakeTask.new
data/command_kit.gemspec CHANGED
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'yaml'
4
2
 
5
3
  Gem::Specification.new do |gem|
@@ -20,11 +18,13 @@ Gem::Specification.new do |gem|
20
18
  gem.authors = Array(gemspec['authors'])
21
19
  gem.email = gemspec['email']
22
20
  gem.homepage = gemspec['homepage']
21
+ gem.metadata = gemspec['metadata'] if gemspec['metadata']
23
22
 
24
23
  glob = lambda { |patterns| gem.files & Dir[*patterns] }
25
24
 
26
- gem.files = `git ls-files`.split($/)
27
- gem.files = glob[gemspec['files']] if gemspec['files']
25
+ gem.files = if gemspec['files'] then glob[gemspec['files']]
26
+ else `git ls-files`.split($/)
27
+ end
28
28
 
29
29
  gem.executables = gemspec.fetch('executables') do
30
30
  glob['bin/*'].map { |path| File.basename(path) }
data/examples/command.rb CHANGED
@@ -16,7 +16,7 @@ class Command < CommandKit::Command
16
16
 
17
17
  option :output, value: {
18
18
  type: String,
19
- usage: 'FILE',
19
+ usage: 'FILE'
20
20
  },
21
21
  short: '-o',
22
22
  desc: "Optional output file"
data/gemspec.yml CHANGED
@@ -7,7 +7,14 @@ description:
7
7
  license: MIT
8
8
  authors: Postmodern
9
9
  email: postmodern.mod3@gmail.com
10
- homepage: https://github.com/postmodern/command_kit#readme
10
+ homepage: https://github.com/postmodern/command_kit.rb#readme
11
+
12
+ metadata:
13
+ documentation_uri: https://rubydoc.info/gems/command_kit
14
+ source_code_uri: https://github.com/postmodern/command_kit.rb
15
+ bug_tracker_uri: https://github.com/postmodern/command_kit.rb/issues
16
+ changelog_uri: https://github.com/postmodern/command_kit.rb/blob/main/ChangeLog.md
17
+ rubygems_mfa_required: 'true'
11
18
 
12
19
  required_ruby_version: ">= 2.7.0"
13
20
 
@@ -5,6 +5,8 @@ module CommandKit
5
5
  #
6
6
  # Represents a defined argument.
7
7
  #
8
+ # @api private
9
+ #
8
10
  class Argument < ArgumentValue
9
11
 
10
12
  # The argument's name.
@@ -3,6 +3,8 @@ module CommandKit
3
3
  #
4
4
  # Represents an individual argument value.
5
5
  #
6
+ # @api private
7
+ #
6
8
  class ArgumentValue
7
9
 
8
10
  # Specifies whether the argument value is required or optional.
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'command_kit/arguments/argument'
4
+ require 'command_kit/usage'
1
5
  require 'command_kit/main'
2
6
  require 'command_kit/help'
3
- require 'command_kit/arguments/argument'
7
+ require 'command_kit/printing'
4
8
 
5
9
  module CommandKit
6
10
  #
@@ -43,9 +47,14 @@ module CommandKit
43
47
  # end
44
48
  #
45
49
  module Arguments
50
+ include Usage
46
51
  include Main
47
52
  include Help
53
+ include Printing
48
54
 
55
+ #
56
+ # @api private
57
+ #
49
58
  module ModuleMethods
50
59
  #
51
60
  # Extends {ClassMethods} or {ModuleMethods}, depending on whether
@@ -77,6 +86,8 @@ module CommandKit
77
86
  # @return [Hash{Symbol => Argument}]
78
87
  # The defined argument for the class and it's superclass.
79
88
  #
89
+ # @api semipublic
90
+ #
80
91
  def arguments
81
92
  @arguments ||= if superclass.kind_of?(ClassMethods)
82
93
  superclass.arguments.dup
@@ -113,8 +124,8 @@ module CommandKit
113
124
  # argument :bar, desc: "Bar argument"
114
125
  #
115
126
  # @example With a custom usage string:
116
- # option :bar, usage: 'BAR',
117
- # desc: "Bar argument"
127
+ # argument :bar, usage: 'BAR',
128
+ # desc: "Bar argument"
118
129
  #
119
130
  # @example With a custom type:
120
131
  # argument :bar, desc: "Bar argument"
@@ -131,6 +142,8 @@ module CommandKit
131
142
  # argument :bar, repeats: true,
132
143
  # desc: "Bar argument"
133
144
  #
145
+ # @api public
146
+ #
134
147
  def argument(name,**kwargs)
135
148
  arguments[name] = Argument.new(name,**kwargs)
136
149
  end
@@ -147,6 +160,8 @@ module CommandKit
147
160
  # The exit status code. If too few or too many arguments are given, then
148
161
  # an error message is printed and `1` is returned.
149
162
  #
163
+ # @api public
164
+ #
150
165
  def main(argv=[])
151
166
  required_args = self.class.arguments.each_value.count(&:required?)
152
167
  optional_args = self.class.arguments.each_value.count(&:optional?)
@@ -157,7 +172,7 @@ module CommandKit
157
172
  help_usage
158
173
  return 1
159
174
  elsif argv.length > (required_args + optional_args) && !has_repeats_arg
160
- print_error("too many arguments given")
175
+ print_error("too many arguments given.")
161
176
  help_usage
162
177
  return 1
163
178
  end
@@ -168,12 +183,14 @@ module CommandKit
168
183
  #
169
184
  # Prints any defined arguments, along with the usual `--help` information.
170
185
  #
186
+ # @api semipublic
187
+ #
171
188
  def help_arguments
172
189
  unless (arguments = self.class.arguments).empty?
173
190
  puts
174
191
  puts 'Arguments:'
175
192
 
176
- self.class.arguments.each_value do |arg|
193
+ arguments.each_value do |arg|
177
194
  puts " #{arg.usage.ljust(33)}#{arg.desc}"
178
195
  end
179
196
  end
@@ -183,8 +200,10 @@ module CommandKit
183
200
  # Calls the superclass'es `#help` method, if it's defined, then calls
184
201
  # {#help_arguments}.
185
202
  #
203
+ # @api public
204
+ #
186
205
  def help
187
- super if defined?(super)
206
+ super
188
207
 
189
208
  help_arguments
190
209
  end
@@ -26,7 +26,7 @@ module CommandKit
26
26
  #
27
27
  # ## Alternatives
28
28
  #
29
- # * [ansi](http://rubyworks.github.io/ansi/)
29
+ # * [ansi](https://rubyworks.github.io/ansi/)
30
30
  # * [colorize](https://github.com/fazibear/colorize#readme)
31
31
  #
32
32
  # @see https://en.wikipedia.org/wiki/ANSI_escape_code
@@ -67,7 +67,7 @@ module CommandKit
67
67
  # ANSI color code for blue
68
68
  BLUE = "\e[34m"
69
69
 
70
- # ANSI color code for megenta
70
+ # ANSI color code for magenta
71
71
  MAGENTA = "\e[35m"
72
72
 
73
73
  # ANSI color code for cyan
@@ -79,6 +79,51 @@ module CommandKit
79
79
  # ANSI color for the default foreground color
80
80
  RESET_COLOR = "\e[39m"
81
81
 
82
+ # ANSI color code for background color black
83
+ #
84
+ # @since 0.2.0
85
+ ON_BLACK = "\e[40m"
86
+
87
+ # ANSI color code for background color red
88
+ #
89
+ # @since 0.2.0
90
+ ON_RED = "\e[41m"
91
+
92
+ # ANSI color code for background color green
93
+ #
94
+ # @since 0.2.0
95
+ ON_GREEN = "\e[42m"
96
+
97
+ # ANSI color code for background color yellow
98
+ #
99
+ # @since 0.2.0
100
+ ON_YELLOW = "\e[43m"
101
+
102
+ # ANSI color code for background color blue
103
+ #
104
+ # @since 0.2.0
105
+ ON_BLUE = "\e[44m"
106
+
107
+ # ANSI color code for background color magenta
108
+ #
109
+ # @since 0.2.0
110
+ ON_MAGENTA = "\e[45m"
111
+
112
+ # ANSI color code for background color cyan
113
+ #
114
+ # @since 0.2.0
115
+ ON_CYAN = "\e[46m"
116
+
117
+ # ANSI color code for background color white
118
+ #
119
+ # @since 0.2.0
120
+ ON_WHITE = "\e[47m"
121
+
122
+ # ANSI color for the default background color
123
+ #
124
+ # @since 0.2.0
125
+ RESET_BG = "\e[49m"
126
+
82
127
  module_function
83
128
 
84
129
  #
@@ -88,6 +133,8 @@ module CommandKit
88
133
  #
89
134
  # @see RESET
90
135
  #
136
+ # @api public
137
+ #
91
138
  def reset
92
139
  RESET
93
140
  end
@@ -95,6 +142,8 @@ module CommandKit
95
142
  #
96
143
  # @see reset
97
144
  #
145
+ # @api public
146
+ #
98
147
  def clear
99
148
  reset
100
149
  end
@@ -110,6 +159,8 @@ module CommandKit
110
159
  #
111
160
  # @see BOLD
112
161
  #
162
+ # @api public
163
+ #
113
164
  def bold(string=nil)
114
165
  if string then "#{BOLD}#{string}#{RESET_INTENSITY}"
115
166
  else BOLD
@@ -127,6 +178,8 @@ module CommandKit
127
178
  #
128
179
  # @see BLACK
129
180
  #
181
+ # @api public
182
+ #
130
183
  def black(string=nil)
131
184
  if string then "#{BLACK}#{string}#{RESET_COLOR}"
132
185
  else BLACK
@@ -144,6 +197,8 @@ module CommandKit
144
197
  #
145
198
  # @see RED
146
199
  #
200
+ # @api public
201
+ #
147
202
  def red(string=nil)
148
203
  if string then "#{RED}#{string}#{RESET_COLOR}"
149
204
  else RED
@@ -161,6 +216,8 @@ module CommandKit
161
216
  #
162
217
  # @see GREEN
163
218
  #
219
+ # @api public
220
+ #
164
221
  def green(string=nil)
165
222
  if string then "#{GREEN}#{string}#{RESET_COLOR}"
166
223
  else GREEN
@@ -178,6 +235,8 @@ module CommandKit
178
235
  #
179
236
  # @see YELLOW
180
237
  #
238
+ # @api public
239
+ #
181
240
  def yellow(string=nil)
182
241
  if string then "#{YELLOW}#{string}#{RESET_COLOR}"
183
242
  else YELLOW
@@ -195,6 +254,8 @@ module CommandKit
195
254
  #
196
255
  # @see BLUE
197
256
  #
257
+ # @api public
258
+ #
198
259
  def blue(string=nil)
199
260
  if string then "#{BLUE}#{string}#{RESET_COLOR}"
200
261
  else BLUE
@@ -212,6 +273,8 @@ module CommandKit
212
273
  #
213
274
  # @see MAGENTA
214
275
  #
276
+ # @api public
277
+ #
215
278
  def magenta(string=nil)
216
279
  if string then "#{MAGENTA}#{string}#{RESET_COLOR}"
217
280
  else MAGENTA
@@ -229,6 +292,8 @@ module CommandKit
229
292
  #
230
293
  # @see CYAN
231
294
  #
295
+ # @api public
296
+ #
232
297
  def cyan(string=nil)
233
298
  if string then "#{CYAN}#{string}#{RESET_COLOR}"
234
299
  else CYAN
@@ -246,76 +311,209 @@ module CommandKit
246
311
  #
247
312
  # @see WHITE
248
313
  #
314
+ # @api public
315
+ #
249
316
  def white(string=nil)
250
317
  if string then "#{WHITE}#{string}#{RESET_COLOR}"
251
318
  else WHITE
252
319
  end
253
320
  end
254
- end
255
321
 
256
- #
257
- # Dummy module with the same interface as {ANSI}, but for when ANSI is not
258
- # supported.
259
- #
260
- module PlainText
261
- RESET = \
262
- CLEAR = \
263
- BOLD = \
264
- RESET_INTENSITY = \
265
- BLACK = \
266
- RED = \
267
- GREEN = \
268
- YELLOW = \
269
- BLUE = \
270
- MAGENTA = \
271
- CYAN = \
272
- WHITE = \
273
- RESET_COLOR = ''
274
-
275
- module_function
322
+ #
323
+ # Sets the background color to black.
324
+ #
325
+ # @param [String, nil] string
326
+ # An optional string.
327
+ #
328
+ # @return [String, ON_BLACK]
329
+ # The colorized string or just {ON_BLACK} if no arguments were given.
330
+ #
331
+ # @see ON_BLACK
332
+ #
333
+ # @api public
334
+ #
335
+ # @since 0.2.0
336
+ #
337
+ def on_black(string=nil)
338
+ if string then "#{ON_BLACK}#{string}#{RESET_BG}"
339
+ else ON_BLACK
340
+ end
341
+ end
276
342
 
277
- def reset
278
- RESET
343
+ #
344
+ # Sets the background color to red.
345
+ #
346
+ # @param [String, nil] string
347
+ # An optional string.
348
+ #
349
+ # @return [String, ON_RED]
350
+ # The colorized string or just {ON_RED} if no arguments were given.
351
+ #
352
+ # @see ON_RED
353
+ #
354
+ # @api public
355
+ #
356
+ # @since 0.2.0
357
+ #
358
+ def on_red(string=nil)
359
+ if string then "#{ON_RED}#{string}#{RESET_BG}"
360
+ else ON_RED
361
+ end
279
362
  end
280
363
 
281
- def clear
282
- reset
364
+ #
365
+ # Sets the background color to green.
366
+ #
367
+ # @param [String, nil] string
368
+ # An optional string.
369
+ #
370
+ # @return [String, ON_GREEN]
371
+ # The colorized string or just {ON_GREEN} if no arguments were given.
372
+ #
373
+ # @see ON_GREEN
374
+ #
375
+ # @api public
376
+ #
377
+ # @since 0.2.0
378
+ #
379
+ def on_green(string=nil)
380
+ if string then "#{ON_GREEN}#{string}#{RESET_BG}"
381
+ else ON_GREEN
382
+ end
283
383
  end
284
384
 
285
- def bold(string=nil)
286
- string || ''
385
+ #
386
+ # Sets the background color to yellow.
387
+ #
388
+ # @param [String, nil] string
389
+ # An optional string.
390
+ #
391
+ # @return [String, ON_YELLOW]
392
+ # The colorized string or just {ON_YELLOW} if no arguments were given.
393
+ #
394
+ # @see ON_YELLOW
395
+ #
396
+ # @api public
397
+ #
398
+ # @since 0.2.0
399
+ #
400
+ def on_yellow(string=nil)
401
+ if string then "#{ON_YELLOW}#{string}#{RESET_BG}"
402
+ else ON_YELLOW
403
+ end
287
404
  end
288
405
 
289
- def black(string=nil)
290
- string || ''
406
+ #
407
+ # Sets the background color to blue.
408
+ #
409
+ # @param [String, nil] string
410
+ # An optional string.
411
+ #
412
+ # @return [String, ON_BLUE]
413
+ # The colorized string or just {ON_BLUE} if no arguments were given.
414
+ #
415
+ # @see ON_BLUE
416
+ #
417
+ # @api public
418
+ #
419
+ # @since 0.2.0
420
+ #
421
+ def on_blue(string=nil)
422
+ if string then "#{ON_BLUE}#{string}#{RESET_BG}"
423
+ else ON_BLUE
424
+ end
291
425
  end
292
426
 
293
- def red(string=nil)
294
- string || ''
427
+ #
428
+ # Sets the background color to magenta.
429
+ #
430
+ # @param [String, nil] string
431
+ # An optional string.
432
+ #
433
+ # @return [String, ON_MAGENTA]
434
+ # The colorized string or just {ON_MAGENTA} if no arguments were given.
435
+ #
436
+ # @see ON_MAGENTA
437
+ #
438
+ # @api public
439
+ #
440
+ # @since 0.2.0
441
+ #
442
+ def on_magenta(string=nil)
443
+ if string then "#{ON_MAGENTA}#{string}#{RESET_BG}"
444
+ else ON_MAGENTA
445
+ end
295
446
  end
296
447
 
297
- def green(string=nil)
298
- string || ''
448
+ #
449
+ # Sets the background color to cyan.
450
+ #
451
+ # @param [String, nil] string
452
+ # An optional string.
453
+ #
454
+ # @return [String, ON_CYAN]
455
+ # The colorized string or just {ON_CYAN} if no arguments were given.
456
+ #
457
+ # @see ON_CYAN
458
+ #
459
+ # @api public
460
+ #
461
+ # @since 0.2.0
462
+ #
463
+ def on_cyan(string=nil)
464
+ if string then "#{ON_CYAN}#{string}#{RESET_BG}"
465
+ else ON_CYAN
466
+ end
299
467
  end
300
468
 
301
- def yellow(string=nil)
302
- string || ''
469
+ #
470
+ # Sets the background color to white.
471
+ #
472
+ # @param [String, nil] string
473
+ # An optional string.
474
+ #
475
+ # @return [String, ON_WHITE]
476
+ # The colorized string or just {ON_WHITE} if no arguments were given.
477
+ #
478
+ # @see ON_WHITE
479
+ #
480
+ # @api public
481
+ #
482
+ # @since 0.2.0
483
+ #
484
+ def on_white(string=nil)
485
+ if string then "#{ON_WHITE}#{string}#{RESET_BG}"
486
+ else ON_WHITE
487
+ end
303
488
  end
489
+ end
304
490
 
305
- def blue(string=nil)
306
- string || ''
491
+ #
492
+ # Dummy module with the same interface as {ANSI}, but for when ANSI is not
493
+ # supported.
494
+ #
495
+ module PlainText
496
+ ANSI.constants(false).each do |name|
497
+ const_set(name,'')
307
498
  end
308
499
 
309
- def magenta(string=nil)
310
- string || ''
500
+ module_function
501
+
502
+ def reset
503
+ RESET
311
504
  end
312
505
 
313
- def cyan(string=nil)
314
- string || ''
506
+ def clear
507
+ reset
315
508
  end
316
509
 
317
- def white(string=nil)
318
- string || ''
510
+ [
511
+ :bold, :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white,
512
+ :on_black, :on_red, :on_green, :on_yellow, :on_blue, :on_magenta, :on_cyan, :on_white
513
+ ].each do |name|
514
+ define_method(name) do |string=nil|
515
+ string || ''
516
+ end
319
517
  end
320
518
  end
321
519
 
@@ -331,6 +529,8 @@ module CommandKit
331
529
  # output. Color output will also be disabled if the given stream is not
332
530
  # a TTY.
333
531
  #
532
+ # @api public
533
+ #
334
534
  def ansi?(stream=stdout)
335
535
  env['TERM'] != 'dumb' && stream.tty?
336
536
  end
@@ -343,6 +543,14 @@ module CommandKit
343
543
  # @return [ANSI, PlainText]
344
544
  # The ANSI module or PlainText dummy module.
345
545
  #
546
+ # @example
547
+ # puts colors.green("Hello world")
548
+ #
549
+ # @example Using colors with stderr output:
550
+ # stderr.puts colors(stderr).green("Hello world")
551
+ #
552
+ # @api public
553
+ #
346
554
  def colors(stream=stdout)
347
555
  color = if ansi?(stream) then ANSI
348
556
  else PlainText
@@ -9,6 +9,8 @@ require 'command_kit/examples'
9
9
  require 'command_kit/description'
10
10
  require 'command_kit/exception_handler'
11
11
 
12
+ require 'fileutils'
13
+
12
14
  module CommandKit
13
15
  #
14
16
  # The command class base-class.
@@ -54,7 +56,7 @@ module CommandKit
54
56
  # end
55
57
  # end
56
58
  #
57
- # ### initialize and using ivars
59
+ # ### initialize and using instance variables
58
60
  #
59
61
  # option :verbose, short: '-v', desc: "Increase verbose level" do
60
62
  # @verbose += 1
@@ -66,6 +68,8 @@ module CommandKit
66
68
  # @verbose = 0
67
69
  # end
68
70
  #
71
+ # @api public
72
+ #
69
73
  class Command
70
74
 
71
75
  include Main
@@ -79,6 +83,7 @@ module CommandKit
79
83
  include Examples
80
84
  include Description
81
85
  include ExceptionHandler
86
+ include FileUtils
82
87
 
83
88
  end
84
89
  end
@@ -31,6 +31,9 @@ module CommandKit
31
31
  # # => "foo-cmd"
32
32
  #
33
33
  module CommandName
34
+ #
35
+ # @api private
36
+ #
34
37
  module ModuleMethods
35
38
  #
36
39
  # Extends {ClassMethods} or {ModuleMethods}, depending on whether
@@ -65,6 +68,8 @@ module CommandKit
65
68
  #
66
69
  # @return [String]
67
70
  #
71
+ # @api public
72
+ #
68
73
  def command_name(new_command_name=nil)
69
74
  if new_command_name
70
75
  @command_name = new_command_name.to_s
@@ -77,6 +82,8 @@ module CommandKit
77
82
  # The commands name.
78
83
  #
79
84
  # @return [String]
85
+ #
86
+ # @api public
80
87
  attr_reader :command_name
81
88
 
82
89
  #
@@ -86,6 +93,8 @@ module CommandKit
86
93
  # Overrides the command name. Defaults to
87
94
  # {ClassMethods#command_name self.class.command_name}.
88
95
  #
96
+ # @api public
97
+ #
89
98
  def initialize(command_name: self.class.command_name, **kwargs)
90
99
  @command_name = command_name
91
100