command_kit 0.2.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +4 -5
  3. data/.rubocop.yml +14 -1
  4. data/ChangeLog.md +82 -0
  5. data/Gemfile +2 -0
  6. data/LICENSE.txt +1 -1
  7. data/README.md +18 -9
  8. data/command_kit.gemspec +0 -1
  9. data/examples/printing/tables.rb +141 -0
  10. data/gemspec.yml +3 -3
  11. data/lib/command_kit/arguments/argument.rb +2 -2
  12. data/lib/command_kit/arguments.rb +27 -2
  13. data/lib/command_kit/bug_report.rb +105 -0
  14. data/lib/command_kit/colors.rb +488 -15
  15. data/lib/command_kit/command.rb +1 -2
  16. data/lib/command_kit/edit.rb +54 -0
  17. data/lib/command_kit/env.rb +1 -1
  18. data/lib/command_kit/file_utils.rb +46 -0
  19. data/lib/command_kit/options/option.rb +45 -22
  20. data/lib/command_kit/options/option_value.rb +2 -2
  21. data/lib/command_kit/options/parser.rb +1 -4
  22. data/lib/command_kit/options/quiet.rb +1 -1
  23. data/lib/command_kit/options/verbose.rb +2 -2
  24. data/lib/command_kit/options/version.rb +10 -0
  25. data/lib/command_kit/options.rb +89 -14
  26. data/lib/command_kit/os.rb +1 -1
  27. data/lib/command_kit/printing/fields.rb +56 -0
  28. data/lib/command_kit/printing/indent.rb +1 -1
  29. data/lib/command_kit/printing/lists.rb +91 -0
  30. data/lib/command_kit/printing/tables/border_style.rb +169 -0
  31. data/lib/command_kit/printing/tables/cell_builder.rb +93 -0
  32. data/lib/command_kit/printing/tables/row_builder.rb +111 -0
  33. data/lib/command_kit/printing/tables/style.rb +198 -0
  34. data/lib/command_kit/printing/tables/table_builder.rb +145 -0
  35. data/lib/command_kit/printing/tables/table_formatter.rb +254 -0
  36. data/lib/command_kit/printing/tables.rb +208 -0
  37. data/lib/command_kit/program_name.rb +9 -0
  38. data/lib/command_kit/stdio.rb +5 -1
  39. data/lib/command_kit/version.rb +1 -1
  40. data/spec/arguments_spec.rb +33 -0
  41. data/spec/bug_report_spec.rb +266 -0
  42. data/spec/colors_spec.rb +232 -195
  43. data/spec/command_name_spec.rb +1 -1
  44. data/spec/command_spec.rb +2 -2
  45. data/spec/edit_spec.rb +72 -0
  46. data/spec/file_utils_spec.rb +59 -0
  47. data/spec/fixtures/template.erb +5 -0
  48. data/spec/options/option_spec.rb +48 -2
  49. data/spec/options/parser_spec.rb +0 -10
  50. data/spec/options/quiet_spec.rb +51 -0
  51. data/spec/options/verbose_spec.rb +51 -0
  52. data/spec/options/version_spec.rb +146 -0
  53. data/spec/options_spec.rb +46 -0
  54. data/spec/pager_spec.rb +1 -1
  55. data/spec/printing/fields_spec.rb +167 -0
  56. data/spec/printing/lists_spec.rb +99 -0
  57. data/spec/printing/tables/border_style.rb +43 -0
  58. data/spec/printing/tables/cell_builer_spec.rb +135 -0
  59. data/spec/printing/tables/row_builder_spec.rb +165 -0
  60. data/spec/printing/tables/style_spec.rb +377 -0
  61. data/spec/printing/tables/table_builder_spec.rb +252 -0
  62. data/spec/printing/tables/table_formatter_spec.rb +1180 -0
  63. data/spec/printing/tables_spec.rb +1069 -0
  64. data/spec/program_name_spec.rb +8 -0
  65. metadata +36 -7
@@ -76,8 +76,53 @@ module CommandKit
76
76
  # ANSI color code for white
77
77
  WHITE = "\e[37m"
78
78
 
