command_kit 0.1.0.pre2 → 0.2.1
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 +141 -0
- data/ChangeLog.md +98 -2
- data/Gemfile +3 -0
- data/README.md +189 -117
- data/Rakefile +3 -2
- data/command_kit.gemspec +4 -4
- data/examples/command.rb +1 -1
- data/gemspec.yml +10 -2
- data/lib/command_kit/arguments/argument.rb +2 -0
- data/lib/command_kit/arguments/argument_value.rb +2 -0
- data/lib/command_kit/arguments.rb +23 -4
- data/lib/command_kit/colors.rb +253 -45
- data/lib/command_kit/command.rb +6 -1
- data/lib/command_kit/command_name.rb +9 -0
- data/lib/command_kit/commands/auto_load.rb +24 -1
- data/lib/command_kit/commands/auto_require.rb +16 -0
- data/lib/command_kit/commands/command.rb +3 -0
- data/lib/command_kit/commands/help.rb +5 -2
- data/lib/command_kit/commands/parent_command.rb +7 -0
- data/lib/command_kit/commands/subcommand.rb +13 -1
- data/lib/command_kit/commands.rb +54 -9
- data/lib/command_kit/description.rb +12 -1
- data/lib/command_kit/env/home.rb +9 -0
- data/lib/command_kit/env/path.rb +16 -1
- data/lib/command_kit/env.rb +4 -0
- data/lib/command_kit/examples.rb +12 -1
- data/lib/command_kit/exception_handler.rb +4 -0
- data/lib/command_kit/help/man.rb +26 -30
- data/lib/command_kit/help.rb +7 -1
- data/lib/command_kit/inflector.rb +49 -17
- data/lib/command_kit/interactive.rb +248 -0
- data/lib/command_kit/main.rb +18 -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 +3 -6
- data/lib/command_kit/options/option_value.rb +5 -2
- data/lib/command_kit/options/parser.rb +46 -19
- data/lib/command_kit/options/quiet.rb +3 -0
- data/lib/command_kit/options/verbose.rb +5 -0
- data/lib/command_kit/options/version.rb +6 -0
- data/lib/command_kit/options.rb +32 -7
- data/lib/command_kit/os/linux.rb +157 -0
- data/lib/command_kit/os.rb +165 -11
- data/lib/command_kit/package_manager.rb +200 -0
- data/lib/command_kit/pager.rb +80 -11
- data/lib/command_kit/printing/indent.rb +27 -4
- data/lib/command_kit/printing.rb +35 -1
- data/lib/command_kit/program_name.rb +7 -0
- data/lib/command_kit/stdio.rb +24 -0
- data/lib/command_kit/sudo.rb +40 -0
- data/lib/command_kit/terminal.rb +159 -0
- data/lib/command_kit/usage.rb +14 -0
- data/lib/command_kit/version.rb +1 -1
- data/lib/command_kit/xdg.rb +13 -0
- data/lib/command_kit.rb +1 -0
- data/spec/arguments/argument_spec.rb +2 -2
- data/spec/arguments_spec.rb +53 -27
- data/spec/colors_spec.rb +277 -13
- data/spec/command_name_spec.rb +1 -1
- data/spec/command_spec.rb +79 -5
- data/spec/commands/auto_load/subcommand_spec.rb +1 -1
- data/spec/commands/auto_load_spec.rb +34 -3
- data/spec/commands/auto_require_spec.rb +2 -2
- data/spec/commands/help_spec.rb +1 -1
- data/spec/commands/parent_command_spec.rb +1 -1
- data/spec/commands/subcommand_spec.rb +1 -1
- data/spec/commands_spec.rb +103 -29
- data/spec/description_spec.rb +1 -25
- data/spec/env/home_spec.rb +1 -1
- data/spec/env/path_spec.rb +7 -1
- data/spec/examples_spec.rb +1 -25
- data/spec/exception_handler_spec.rb +1 -1
- data/spec/help/man_spec.rb +45 -58
- data/spec/help_spec.rb +0 -25
- data/spec/inflector_spec.rb +71 -9
- data/spec/interactive_spec.rb +415 -0
- data/spec/main_spec.rb +7 -7
- data/spec/man_spec.rb +46 -0
- data/spec/open_app_spec.rb +85 -0
- data/spec/options/option_spec.rb +5 -5
- data/spec/options/option_value_spec.rb +56 -1
- data/spec/options_spec.rb +283 -1
- data/spec/os/linux_spec.rb +164 -0
- data/spec/os_spec.rb +201 -14
- data/spec/package_manager_spec.rb +806 -0
- data/spec/pager_spec.rb +76 -11
- data/spec/printing/indent_spec.rb +8 -6
- data/spec/printing_spec.rb +33 -3
- data/spec/program_name_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -3
- data/spec/sudo_spec.rb +51 -0
- data/spec/{console_spec.rb → terminal_spec.rb} +65 -35
- data/spec/usage_spec.rb +2 -2
- data/spec/xdg_spec.rb +1 -1
- metadata +26 -8
- data/lib/command_kit/console.rb +0 -141
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: command_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
27
|
description: A Ruby toolkit for building clean, correct, and robust CLI commands as
|
28
|
-
Ruby classes.
|
28
|
+
plain-old Ruby classes.
|
29
29
|
email: postmodern.mod3@gmail.com
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- ".github/workflows/ruby.yml"
|
39
39
|
- ".gitignore"
|
40
40
|
- ".rspec"
|
41
|
+
- ".rubocop.yml"
|
41
42
|
- ".yardopts"
|
42
43
|
- ChangeLog.md
|
43
44
|
- Gemfile
|
@@ -64,7 +65,6 @@ files:
|
|
64
65
|
- lib/command_kit/commands/help.rb
|
65
66
|
- lib/command_kit/commands/parent_command.rb
|
66
67
|
- lib/command_kit/commands/subcommand.rb
|
67
|
-
- lib/command_kit/console.rb
|
68
68
|
- lib/command_kit/description.rb
|
69
69
|
- lib/command_kit/env.rb
|
70
70
|
- lib/command_kit/env/home.rb
|
@@ -74,7 +74,10 @@ files:
|
|
74
74
|
- lib/command_kit/help.rb
|
75
75
|
- lib/command_kit/help/man.rb
|
76
76
|
- lib/command_kit/inflector.rb
|
77
|
+
- lib/command_kit/interactive.rb
|
77
78
|
- lib/command_kit/main.rb
|
79
|
+
- lib/command_kit/man.rb
|
80
|
+
- lib/command_kit/open_app.rb
|
78
81
|
- lib/command_kit/options.rb
|
79
82
|
- lib/command_kit/options/option.rb
|
80
83
|
- lib/command_kit/options/option_value.rb
|
@@ -83,11 +86,15 @@ files:
|
|
83
86
|
- lib/command_kit/options/verbose.rb
|
84
87
|
- lib/command_kit/options/version.rb
|
85
88
|
- lib/command_kit/os.rb
|
89
|
+
- lib/command_kit/os/linux.rb
|
90
|
+
- lib/command_kit/package_manager.rb
|
86
91
|
- lib/command_kit/pager.rb
|
87
92
|
- lib/command_kit/printing.rb
|
88
93
|
- lib/command_kit/printing/indent.rb
|
89
94
|
- lib/command_kit/program_name.rb
|
90
95
|
- lib/command_kit/stdio.rb
|
96
|
+
- lib/command_kit/sudo.rb
|
97
|
+
- lib/command_kit/terminal.rb
|
91
98
|
- lib/command_kit/usage.rb
|
92
99
|
- lib/command_kit/version.rb
|
93
100
|
- lib/command_kit/xdg.rb
|
@@ -108,7 +115,6 @@ files:
|
|
108
115
|
- spec/commands/parent_command_spec.rb
|
109
116
|
- spec/commands/subcommand_spec.rb
|
110
117
|
- spec/commands_spec.rb
|
111
|
-
- spec/console_spec.rb
|
112
118
|
- spec/description_spec.rb
|
113
119
|
- spec/env/home_spec.rb
|
114
120
|
- spec/env/path_spec.rb
|
@@ -118,24 +124,36 @@ files:
|
|
118
124
|
- spec/help/man_spec.rb
|
119
125
|
- spec/help_spec.rb
|
120
126
|
- spec/inflector_spec.rb
|
127
|
+
- spec/interactive_spec.rb
|
121
128
|
- spec/main_spec.rb
|
129
|
+
- spec/man_spec.rb
|
130
|
+
- spec/open_app_spec.rb
|
122
131
|
- spec/options/option_spec.rb
|
123
132
|
- spec/options/option_value_spec.rb
|
124
133
|
- spec/options/parser_spec.rb
|
125
134
|
- spec/options_spec.rb
|
135
|
+
- spec/os/linux_spec.rb
|
126
136
|
- spec/os_spec.rb
|
137
|
+
- spec/package_manager_spec.rb
|
127
138
|
- spec/pager_spec.rb
|
128
139
|
- spec/printing/indent_spec.rb
|
129
140
|
- spec/printing_spec.rb
|
130
141
|
- spec/program_name_spec.rb
|
131
142
|
- spec/spec_helper.rb
|
132
143
|
- spec/stdio_spec.rb
|
144
|
+
- spec/sudo_spec.rb
|
145
|
+
- spec/terminal_spec.rb
|
133
146
|
- spec/usage_spec.rb
|
134
147
|
- spec/xdg_spec.rb
|
135
|
-
homepage: https://github.com/postmodern/command_kit#readme
|
148
|
+
homepage: https://github.com/postmodern/command_kit.rb#readme
|
136
149
|
licenses:
|
137
150
|
- MIT
|
138
|
-
metadata:
|
151
|
+
metadata:
|
152
|
+
documentation_uri: https://rubydoc.info/gems/command_kit
|
153
|
+
source_code_uri: https://github.com/postmodern/command_kit.rb
|
154
|
+
bug_tracker_uri: https://github.com/postmodern/command_kit.rb/issues
|
155
|
+
changelog_uri: https://github.com/postmodern/command_kit.rb/blob/main/ChangeLog.md
|
156
|
+
rubygems_mfa_required: 'true'
|
139
157
|
post_install_message:
|
140
158
|
rdoc_options: []
|
141
159
|
require_paths:
|
@@ -151,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
169
|
- !ruby/object:Gem::Version
|
152
170
|
version: '0'
|
153
171
|
requirements: []
|
154
|
-
rubygems_version: 3.2.
|
172
|
+
rubygems_version: 3.2.22
|
155
173
|
signing_key:
|
156
174
|
specification_version: 4
|
157
175
|
summary: A toolkit for building Ruby CLI commands
|
data/lib/command_kit/console.rb
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
require 'command_kit/stdio'
|
2
|
-
require 'command_kit/env'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'io/console'
|
6
|
-
rescue LoadError
|
7
|
-
end
|
8
|
-
|
9
|
-
module CommandKit
|
10
|
-
#
|
11
|
-
# Provides access to [IO.console] and [IO.console_size].
|
12
|
-
#
|
13
|
-
# ## Environment Variables
|
14
|
-
#
|
15
|
-
# * `LINES` - The explicit number of lines or rows the console should have.
|
16
|
-
# * `COLUMNS` - The explicit number of columns the console should have.
|
17
|
-
#
|
18
|
-
# [IO.console]: https://rubydoc.info/gems/io-console/IO#console-class_method
|
19
|
-
# [IO#winsize]: https://rubydoc.info/gems/io-console/IO#winsize-instance_method
|
20
|
-
#
|
21
|
-
module Console
|
22
|
-
include Stdio
|
23
|
-
include Env
|
24
|
-
|
25
|
-
# The default console height to fallback to.
|
26
|
-
DEFAULT_HEIGHT = 25
|
27
|
-
|
28
|
-
# The default console width to fallback to.
|
29
|
-
DEFAULT_WIDTH = 80
|
30
|
-
|
31
|
-
#
|
32
|
-
# Initializes any console settings.
|
33
|
-
#
|
34
|
-
# @param [Hash{Symbol => Object}] kwargs
|
35
|
-
# Additional keyword arguments.
|
36
|
-
#
|
37
|
-
# @note
|
38
|
-
# If the `$LINES` env variable is set, and is non-zero, it will be
|
39
|
-
# returned by {#console_height}.
|
40
|
-
#
|
41
|
-
# @note
|
42
|
-
# If the `$COLUMNS` env variable is set, and is non-zero, it will be
|
43
|
-
# returned by {#console_width}.
|
44
|
-
#
|
45
|
-
def initialize(**kwargs)
|
46
|
-
super(**kwargs)
|
47
|
-
|
48
|
-
@default_console_height = if (lines = env['LINES'])
|
49
|
-
lines.to_i
|
50
|
-
else
|
51
|
-
DEFAULT_HEIGHT
|
52
|
-
end
|
53
|
-
|
54
|
-
@default_console_width = if (columns = env['COLUMNS'])
|
55
|
-
columns.to_i
|
56
|
-
else
|
57
|
-
DEFAULT_WIDTH
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
#
|
62
|
-
# Determines if there is a console present.
|
63
|
-
#
|
64
|
-
# @return [Boolean]
|
65
|
-
# Specifies whether {Stdio#stdout stdout} is connected to a console.
|
66
|
-
#
|
67
|
-
def console?
|
68
|
-
IO.respond_to?(:console) && stdout.tty?
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# Returns the console object, if {Stdio#stdout stdout} is connected to a
|
73
|
-
# console.
|
74
|
-
#
|
75
|
-
# @return [IO, nil]
|
76
|
-
# The IO objects or `nil` if {Stdio#stdout stdout} is not connected to a
|
77
|
-
# console.
|
78
|
-
#
|
79
|
-
# @example
|
80
|
-
# console
|
81
|
-
# # => #<File:/dev/tty>
|
82
|
-
#
|
83
|
-
def console
|
84
|
-
IO.console if console?
|
85
|
-
end
|
86
|
-
|
87
|
-
#
|
88
|
-
# Returns the console's height in number of lines.
|
89
|
-
#
|
90
|
-
# @return [Integer]
|
91
|
-
# The console's height in number of lines.
|
92
|
-
#
|
93
|
-
# @example
|
94
|
-
# console_height
|
95
|
-
# # => 22
|
96
|
-
#
|
97
|
-
def console_height
|
98
|
-
if (console = self.console)
|
99
|
-
console.winsize[0]
|
100
|
-
else
|
101
|
-
@default_console_height
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
#
|
106
|
-
# Returns the console's width in number of lines.
|
107
|
-
#
|
108
|
-
# @return [Integer]
|
109
|
-
# The console's width in number of columns.
|
110
|
-
#
|
111
|
-
# @example
|
112
|
-
# console_width
|
113
|
-
# # => 91
|
114
|
-
#
|
115
|
-
def console_width
|
116
|
-
if (console = self.console)
|
117
|
-
console.winsize[1]
|
118
|
-
else
|
119
|
-
@default_console_width
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
#
|
124
|
-
# The console height (lines) and width (columns).
|
125
|
-
#
|
126
|
-
# @return [(Integer, Integer)]
|
127
|
-
# Returns the height and width of the console.
|
128
|
-
#
|
129
|
-
# @example
|
130
|
-
# console_size
|
131
|
-
# # => [23, 91]
|
132
|
-
#
|
133
|
-
def console_size
|
134
|
-
if (console = self.console)
|
135
|
-
console.winsize
|
136
|
-
else
|
137
|
-
[@default_console_height, @default_console_width]
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|