command_kit 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +6 -0
- data/README.md +3 -0
- data/command_kit.gemspec +7 -2
- data/lib/command_kit/completion/install.rb +276 -0
- data/lib/command_kit/env/prefix.rb +41 -0
- data/lib/command_kit/env/shell.rb +58 -0
- data/lib/command_kit/version.rb +1 -1
- metadata +4 -64
- data/spec/arguments/argument_spec.rb +0 -133
- data/spec/arguments/argument_value_spec.rb +0 -66
- data/spec/arguments_spec.rb +0 -279
- data/spec/bug_report_spec.rb +0 -266
- data/spec/colors_spec.rb +0 -771
- data/spec/command_kit_spec.rb +0 -8
- data/spec/command_name_spec.rb +0 -130
- data/spec/command_spec.rb +0 -123
- data/spec/commands/auto_load/subcommand_spec.rb +0 -82
- data/spec/commands/auto_load_spec.rb +0 -159
- data/spec/commands/auto_require_spec.rb +0 -142
- data/spec/commands/fixtures/test_auto_load/cli/commands/test1.rb +0 -10
- data/spec/commands/fixtures/test_auto_load/cli/commands/test2.rb +0 -10
- data/spec/commands/fixtures/test_auto_require/lib/test_auto_require/cli/commands/test1.rb +0 -10
- data/spec/commands/help_spec.rb +0 -66
- data/spec/commands/parent_command_spec.rb +0 -40
- data/spec/commands/subcommand_spec.rb +0 -99
- data/spec/commands_spec.rb +0 -865
- data/spec/description_spec.rb +0 -179
- data/spec/edit_spec.rb +0 -72
- data/spec/env/home_spec.rb +0 -46
- data/spec/env/path_spec.rb +0 -84
- data/spec/env_spec.rb +0 -123
- data/spec/examples_spec.rb +0 -211
- data/spec/exception_handler_spec.rb +0 -103
- data/spec/file_utils_spec.rb +0 -59
- data/spec/fixtures/template.erb +0 -5
- data/spec/help/man_spec.rb +0 -345
- data/spec/help_spec.rb +0 -94
- data/spec/inflector_spec.rb +0 -166
- data/spec/interactive_spec.rb +0 -415
- data/spec/main_spec.rb +0 -179
- data/spec/man_spec.rb +0 -46
- data/spec/open_app_spec.rb +0 -85
- data/spec/options/option_spec.rb +0 -343
- data/spec/options/option_value_spec.rb +0 -171
- data/spec/options/parser_spec.rb +0 -274
- data/spec/options/quiet_spec.rb +0 -51
- data/spec/options/verbose_spec.rb +0 -51
- data/spec/options/version_spec.rb +0 -146
- data/spec/options_spec.rb +0 -465
- data/spec/os/linux_spec.rb +0 -164
- data/spec/os_spec.rb +0 -233
- data/spec/package_manager_spec.rb +0 -806
- data/spec/pager_spec.rb +0 -217
- data/spec/printing/fields_spec.rb +0 -167
- data/spec/printing/indent_spec.rb +0 -132
- data/spec/printing/lists_spec.rb +0 -99
- data/spec/printing/tables/border_style.rb +0 -43
- data/spec/printing/tables/cell_builer_spec.rb +0 -135
- data/spec/printing/tables/row_builder_spec.rb +0 -165
- data/spec/printing/tables/style_spec.rb +0 -377
- data/spec/printing/tables/table_builder_spec.rb +0 -252
- data/spec/printing/tables/table_formatter_spec.rb +0 -1190
- data/spec/printing/tables_spec.rb +0 -1069
- data/spec/printing_spec.rb +0 -106
- data/spec/program_name_spec.rb +0 -70
- data/spec/spec_helper.rb +0 -3
- data/spec/stdio_spec.rb +0 -264
- data/spec/sudo_spec.rb +0 -51
- data/spec/terminal_spec.rb +0 -231
- data/spec/usage_spec.rb +0 -237
- data/spec/xdg_spec.rb +0 -191
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f815869f166ce21da0c32699e8dcd7cebdb17cdbcc74fba1be3572ebb2d15a0
|
4
|
+
data.tar.gz: 2e2db9a8f190308d473959274dad507095baba55e0e73f7fcd969a4f23267054
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0055ba75d1dc4aef15bf280ed86f5d4a514e5e95c00bc1285c9f29327d5b03ab4415a6001bc4ee05be04bb5504b2d6a0a8de0d33f6048a1ea333adb93915f54
|
7
|
+
data.tar.gz: a198cc0fe966abb5f20f5025b52144bce290d06602e93afd13e2eca03d8aa87477511a598562f023ef921490084c200896c453e78b75d9061216dc8e548f923b
|
data/ChangeLog.md
CHANGED
data/README.md
CHANGED
@@ -214,11 +214,14 @@ end
|
|
214
214
|
* [CommandKit::Commands](https://rubydoc.info/gems/command_kit/CommandKit/Commands)
|
215
215
|
* [CommandKit::Commands::AutoLoad](https://rubydoc.info/gems/command_kit/CommandKit/Commands/AutoLoad)
|
216
216
|
* [CommandKit::Commands::AutoRequire](https://rubydoc.info/gems/command_kit/CommandKit/Commands/AutoRequire)
|
217
|
+
* [CommandKit::Completion::Install](https://rubydoc.info/gems/command_kit/CommandKit/Completion/Install)
|
217
218
|
* [CommandKit::Description](https://rubydoc.info/gems/command_kit/CommandKit/Description)
|
218
219
|
* [CommandKit::Edit](https://rubydoc.info/gems/command_kit/CommandKit/Edit)
|
219
220
|
* [CommandKit::Env](https://rubydoc.info/gems/command_kit/CommandKit/Env)
|
220
221
|
* [CommandKit::Env::Home](https://rubydoc.info/gems/command_kit/CommandKit/Env/Home)
|
221
222
|
* [CommandKit::Env::Path](https://rubydoc.info/gems/command_kit/CommandKit/Env/Path)
|
223
|
+
* [CommandKit::Env::Prefix](https://rubydoc.info/gems/command_kit/CommandKit/Env/Prefix)
|
224
|
+
* [CommandKit::Env::Shell](https://rubydoc.info/gems/command_kit/CommandKit/Env/Shell)
|
222
225
|
* [CommandKit::Examples](https://rubydoc.info/gems/command_kit/CommandKit/Examples)
|
223
226
|
* [CommandKit::ExceptionHandler](https://rubydoc.info/gems/command_kit/CommandKit/ExceptionHandler)
|
224
227
|
* [CommandKit::FileUtils](https://rubydoc.info/gems/command_kit/CommandKit/FileUtils)
|
data/command_kit.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'yaml'
|
2
4
|
|
3
5
|
Gem::Specification.new do |gem|
|
@@ -20,12 +22,15 @@ Gem::Specification.new do |gem|
|
|
20
22
|
gem.homepage = gemspec['homepage']
|
21
23
|
gem.metadata = gemspec['metadata'] if gemspec['metadata']
|
22
24
|
|
23
|
-
glob =
|
25
|
+
glob = ->(patterns) { gem.files & Dir[*patterns] }
|
24
26
|
|
25
27
|
gem.files = if gemspec['files'] then glob[gemspec['files']]
|
26
28
|
else `git ls-files`.split($/)
|
27
29
|
end
|
28
30
|
|
31
|
+
# exclude test files from the packages gem
|
32
|
+
gem.files -= glob[gemspec['test_files'] || 'spec/{**/}*']
|
33
|
+
|
29
34
|
gem.executables = gemspec.fetch('executables') do
|
30
35
|
glob['bin/*'].map { |path| File.basename(path) }
|
31
36
|
end
|
@@ -43,7 +48,7 @@ Gem::Specification.new do |gem|
|
|
43
48
|
gem.required_rubygems_version = gemspec['required_rubygems_version']
|
44
49
|
gem.post_install_message = gemspec['post_install_message']
|
45
50
|
|
46
|
-
split =
|
51
|
+
split = ->(string) { string.split(/,\s*/) }
|
47
52
|
|
48
53
|
if gemspec['dependencies']
|
49
54
|
gemspec['dependencies'].each do |name,versions|
|
@@ -0,0 +1,276 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'command_kit/printing'
|
4
|
+
require 'command_kit/env/home'
|
5
|
+
require 'command_kit/env/shell'
|
6
|
+
require 'command_kit/env/prefix'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
module CommandKit
|
10
|
+
module Completion
|
11
|
+
#
|
12
|
+
# Mixins that adds methods for installing shell completion files.
|
13
|
+
#
|
14
|
+
# ## Environment Variables
|
15
|
+
#
|
16
|
+
# * `SHELL` - The current shell.
|
17
|
+
# * `PREFIX` - The optional root prefix of the file-system.
|
18
|
+
#
|
19
|
+
# @api public
|
20
|
+
#
|
21
|
+
# @since 0.5.0
|
22
|
+
#
|
23
|
+
module Install
|
24
|
+
include Printing
|
25
|
+
include Env::Home
|
26
|
+
include Env::Shell
|
27
|
+
include Env::Prefix
|
28
|
+
|
29
|
+
# The installation directory for completion files for the current shell.
|
30
|
+
#
|
31
|
+
# @return [String, nil]
|
32
|
+
# * Bash
|
33
|
+
# * Regular users: `~/.local/share/bash-completion/completions`
|
34
|
+
# * Root users:`$PREFIX/usr/local/share/bash-completion/completions`
|
35
|
+
# * Zsh: `$PREFIX/usr/local/share/zsh/site-functions`
|
36
|
+
# * Fish:
|
37
|
+
# * Regular users: `~/.config/fish/completions`
|
38
|
+
# * Root users: `$PREFIX/usr/local/share/fish/completions`
|
39
|
+
#
|
40
|
+
# @api private
|
41
|
+
attr_reader :completions_dir
|
42
|
+
|
43
|
+
#
|
44
|
+
# Initialize {#completions_dir} based on the `SHELL` environment variable
|
45
|
+
# and the UID of the process.
|
46
|
+
#
|
47
|
+
# @param [Hash{Symbol => Object}] kwargs
|
48
|
+
# Additional keyword arguments.
|
49
|
+
#
|
50
|
+
# @api public
|
51
|
+
#
|
52
|
+
def initialize(**kwargs)
|
53
|
+
super(**kwargs)
|
54
|
+
|
55
|
+
@completions_dir = case shell_type
|
56
|
+
when :bash
|
57
|
+
if Process.uid == 0
|
58
|
+
File.join(root,'usr','local','share','bash-completion','completions')
|
59
|
+
else
|
60
|
+
xdg_data_home = env.fetch('XDG_DATA_HOME') do
|
61
|
+
File.join(home_dir,'.local','share')
|
62
|
+
end
|
63
|
+
|
64
|
+
File.join(xdg_data_home,'bash-completion','completions')
|
65
|
+
end
|
66
|
+
when :zsh
|
67
|
+
File.join(root,'usr','local','share','zsh','site-functions')
|
68
|
+
when :fish
|
69
|
+
if Process.uid == 0
|
70
|
+
File.join(root,'usr','local','share','fish','completions')
|
71
|
+
else
|
72
|
+
xdg_config_home = env.fetch('XDG_CONFIG_HOME') do
|
73
|
+
File.join(home_dir,'.config')
|
74
|
+
end
|
75
|
+
|
76
|
+
File.join(xdg_config_home,'fish','completions')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
#
|
82
|
+
# Prints the shell completion file to stdout.
|
83
|
+
#
|
84
|
+
# @param [String] path
|
85
|
+
# The path to the shell completion file.
|
86
|
+
#
|
87
|
+
# @param [Hash{Symbol => Object}] kwargs
|
88
|
+
# Additional keyword arguments.
|
89
|
+
#
|
90
|
+
# @option kwargs [:bash, :zsh, :fish] :type (:bash)
|
91
|
+
# The type of the completion file.
|
92
|
+
#
|
93
|
+
# @example Prints a Bash completion file:
|
94
|
+
# print_completion_file 'path/to/completions/foo'
|
95
|
+
#
|
96
|
+
# @example Prints a Zsh completion file:
|
97
|
+
# print_completion_file 'path/to/completions/foo', type: :zsh
|
98
|
+
#
|
99
|
+
# @example Prints a Fish completion file:
|
100
|
+
# print_completion_file 'path/to/completions/foo', type: :fish
|
101
|
+
#
|
102
|
+
# @api public
|
103
|
+
#
|
104
|
+
def print_completion_file(path,**kwargs)
|
105
|
+
write_completion_file(path,stdout,**kwargs)
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Installs the shell completion file into {#completions_dir}.
|
110
|
+
#
|
111
|
+
# @param [String] path
|
112
|
+
# The path to the shell completion file.
|
113
|
+
#
|
114
|
+
# @param [:bash, :zsh, :fish] type
|
115
|
+
# The type of the shell completion file.
|
116
|
+
#
|
117
|
+
# @example Install a Bash completion file:
|
118
|
+
# install_completion_file 'path/to/completions/foo'
|
119
|
+
#
|
120
|
+
# @example Install a Zsh completion file:
|
121
|
+
# install_completion_file 'path/to/completions/foo', type: :zsh
|
122
|
+
#
|
123
|
+
# @example Install a Fish completion file:
|
124
|
+
# install_completion_file 'path/to/completions/foo', type: :fish
|
125
|
+
#
|
126
|
+
# @api public
|
127
|
+
#
|
128
|
+
def install_completion_file(path, type: :bash)
|
129
|
+
completion_file = normalize_completion_file(path, type: type)
|
130
|
+
completion_path = File.join(@completions_dir,completion_file)
|
131
|
+
|
132
|
+
begin
|
133
|
+
::FileUtils.mkdir_p(@completions_dir)
|
134
|
+
rescue Errno::EACCES
|
135
|
+
print_error "cannot write to #{shell_type} completions directory: #{@completions_dir}"
|
136
|
+
exit(-1)
|
137
|
+
end
|
138
|
+
|
139
|
+
begin
|
140
|
+
File.open(completion_path,'w') do |output|
|
141
|
+
write_completion_file(path,output, type: type)
|
142
|
+
end
|
143
|
+
rescue Errno::EACCES
|
144
|
+
print_error "cannot write to #{shell_type} completion file: #{completion_path}"
|
145
|
+
exit(-1)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
#
|
150
|
+
# Uninstalls a shell completion file for the specified command.
|
151
|
+
#
|
152
|
+
# @param [String] command
|
153
|
+
# The command to uninstall the completions for.
|
154
|
+
#
|
155
|
+
# @example Removes the completion file for the command 'foo':
|
156
|
+
# uninstall_completion_file_for 'foo'
|
157
|
+
#
|
158
|
+
# @api public
|
159
|
+
#
|
160
|
+
def uninstall_completion_file_for(command)
|
161
|
+
completion_file = completion_file_for_command(command)
|
162
|
+
completion_path = File.join(@completions_dir,completion_file)
|
163
|
+
|
164
|
+
begin
|
165
|
+
::FileUtils.rm_f(completion_path)
|
166
|
+
rescue Errno::EACCES
|
167
|
+
print_error "cannot remove #{shell_type} completion file: #{completion_path}"
|
168
|
+
exit(-1)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
private
|
173
|
+
|
174
|
+
#
|
175
|
+
# Calculates the installed completion file for the given command.
|
176
|
+
#
|
177
|
+
# @param [String] command
|
178
|
+
# The command name.
|
179
|
+
#
|
180
|
+
# @return [String]
|
181
|
+
# The path to the completion file for the command.
|
182
|
+
#
|
183
|
+
# @api private
|
184
|
+
#
|
185
|
+
def completion_file_for_command(command)
|
186
|
+
case shell_type
|
187
|
+
when :bash then command
|
188
|
+
when :zsh then "_#{command}"
|
189
|
+
when :fish then "#{command}.fish"
|
190
|
+
when nil
|
191
|
+
if shell then print_error("cannot identify shell: #{shell}")
|
192
|
+
else print_error("cannot identify shell")
|
193
|
+
end
|
194
|
+
|
195
|
+
exit(-1)
|
196
|
+
else
|
197
|
+
print_error("completions not support for the #{shell_type} shell: #{shell}")
|
198
|
+
exit(-1)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
#
|
203
|
+
# Calculates the installation path for the given completion file.
|
204
|
+
#
|
205
|
+
# @param [String] path
|
206
|
+
# The path to the completion file that will be installed.
|
207
|
+
#
|
208
|
+
# @param [:bash, :zsh, :fish] type
|
209
|
+
# The type of the shell completion file.
|
210
|
+
#
|
211
|
+
# @return [String]
|
212
|
+
# The installation path for the completion file.
|
213
|
+
#
|
214
|
+
# @api private
|
215
|
+
#
|
216
|
+
def normalize_completion_file(path, type: :bash)
|
217
|
+
ext = File.extname(path)
|
218
|
+
file = File.basename(path,ext)
|
219
|
+
|
220
|
+
case [shell_type, type]
|
221
|
+
when [:bash, :bash] # no-op
|
222
|
+
when [:zsh, :zsh],
|
223
|
+
[:zsh, :bash]
|
224
|
+
unless file.start_with?('_')
|
225
|
+
file = "_#{file}"
|
226
|
+
end
|
227
|
+
when [:fish, :fish]
|
228
|
+
file = "#{file}.fish"
|
229
|
+
else
|
230
|
+
if shell_type
|
231
|
+
print_error("cannot install #{type} completion file into the #{shell_type} shell: #{path}")
|
232
|
+
elsif shell
|
233
|
+
print_error("cannot identify shell: #{shell}")
|
234
|
+
else
|
235
|
+
print_error("cannot identify shell")
|
236
|
+
end
|
237
|
+
|
238
|
+
exit(-1)
|
239
|
+
end
|
240
|
+
|
241
|
+
return file
|
242
|
+
end
|
243
|
+
|
244
|
+
#
|
245
|
+
# Writes the shell completion file to the output
|
246
|
+
#
|
247
|
+
# @param [String] path
|
248
|
+
# The path to the shell completion file.
|
249
|
+
#
|
250
|
+
# @param [IO] output
|
251
|
+
# The output stream to write to.
|
252
|
+
#
|
253
|
+
# @param [:bash, :zsh, :fish] type
|
254
|
+
# The type of the shell completion file.
|
255
|
+
#
|
256
|
+
# @api private
|
257
|
+
#
|
258
|
+
def write_completion_file(path,output, type: :bash)
|
259
|
+
if shell_type == :zsh && type == :bash
|
260
|
+
file_name = File.basename(path,File.extname(path))
|
261
|
+
command = file_name.sub(/\A_/,'')
|
262
|
+
|
263
|
+
# add the #compdef magic comments for zsh
|
264
|
+
output.puts "#compdef #{command}"
|
265
|
+
output.puts
|
266
|
+
end
|
267
|
+
|
268
|
+
File.open(path) do |file|
|
269
|
+
file.each_line do |line|
|
270
|
+
output.write(line)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'command_kit/env'
|
4
|
+
|
5
|
+
module CommandKit
|
6
|
+
module Env
|
7
|
+
#
|
8
|
+
# Methods related to the `PREFIX` environment variable.
|
9
|
+
#
|
10
|
+
# ## Environment Variables
|
11
|
+
#
|
12
|
+
# * `PREFIX` - The optional root prefix of the file-system.
|
13
|
+
#
|
14
|
+
# @since 0.5.0
|
15
|
+
#
|
16
|
+
module Prefix
|
17
|
+
include Env
|
18
|
+
|
19
|
+
# The root of the file-system.
|
20
|
+
#
|
21
|
+
# @return [String]
|
22
|
+
# The `PREFIX` environment variable, or `/` if no `PREFIX` environment
|
23
|
+
# variable is given.
|
24
|
+
attr_reader :root
|
25
|
+
|
26
|
+
#
|
27
|
+
# Initialize {#root} based on the `PREFIX` environment
|
28
|
+
#
|
29
|
+
# @param [Hash{Symbol => Object}] kwargs
|
30
|
+
# Additional keyword arguments.
|
31
|
+
#
|
32
|
+
# @api public
|
33
|
+
#
|
34
|
+
def initialize(**kwargs)
|
35
|
+
super(**kwargs)
|
36
|
+
|
37
|
+
@root = env.fetch('PREFIX','/')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'command_kit/env'
|
4
|
+
|
5
|
+
module CommandKit
|
6
|
+
module Env
|
7
|
+
#
|
8
|
+
# Methods related to the `SHELL` environment variable.
|
9
|
+
#
|
10
|
+
# ## Environment Variables
|
11
|
+
#
|
12
|
+
# * `SHELL` - The current shell.
|
13
|
+
#
|
14
|
+
# @since 0.5.0
|
15
|
+
#
|
16
|
+
module Shell
|
17
|
+
include Env
|
18
|
+
|
19
|
+
# The current shell.
|
20
|
+
#
|
21
|
+
# @return [String, nil]
|
22
|
+
attr_reader :shell
|
23
|
+
|
24
|
+
# The current shell type.
|
25
|
+
#
|
26
|
+
# @return [:bash, :zsh, :fish, :dash, :mksh, :ksh, :tcsh, :csh, :sh, nil]
|
27
|
+
attr_reader :shell_type
|
28
|
+
|
29
|
+
#
|
30
|
+
# Initialize {#shell} and {#shell_type} based on the `SHELL` environment
|
31
|
+
# variable.
|
32
|
+
#
|
33
|
+
# @param [Hash{Symbol => Object}] kwargs
|
34
|
+
# Additional keyword arguments.
|
35
|
+
#
|
36
|
+
# @api public
|
37
|
+
#
|
38
|
+
def initialize(**kwargs)
|
39
|
+
super(**kwargs)
|
40
|
+
|
41
|
+
@shell = env['SHELL']
|
42
|
+
@shell_type = if @shell
|
43
|
+
case File.basename(@shell)
|
44
|
+
when /bash/ then :bash
|
45
|
+
when /zsh/ then :zsh
|
46
|
+
when /fish/ then :fish
|
47
|
+
when /dash/ then :dash
|
48
|
+
when /mksh/ then :mksh
|
49
|
+
when /ksh/ then :ksh
|
50
|
+
when /tcsh/ then :tcsh
|
51
|
+
when /csh/ then :csh
|
52
|
+
when /sh/ then :sh
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/command_kit/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: command_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
@@ -73,11 +73,14 @@ files:
|
|
73
73
|
- lib/command_kit/commands/help.rb
|
74
74
|
- lib/command_kit/commands/parent_command.rb
|
75
75
|
- lib/command_kit/commands/subcommand.rb
|
76
|
+
- lib/command_kit/completion/install.rb
|
76
77
|
- lib/command_kit/description.rb
|
77
78
|
- lib/command_kit/edit.rb
|
78
79
|
- lib/command_kit/env.rb
|
79
80
|
- lib/command_kit/env/home.rb
|
80
81
|
- lib/command_kit/env/path.rb
|
82
|
+
- lib/command_kit/env/prefix.rb
|
83
|
+
- lib/command_kit/env/shell.rb
|
81
84
|
- lib/command_kit/examples.rb
|
82
85
|
- lib/command_kit/exception_handler.rb
|
83
86
|
- lib/command_kit/file_utils.rb
|
@@ -117,69 +120,6 @@ files:
|
|
117
120
|
- lib/command_kit/usage.rb
|
118
121
|
- lib/command_kit/version.rb
|
119
122
|
- lib/command_kit/xdg.rb
|
120
|
-
- spec/arguments/argument_spec.rb
|
121
|
-
- spec/arguments/argument_value_spec.rb
|
122
|
-
- spec/arguments_spec.rb
|
123
|
-
- spec/bug_report_spec.rb
|
124
|
-
- spec/colors_spec.rb
|
125
|
-
- spec/command_kit_spec.rb
|
126
|
-
- spec/command_name_spec.rb
|
127
|
-
- spec/command_spec.rb
|
128
|
-
- spec/commands/auto_load/subcommand_spec.rb
|
129
|
-
- spec/commands/auto_load_spec.rb
|
130
|
-
- spec/commands/auto_require_spec.rb
|
131
|
-
- spec/commands/fixtures/test_auto_load/cli/commands/test1.rb
|
132
|
-
- spec/commands/fixtures/test_auto_load/cli/commands/test2.rb
|
133
|
-
- spec/commands/fixtures/test_auto_require/lib/test_auto_require/cli/commands/test1.rb
|
134
|
-
- spec/commands/help_spec.rb
|
135
|
-
- spec/commands/parent_command_spec.rb
|
136
|
-
- spec/commands/subcommand_spec.rb
|
137
|
-
- spec/commands_spec.rb
|
138
|
-
- spec/description_spec.rb
|
139
|
-
- spec/edit_spec.rb
|
140
|
-
- spec/env/home_spec.rb
|
141
|
-
- spec/env/path_spec.rb
|
142
|
-
- spec/env_spec.rb
|
143
|
-
- spec/examples_spec.rb
|
144
|
-
- spec/exception_handler_spec.rb
|
145
|
-
- spec/file_utils_spec.rb
|
146
|
-
- spec/fixtures/template.erb
|
147
|
-
- spec/help/man_spec.rb
|
148
|
-
- spec/help_spec.rb
|
149
|
-
- spec/inflector_spec.rb
|
150
|
-
- spec/interactive_spec.rb
|
151
|
-
- spec/main_spec.rb
|
152
|
-
- spec/man_spec.rb
|
153
|
-
- spec/open_app_spec.rb
|
154
|
-
- spec/options/option_spec.rb
|
155
|
-
- spec/options/option_value_spec.rb
|
156
|
-
- spec/options/parser_spec.rb
|
157
|
-
- spec/options/quiet_spec.rb
|
158
|
-
- spec/options/verbose_spec.rb
|
159
|
-
- spec/options/version_spec.rb
|
160
|
-
- spec/options_spec.rb
|
161
|
-
- spec/os/linux_spec.rb
|
162
|
-
- spec/os_spec.rb
|
163
|
-
- spec/package_manager_spec.rb
|
164
|
-
- spec/pager_spec.rb
|
165
|
-
- spec/printing/fields_spec.rb
|
166
|
-
- spec/printing/indent_spec.rb
|
167
|
-
- spec/printing/lists_spec.rb
|
168
|
-
- spec/printing/tables/border_style.rb
|
169
|
-
- spec/printing/tables/cell_builer_spec.rb
|
170
|
-
- spec/printing/tables/row_builder_spec.rb
|
171
|
-
- spec/printing/tables/style_spec.rb
|
172
|
-
- spec/printing/tables/table_builder_spec.rb
|
173
|
-
- spec/printing/tables/table_formatter_spec.rb
|
174
|
-
- spec/printing/tables_spec.rb
|
175
|
-
- spec/printing_spec.rb
|
176
|
-
- spec/program_name_spec.rb
|
177
|
-
- spec/spec_helper.rb
|
178
|
-
- spec/stdio_spec.rb
|
179
|
-
- spec/sudo_spec.rb
|
180
|
-
- spec/terminal_spec.rb
|
181
|
-
- spec/usage_spec.rb
|
182
|
-
- spec/xdg_spec.rb
|
183
123
|
homepage: https://github.com/postmodern/command_kit.rb#readme
|
184
124
|
licenses:
|
185
125
|
- MIT
|
@@ -1,133 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'command_kit/arguments/argument'
|
3
|
-
|
4
|
-
describe CommandKit::Arguments::Argument do
|
5
|
-
let(:name) { :foo }
|
6
|
-
let(:usage) { 'FOO' }
|
7
|
-
let(:required) { true }
|
8
|
-
let(:repeats) { false }
|
9
|
-
let(:desc) { 'Foo argument' }
|
10
|
-
|
11
|
-
subject do
|
12
|
-
described_class.new name, usage: usage,
|
13
|
-
required: required,
|
14
|
-
repeats: repeats,
|
15
|
-
desc: desc
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#initialize" do
|
19
|
-
context "when the usage: keyword is given" do
|
20
|
-
subject { described_class.new(name, usage: usage, desc: desc) }
|
21
|
-
|
22
|
-
it "must include usage: in #usage" do
|
23
|
-
expect(subject.usage).to include(usage)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when the usage: keyword is not given" do
|
28
|
-
subject { described_class.new(name, desc: desc) }
|
29
|
-
|
30
|
-
it "should use uppercased argument name in #usage" do
|
31
|
-
expect(subject.usage).to include(name.to_s.upcase)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when the required: keyword is given" do
|
36
|
-
subject { described_class.new(name, required: required, desc: desc) }
|
37
|
-
|
38
|
-
it "must set #required" do
|
39
|
-
expect(subject.required).to eq(required)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "when the required: keyword is not given" do
|
44
|
-
subject { described_class.new(name, desc: desc) }
|
45
|
-
|
46
|
-
it "default #required to String" do
|
47
|
-
expect(subject.required).to eq(true)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when the repeats: keyword is given" do
|
52
|
-
subject { described_class.new(name, repeats: repeats, desc: desc) }
|
53
|
-
|
54
|
-
it "must set #repeats" do
|
55
|
-
expect(subject.repeats?).to eq(repeats)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when the repeats: keyword is not given" do
|
60
|
-
subject { described_class.new(name, desc: desc) }
|
61
|
-
|
62
|
-
it "default #repeats to String" do
|
63
|
-
expect(subject.repeats?).to eq(false)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when the desc: keyword is given" do
|
68
|
-
subject { described_class.new(name, desc: desc) }
|
69
|
-
|
70
|
-
it "must set #desc" do
|
71
|
-
expect(subject.desc).to eq(desc)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "when the desc: keyword is not given" do
|
76
|
-
it do
|
77
|
-
expect {
|
78
|
-
described_class.new(name)
|
79
|
-
}.to raise_error(ArgumentError)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "#repeats?" do
|
85
|
-
context "when initialized with repeats: true" do
|
86
|
-
let(:repeats) { true }
|
87
|
-
|
88
|
-
it { expect(subject.repeats?).to be(true) }
|
89
|
-
end
|
90
|
-
|
91
|
-
context "when initialized with repeats: false" do
|
92
|
-
let(:repeats) { false }
|
93
|
-
|
94
|
-
it { expect(subject.repeats?).to be(false) }
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "#usage" do
|
99
|
-
let(:usage) { 'FOO' }
|
100
|
-
|
101
|
-
context "initialized with required: true" do
|
102
|
-
let(:required) { true }
|
103
|
-
|
104
|
-
it "must return the usage unchanged" do
|
105
|
-
expect(subject.usage).to eq(usage)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context "initialized with required: false" do
|
110
|
-
let(:required) { false }
|
111
|
-
|
112
|
-
it "must wrap the usage in [ ] brackets" do
|
113
|
-
expect(subject.usage).to eq("[#{usage}]")
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context "initialized with repeats: true" do
|
118
|
-
let(:repeats) { true }
|
119
|
-
|
120
|
-
it "must append the ... ellipses" do
|
121
|
-
expect(subject.usage).to eq("#{usage} ...")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "initialized with repeats: false" do
|
126
|
-
let(:repeats) { false }
|
127
|
-
|
128
|
-
it "must return the usage name unchanged" do
|
129
|
-
expect(subject.usage).to eq(usage)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|