79
+ # ANSI color code for black
80
+ #
81
+ # @since 0.3.0
82
+ BRIGHT_BLACK = "\e[90m"
83
+
84
+ # ANSI color code for red
85
+ #
86
+ # @since 0.3.0
87
+ BRIGHT_RED = "\e[91m"
88
+
89
+ # ANSI color code for green
90
+ #
91
+ # @since 0.3.0
92
+ BRIGHT_GREEN = "\e[92m"
93
+
94
+ # ANSI color code for yellow
95
+ #
96
+ # @since 0.3.0
97
+ BRIGHT_YELLOW = "\e[93m"
98
+
99
+ # ANSI color code for blue
100
+ #
101
+ # @since 0.3.0
102
+ BRIGHT_BLUE = "\e[94m"
103
+
104
+ # ANSI color code for magenta
105
+ #
106
+ # @since 0.3.0
107
+ BRIGHT_MAGENTA = "\e[95m"
108
+
109
+ # ANSI color code for cyan
110
+ #
111
+ # @since 0.3.0
112
+ BRIGHT_CYAN = "\e[96m"
113
+
114
+ # ANSI color code for white
115
+ #
116
+ # @since 0.3.0
117
+ BRIGHT_WHITE = "\e[97m"
118
+
79
119
  # ANSI color for the default foreground color
80
- RESET_COLOR = "\e[39m"
120
+ #
121
+ # @since 0.3.0
122
+ RESET_FG = "\e[39m"
123
+
124
+ # @see RESET_FG
125
+ RESET_COLOR = RESET_FG
81
126
 
82
127
  # ANSI color code for background color black
83
128
  #
@@ -119,6 +164,46 @@ module CommandKit
119
164
  # @since 0.2.0
120
165
  ON_WHITE = "\e[47m"
121
166
 
167
+ # ANSI color code for background color bright black
168
+ #
169
+ # @since 0.3.0
170
+ ON_BRIGHT_BLACK = "\e[100m"
171
+
172
+ # ANSI color code for background color bright red
173
+ #
174
+ # @since 0.3.0
175
+ ON_BRIGHT_RED = "\e[101m"
176
+
177
+ # ANSI color code for background color bright green
178
+ #
179
+ # @since 0.3.0
180
+ ON_BRIGHT_GREEN = "\e[102m"
181
+
182
+ # ANSI color code for background color bright yellow
183
+ #
184
+ # @since 0.3.0
185
+ ON_BRIGHT_YELLOW = "\e[103m"
186
+
187
+ # ANSI color code for background color bright blue
188
+ #
189
+ # @since 0.3.0
190
+ ON_BRIGHT_BLUE = "\e[104m"
191
+
192
+ # ANSI color code for background color bright magenta
193
+ #
194
+ # @since 0.3.0
195
+ ON_BRIGHT_MAGENTA = "\e[105m"
196
+
197
+ # ANSI color code for background color bright cyan
198
+ #
199
+ # @since 0.3.0
200
+ ON_BRIGHT_CYAN = "\e[106m"
201
+
202
+ # ANSI color code for background color bright white
203
+ #
204
+ # @since 0.3.0
205
+ ON_BRIGHT_WHITE = "\e[107m"
206
+
122
207
  # ANSI color for the default background color
123
208
  #
124
209
  # @since 0.2.0
@@ -126,6 +211,10 @@ module CommandKit
126
211
 
127
212
  module_function
128
213
 
214
+ #
215
+ # @group Styling Methods
216
+ #
217
+
129
218
  #
130
219
  # Resets text formatting.
131
220
  #
@@ -167,6 +256,10 @@ module CommandKit
167
256
  end
168
257
  end
169
258
 
259
+ #
260
+ # @group Foreground Color Methods
261
+ #
262
+
170
263
  #
171
264
  # Sets the text color to black.
172
265
  #
@@ -181,7 +274,7 @@ module CommandKit
181
274
  # @api public
182
275
  #
183
276
  def black(string=nil)
184
- if string then "#{BLACK}#{string}#{RESET_COLOR}"
277
+ if string then "#{BLACK}#{string}#{RESET_FG}"
185
278
  else BLACK
186
279
  end
187
280
  end
@@ -200,7 +293,7 @@ module CommandKit
200
293
  # @api public
201
294
  #
202
295
  def red(string=nil)
203
- if string then "#{RED}#{string}#{RESET_COLOR}"
296
+ if string then "#{RED}#{string}#{RESET_FG}"
204
297
  else RED
205
298
  end
206
299
  end
@@ -219,7 +312,7 @@ module CommandKit
219
312
  # @api public
220
313
  #
221
314
  def green(string=nil)
222
- if string then "#{GREEN}#{string}#{RESET_COLOR}"
315
+ if string then "#{GREEN}#{string}#{RESET_FG}"
223
316
  else GREEN
