command_kit 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +15 -0
- data/.rubocop.yml +138 -0
- data/ChangeLog.md +29 -0
- data/Gemfile +3 -0
- data/README.md +141 -121
- data/Rakefile +3 -2
- data/command_kit.gemspec +4 -4
- data/examples/command.rb +1 -1
- data/gemspec.yml +7 -0
- data/lib/command_kit/arguments.rb +1 -1
- data/lib/command_kit/colors.rb +221 -45
- data/lib/command_kit/command.rb +1 -1
- data/lib/command_kit/commands.rb +4 -4
- data/lib/command_kit/help/man.rb +4 -25
- data/lib/command_kit/inflector.rb +47 -17
- data/lib/command_kit/main.rb +7 -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 +1 -6
- data/lib/command_kit/options/parser.rb +15 -17
- data/lib/command_kit/options.rb +2 -2
- data/lib/command_kit/os/linux.rb +157 -0
- data/lib/command_kit/os.rb +159 -11
- data/lib/command_kit/package_manager.rb +200 -0
- data/lib/command_kit/pager.rb +46 -4
- data/lib/command_kit/printing/indent.rb +2 -2
- data/lib/command_kit/printing.rb +1 -1
- data/lib/command_kit/sudo.rb +40 -0
- data/lib/command_kit/terminal.rb +5 -0
- data/lib/command_kit/version.rb +1 -1
- data/spec/arguments/argument_spec.rb +1 -1
- data/spec/colors_spec.rb +256 -0
- data/spec/commands_spec.rb +1 -1
- data/spec/exception_handler_spec.rb +1 -1
- data/spec/help/man_spec.rb +0 -32
- data/spec/inflector_spec.rb +70 -8
- data/spec/man_spec.rb +46 -0
- data/spec/open_app_spec.rb +85 -0
- data/spec/options/option_spec.rb +2 -2
- data/spec/os/linux_spec.rb +154 -0
- data/spec/os_spec.rb +200 -13
- data/spec/package_manager_spec.rb +806 -0
- data/spec/pager_spec.rb +71 -6
- data/spec/sudo_spec.rb +51 -0
- data/spec/terminal_spec.rb +30 -0
- data/spec/usage_spec.rb +1 -1
- metadata +19 -4
data/Rakefile
CHANGED
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 =
|
27
|
-
|
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
data/gemspec.yml
CHANGED
@@ -9,6 +9,13 @@ authors: Postmodern
|
|
9
9
|
email: postmodern.mod3@gmail.com
|
10
10
|
homepage: https://github.com/postmodern/command_kit.rb#readme
|
11
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
|
+
|
18
|
+
|
12
19
|
required_ruby_version: ">= 2.7.0"
|
13
20
|
|
14
21
|
development_dependencies:
|
data/lib/command_kit/colors.rb
CHANGED
@@ -26,7 +26,7 @@ module CommandKit
|
|
26
26
|
#
|
27
27
|
# ## Alternatives
|
28
28
|
#
|
29
|
-
# * [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
|
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 megenta
|
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
|
#
|
@@ -273,71 +318,202 @@ module CommandKit
|
|
273
318
|
else WHITE
|
274
319
|
end
|
275
320
|
end
|
276
|
-
end
|
277
321
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
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
|
298
342
|
|
299
|
-
|
300
|
-
|
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
|
301
362
|
end
|
302
363
|
|
303
|
-
|
304
|
-
|
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
|
305
383
|
end
|
306
384
|
|
307
|
-
|
308
|
-
|
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
|
309
404
|
end
|
310
405
|
|
311
|
-
|
312
|
-
|
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
|
313
425
|
end
|
314
426
|
|
315
|
-
|
316
|
-
|
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
|
317
446
|
end
|
318
447
|
|
319
|
-
|
320
|
-
|
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
|
321
467
|
end
|
322
468
|
|
323
|
-
|
324
|
-
|
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
|
325
488
|
end
|
489
|
+
end
|
326
490
|
|
327
|
-
|
328
|
-
|
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,'')
|
329
498
|
end
|
330
499
|
|
331
|
-
|
332
|
-
|
500
|
+
module_function
|
501
|
+
|
502
|
+
def reset
|
503
|
+
RESET
|
333
504
|
end
|
334
505
|
|
335
|
-
def
|
336
|
-
|
506
|
+
def clear
|
507
|
+
reset
|
337
508
|
end
|
338
509
|
|
339
|
-
|
340
|
-
|
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
|
341
517
|
end
|
342
518
|
end
|
343
519
|
|
data/lib/command_kit/command.rb
CHANGED
data/lib/command_kit/commands.rb
CHANGED
data/lib/command_kit/help/man.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'command_kit/command_name'
|
4
4
|
require 'command_kit/help'
|
5
5
|
require 'command_kit/stdio'
|
6
|
+
require 'command_kit/man'
|
6
7
|
|
7
8
|
module CommandKit
|
8
9
|
module Help
|
@@ -23,6 +24,7 @@ module CommandKit
|
|
23
24
|
include CommandName
|
24
25
|
include Help
|
25
26
|
include Stdio
|
27
|
+
include CommandKit::Man
|
26
28
|
|
27
29
|
#
|
28
30
|
# @api private
|
@@ -96,29 +98,6 @@ module CommandKit
|
|
96
98
|
end
|
97
99
|
end
|
98
100
|
|
99
|
-
#
|
100
|
-
# Displays the given man page.
|
101
|
-
#
|
102
|
-
# @param [String] page
|
103
|
-
# The man page file name.
|
104
|
-
#
|
105
|
-
# @param [Integer, String, nil] section
|
106
|
-
# The optional section number to specify.
|
107
|
-
#
|
108
|
-
# @return [Boolean, nil]
|
109
|
-
# Specifies whether the `man` command was successful or not.
|
110
|
-
# Returns `nil` when the `man` command is not installed.
|
111
|
-
#
|
112
|
-
# @api public
|
113
|
-
#
|
114
|
-
def man(page, section: nil)
|
115
|
-
if section
|
116
|
-
system('man',section.to_s,page.to_s)
|
117
|
-
else
|
118
|
-
system('man',page.to_s)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
101
|
#
|
123
102
|
# Provides help information by showing one of the man pages within
|
124
103
|
# {ClassMethods#man_dir .man_dir}.
|
@@ -153,8 +132,8 @@ module CommandKit
|
|
153
132
|
# {ClassMethods#man_dir .man_dir} does not have a value.
|
154
133
|
#
|
155
134
|
# @note
|
156
|
-
# if `TERM` is `dumb` or `$stdout` is not a TTY,
|
157
|
-
# the usual `--help` output.
|
135
|
+
# if `TERM` is `dumb` or `$stdout` is not a TTY, will fall back to
|
136
|
+
# printing the usual `--help` output.
|
158
137
|
#
|
159
138
|
# @api public
|
160
139
|
#
|