224
317
  end
225
318
  end
@@ -238,7 +331,7 @@ module CommandKit
238
331
  # @api public
239
332
  #
240
333
  def yellow(string=nil)
241
- if string then "#{YELLOW}#{string}#{RESET_COLOR}"
334
+ if string then "#{YELLOW}#{string}#{RESET_FG}"
242
335
  else YELLOW
243
336
  end
244
337
  end
@@ -257,7 +350,7 @@ module CommandKit
257
350
  # @api public
258
351
  #
259
352
  def blue(string=nil)
260
- if string then "#{BLUE}#{string}#{RESET_COLOR}"
353
+ if string then "#{BLUE}#{string}#{RESET_FG}"
261
354
  else BLUE
262
355
  end
263
356
  end
@@ -276,7 +369,7 @@ module CommandKit
276
369
  # @api public
277
370
  #
278
371
  def magenta(string=nil)
279
- if string then "#{MAGENTA}#{string}#{RESET_COLOR}"
372
+ if string then "#{MAGENTA}#{string}#{RESET_FG}"
280
373
  else MAGENTA
281
374
  end
282
375
  end
@@ -295,7 +388,7 @@ module CommandKit
295
388
  # @api public
296
389
  #
297
390
  def cyan(string=nil)
298
- if string then "#{CYAN}#{string}#{RESET_COLOR}"
391
+ if string then "#{CYAN}#{string}#{RESET_FG}"
299
392
  else CYAN
300
393
  end
301
394
  end
@@ -314,11 +407,201 @@ module CommandKit
314
407
  # @api public
315
408
  #
316
409
  def white(string=nil)
317
- if string then "#{WHITE}#{string}#{RESET_COLOR}"
410
+ if string then "#{WHITE}#{string}#{RESET_FG}"
318
411
  else WHITE
319
412
  end
320
413
  end
321
414
 
415
+ #
416
+ # Sets the text color to bright black (gray).
417
+ #
418
+ # @param [String, nil] string
419
+ # An optional string.
420
+ #
421
+ # @return [String, BRIGHT_BLACK]
422
+ # The colorized string or just {BRIGHT_BLACK} if no arguments were
423
+ # given.
424
+ #
425
+ # @see BRIGHT_BLACK
426
+ #
427
+ # @api public
428
+ #
429
+ # @since 0.3.0
430
+ #
431
+ def bright_black(string=nil)
432
+ if string then "#{BRIGHT_BLACK}#{string}#{RESET_FG}"
433
+ else BRIGHT_BLACK
434
+ end
435
+ end
436
+
437
+ #
438
+ # Sets the text color to gray.
439
+ #
440
+ # @api public
441
+ #
442
+ # @see #bright_black
443
+ #
444
+ # @since 0.3.0
445
+ #
446
+ def gray(string=nil)
447
+ bright_black(string)
448
+ end
449
+
450
+ #
451
+ # Sets the text color to bright red.
452
+ #
453
+ # @param [String, nil] string
454
+ # An optional string.
455
+ #
456
+ # @return [String, BRIGHT_RED]
457
+ # The colorized string or just {BRIGHT_RED} if no arguments were given.
458
+ #
459
+ # @see BRIGHT_RED
460
+ #
461
+ # @api public
462
+ #
463
+ # @since 0.3.0
464
+ #
465
+ def bright_red(string=nil)
466
+ if string then "#{BRIGHT_RED}#{string}#{RESET_FG}"
467
+ else BRIGHT_RED
468
+ end
469
+ end
470
+
471
+ #
472
+ # Sets the text color to bright green.
473
+ #
474
+ # @param [String, nil] string
475
+ # An optional string.
476
+ #
477
+ # @return [String, BRIGHT_GREEN]
478
+ # The colorized string or just {BRIGHT_GREEN} if no arguments were
479
+ # given.
480
+ #
481
+ # @see BRIGHT_GREEN
482
+ #
483
+ # @api public
484
+ #
485
+ # @since 0.3.0
486
+ #
487
+ def bright_green(string=nil)
488
+ if string then "#{BRIGHT_GREEN}#{string}#{RESET_FG}"
489
+ else BRIGHT_GREEN
490
+ end
491
+ end
492
+
493
+ #
494
+ # Sets the text color to bright yellow.
495
+ #
496
+ # @param [String, nil] string
497
+ # An optional string.
498
+ #
499
+ # @return [String, BRIGHT_YELLOW]
500
+ # The colorized string or just {BRIGHT_YELLOW} if no arguments were
501
+ # given.
502
+ #
503
+ # @see BRIGHT_YELLOW
504
+ #
505
+ # @api public
506
+ #
507
+ # @since 0.3.0
508
+ #
509
+ def bright_yellow(string=nil)
510
+ if string then "#{BRIGHT_YELLOW}#{string}#{RESET_FG}"
511
+ else BRIGHT_YELLOW
512
+ end
513
+ end
514
+
515
+ #
516
+ # Sets the text color to bright blue.
517
+ #
518
+ # @param [String, nil] string
519
+ # An optional string.
520
+ #
521
+ # @return [String, BRIGHT_BLUE]
522
+ # The colorized string or just {BRIGHT_BLUE} if no arguments were given.
523
+ #
524
+ # @see BRIGHT_BLUE
525
+ #
526
+ # @api public
527
+ #
528
+ # @since 0.3.0
529
+ #
530
+ def bright_blue(string=nil)
531
+ if string then "#{BRIGHT_BLUE}#{string}#{RESET_FG}"
532
+ else BRIGHT_BLUE
533
+ end
534
+ end
535
+
536
+ #
537
+ # Sets the text color to bright magenta.
538
+ #
539
+ # @param [String, nil] string
540
+ # An optional string.
541
+ #
542
+ # @return [String, BRIGHT_MAGENTA]
543
+ # The colorized string or just {BRIGHT_MAGENTA} if no arguments were
544
+ # given.
545
+ #
546
+ # @see BRIGHT_MAGENTA
547
+ #
548
+ # @api public
549
+ #
550
+ # @since 0.3.0
551
+ #
552
+ def bright_magenta(string=nil)
553
+ if string then "#{BRIGHT_MAGENTA}#{string}#{RESET_FG}"
554
+ else BRIGHT_MAGENTA
555
+ end
556
+ end
557
+
558
+ #
559
+ # Sets the text color to bright cyan.
560
+ #
561
+ # @param [String, nil] string
562
+ # An optional string.
563
+ #
564
+ # @return [String, BRIGHT_CYAN]
565
+ # The colorized string or just {BRIGHT_CYAN} if no arguments were given.
566
+ #
567
+ # @see BRIGHT_CYAN
568
+ #
569
+ # @api public
570
+ #
571
+ # @since 0.3.0
572
+ #
573
+ def bright_cyan(string=nil)
574
+ if string then "#{BRIGHT_CYAN}#{string}#{RESET_FG}"
575
+ else BRIGHT_CYAN
576
+ end
577
+ end
578
+
579
+ #
580
+ # Sets the text color to bright white.
581
+ #
582
+ # @param [String, nil] string
583
+ # An optional string.
584
+ #
585
+ # @return [String, BRIGHT_WHITE]
586
+ # The colorized string or just {BRIGHT_WHITE} if no arguments were
587
+ # given.
588
+ #
589
+ # @see BRIGHT_WHITE
590
+ #
591
+ # @api public
592
+ #
593
+ # @since 0.3.0
594
+ #
595
+ def bright_white(string=nil)
596
+ if string then "#{BRIGHT_WHITE}#{string}#{RESET_FG}"
597
+ else BRIGHT_WHITE
598
+ end
599
+ end
600
+
601
+ #
602
+ # @group Background Color Methods
603
+ #
604
+
322
605
  #
323
606
  # Sets the background color to black.
324
607
  #
@@ -486,6 +769,193 @@ module CommandKit
486
769
  else ON_WHITE
487
770
  end
488
771
  end
772
+
773
+ #
774
+ # Sets the background color to bright black.
775
+ #
776
+ # @param [String, nil] string
777
+ # An optional string.
778
+ #
779
+ # @return [String, ON_BRIGHT_BLACK]
780
+ # The colorized string or just {ON_BRIGHT_BLACK} if no arguments were
781
+ # given.
782
+ #
783
+ # @see ON_BRIGHT_BLACK
784
+ #
785
+ # @api public
786
+ #
787
+ # @since 0.3.0
788
+ #
789
+ def on_bright_black(string=nil)
790
+ if string then "#{ON_BRIGHT_BLACK}#{string}#{RESET_BG}"
791
+ else ON_BRIGHT_BLACK
792
+ end
793
+ end
794
+
795
+ #
796
+ # @see #on_bright_black
797
+ #
798
+ # @api public
799
+ #
800
+ # @since 0.3.0
801
+ #
802
+ def on_gray(string=nil)
803
+ on_bright_black(string)
804
+ end
805
+
806
+ #
807
+ # Sets the background color to bright red.
808
+ #
809
+ # @param [String, nil] string
810
+ # An optional string.
811
+ #
812
+ # @return [String, ON_BRIGHT_RED]
813
+ # The colorized string or just {ON_BRIGHT_RED} if no arguments were
814
+ # given.
815
+ #
816
+ # @see ON_BRIGHT_RED
817
+ #
818
+ # @api public
819
+ #
820
+ # @since 0.3.0
821
+ #
822
+ def on_bright_red(string=nil)
823
+ if string then "#{ON_BRIGHT_RED}#{string}#{RESET_BG}"
824
+ else ON_BRIGHT_RED
825
+ end
826
+ end
827
+
828
+ #
829
+ # Sets the background color to bright green.
830
+ #
831
+ # @param [String, nil] string
832
+ # An optional string.
833
+ #
834
+ # @return [String, ON_BRIGHT_GREEN]
835
+ # The colorized string or just {ON_BRIGHT_GREEN} if no arguments were
836
+ # given.
837
+ #
838
+ # @see ON_BRIGHT_GREEN
839
+ #
840
+ # @api public
841
+ #
842
+ # @since 0.3.0
843
+ #
844
+ def on_bright_green(string=nil)
845
+ if string then "#{ON_BRIGHT_GREEN}#{string}#{RESET_BG}"
846
+ else ON_BRIGHT_GREEN
847
+ end
848
+ end
849
+
850
+ #
851
+ # Sets the background color to bright yellow.
852
+ #
853
+ # @param [String, nil] string
854
+ # An optional string.
855
+ #
856
+ # @return [String, ON_BRIGHT_YELLOW]
857
+ # The colorized string or just {ON_BRIGHT_YELLOW} if no arguments were
858
+ # given.
859
+ #
860
+ # @see ON_BRIGHT_YELLOW
861
+ #
862
+ # @api public
863
+ #
864
+ # @since 0.3.0
865
+ #
866
+ def on_bright_yellow(string=nil)
867
+ if string then "#{ON_BRIGHT_YELLOW}#{string}#{RESET_BG}"
868
+ else ON_BRIGHT_YELLOW
869
+ end
870
+ end
871
+
872
+ #
873
+ # Sets the background color to bright blue.
874
+ #
875
+ # @param [String, nil] string
876
+ # An optional string.
877
+ #
878
+ # @return [String, ON_BRIGHT_BLUE]
879
+ # The colorized string or just {ON_BRIGHT_BLUE} if no arguments were
880
+ # given.
881
+ #
882
+ # @see ON_BRIGHT_BLUE
883
+ #
884
+ # @api public
885
+ #
886
+ # @since 0.3.0
887
+ #
888
+ def on_bright_blue(string=nil)
889
+ if string then "#{ON_BRIGHT_BLUE}#{string}#{RESET_BG}"
890
+ else ON_BRIGHT_BLUE
891
+ end
892
+ end
893
+
894
+ #
895
+ # Sets the background color to bright magenta.
896
+ #
897
+ # @param [String, nil] string
898
+ # An optional string.
899
+ #
900
+ # @return [String, ON_BRIGHT_MAGENTA]
901
+ # The colorized string or just {ON_BRIGHT_MAGENTA} if no arguments were
902
+ # given.
903
+ #
904
+ # @see ON_BRIGHT_MAGENTA
905
+ #
906
+ # @api public
907
+ #
908
+ # @since 0.3.0
909
+ #
910
+ def on_bright_magenta(string=nil)
911
+ if string then "#{ON_BRIGHT_MAGENTA}#{string}#{RESET_BG}"
912
+ else ON_BRIGHT_MAGENTA
913
+ end
914
+ end
915
+
916
+ #
917
+ # Sets the background color to bright cyan.
918
+ #
919
+ # @param [String, nil] string
920
+ # An optional string.
921
+ #
922
+ # @return [String, ON_BRIGHT_CYAN]
923
+ # The colorized string or just {ON_BRIGHT_CYAN} if no arguments were
924
+ # given.
925
+ #
926
+ # @see ON_BRIGHT_CYAN
927
+ #
928
+ # @api public
929
+ #
930
+ # @since 0.3.0
931
+ #
932
+ def on_bright_cyan(string=nil)
933
+ if string then "#{ON_BRIGHT_CYAN}#{string}#{RESET_BG}"
934
+ else ON_BRIGHT_CYAN
935
+ end
936
+ end
937
+
938
+ #
939
+ # Sets the background color to bright white.
940
+ #
941
+ # @param [String, nil] string
942
+ # An optional string.
943
+ #
944
+ # @return [String, ON_BRIGHT_WHITE]
945
+ # The colorized string or just {ON_BRIGHT_WHITE} if no arguments were
946
+ # given.
947
+ #
948
+ # @see ON_BRIGHT_WHITE
949
+ #
950
+ # @api public
951
+ #
952
+ # @since 0.3.0
953
+ #
954
+ def on_bright_white(string=nil)
955
+ if string then "#{ON_BRIGHT_WHITE}#{string}#{RESET_BG}"
956
+ else ON_BRIGHT_WHITE
957
+ end
958
+ end
489
959
  end
490
960
 
491
961
  #
@@ -508,8 +978,11 @@ module CommandKit
508
978
  end
509
979
 
510
980
  [
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
981
+ :bold,
982
+ :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white,
983
+ :bright_black, :gray, :bright_red, :bright_green, :bright_yellow, :bright_blue, :bright_magenta, :bright_cyan, :bright_white,
984
+ :on_black, :on_red, :on_green, :on_yellow, :on_blue, :on_magenta, :on_cyan, :on_white,
985
+ :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
513
986
  ].each do |name|
514
987
  define_method(name) do |string=nil|
515
988
  string || ''
@@ -525,14 +998,14 @@ module CommandKit
525
998
  # @return [Boolean]
526
999
  #
527
1000
  # @note
528
- # When the env variable `TERM` is set to `dumb`, it will disable color
529
- # output. Color output will also be disabled if the given stream is not
530
- # a TTY.
1001
+ # When the env variable `TERM` is set to `dumb` or when the `NO_COLOR`
1002
+ # env variable is set, it will disable color output. Color output will
1003
+ # also be disabled if the given stream is not a TTY.
531
1004
  #
532
1005
  # @api public
533
1006
  #
534
1007
  def ansi?(stream=stdout)
535
- env['TERM'] != 'dumb' && stream.tty?
1008
+ env['TERM'] != 'dumb' && !env['NO_COLOR'] && stream.tty?
536
1009
  end
537
1010
 
538
1011
  #
@@ -8,8 +8,7 @@ require 'command_kit/options'
8
8
  require 'command_kit/examples'
9
9
  require 'command_kit/description'
10
10
  require 'command_kit/exception_handler'
11
-
12
- require 'fileutils'
11
+ require 'command_kit/file_utils'
13
12
 
14
13
  module CommandKit
15
14
  #
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'command_kit/env'
4
+
5
+ module CommandKit
6
+ #
7
+ # Allows invoking the `EDITOR` environment variable.
8
+ #
9
+ # ## Environment Variables
10
+ #
11
+ # * `EDITOR` - The preferred editor command.
12
+ #
13
+ # ## Example
14
+ #
15
+ # if options[:edit]
16
+ # edit CONFIG_FILE
17
+ # end
18
+ #
19
+ # @since 0.4.0
20
+ #
21
+ module Edit
22
+ include Env
23
+
24
+ #
25
+ # The `EDITOR` environment variable.
26
+ #
27
+ # @return [String]
28
+ # The `EDITOR` environment variable, or `"nano"` if `EDITOR` was not set.
29
+ #
30
+ # @api semipublic
31
+ #
32
+ def editor
33
+ env['EDITOR'] || 'nano'
34
+ end
35
+
36
+ #
37
+ # Invokes the preferred editor with the additional arguments.
38
+ #
39
+ # @param [Array] arguments
40
+ # The additional arguments to pass to the editor command.
41
+ #
42
+ # @return [Boolean, nil]
43
+ # Indicates whether the editor successfully launched and exited.
44
+ # If the {#editor} command was not installed, `nil` will be returned.
45
+ #
46
+ # @api public
47
+ #
48
+ def edit(*arguments)
49
+ if editor
50
+ system(editor,*arguments.map(&:to_s))
51
+ end
52
+ end
53
+ end
54
+ end
@@ -7,7 +7,7 @@ module CommandKit
7
7
  # class MyCmd
8
8
  # include CommandKit::Env
9
9
  #
10
- # def main
10
+ # def run
11
11
  # home = env['HOME']
12
12
  # # ...
13
13
  # end