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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +6 -0
  3. data/README.md +3 -0
  4. data/command_kit.gemspec +7 -2
  5. data/lib/command_kit/completion/install.rb +276 -0
  6. data/lib/command_kit/env/prefix.rb +41 -0
  7. data/lib/command_kit/env/shell.rb +58 -0
  8. data/lib/command_kit/version.rb +1 -1
  9. metadata +4 -64
  10. data/spec/arguments/argument_spec.rb +0 -133
  11. data/spec/arguments/argument_value_spec.rb +0 -66
  12. data/spec/arguments_spec.rb +0 -279
  13. data/spec/bug_report_spec.rb +0 -266
  14. data/spec/colors_spec.rb +0 -771
  15. data/spec/command_kit_spec.rb +0 -8
  16. data/spec/command_name_spec.rb +0 -130
  17. data/spec/command_spec.rb +0 -123
  18. data/spec/commands/auto_load/subcommand_spec.rb +0 -82
  19. data/spec/commands/auto_load_spec.rb +0 -159
  20. data/spec/commands/auto_require_spec.rb +0 -142
  21. data/spec/commands/fixtures/test_auto_load/cli/commands/test1.rb +0 -10
  22. data/spec/commands/fixtures/test_auto_load/cli/commands/test2.rb +0 -10
  23. data/spec/commands/fixtures/test_auto_require/lib/test_auto_require/cli/commands/test1.rb +0 -10
  24. data/spec/commands/help_spec.rb +0 -66
  25. data/spec/commands/parent_command_spec.rb +0 -40
  26. data/spec/commands/subcommand_spec.rb +0 -99
  27. data/spec/commands_spec.rb +0 -865
  28. data/spec/description_spec.rb +0 -179
  29. data/spec/edit_spec.rb +0 -72
  30. data/spec/env/home_spec.rb +0 -46
  31. data/spec/env/path_spec.rb +0 -84
  32. data/spec/env_spec.rb +0 -123
  33. data/spec/examples_spec.rb +0 -211
  34. data/spec/exception_handler_spec.rb +0 -103
  35. data/spec/file_utils_spec.rb +0 -59
  36. data/spec/fixtures/template.erb +0 -5
  37. data/spec/help/man_spec.rb +0 -345
  38. data/spec/help_spec.rb +0 -94
  39. data/spec/inflector_spec.rb +0 -166
  40. data/spec/interactive_spec.rb +0 -415
  41. data/spec/main_spec.rb +0 -179
  42. data/spec/man_spec.rb +0 -46
  43. data/spec/open_app_spec.rb +0 -85
  44. data/spec/options/option_spec.rb +0 -343
  45. data/spec/options/option_value_spec.rb +0 -171
  46. data/spec/options/parser_spec.rb +0 -274
  47. data/spec/options/quiet_spec.rb +0 -51
  48. data/spec/options/verbose_spec.rb +0 -51
  49. data/spec/options/version_spec.rb +0 -146
  50. data/spec/options_spec.rb +0 -465
  51. data/spec/os/linux_spec.rb +0 -164
  52. data/spec/os_spec.rb +0 -233
  53. data/spec/package_manager_spec.rb +0 -806
  54. data/spec/pager_spec.rb +0 -217
  55. data/spec/printing/fields_spec.rb +0 -167
  56. data/spec/printing/indent_spec.rb +0 -132
  57. data/spec/printing/lists_spec.rb +0 -99
  58. data/spec/printing/tables/border_style.rb +0 -43
  59. data/spec/printing/tables/cell_builer_spec.rb +0 -135
  60. data/spec/printing/tables/row_builder_spec.rb +0 -165
  61. data/spec/printing/tables/style_spec.rb +0 -377
  62. data/spec/printing/tables/table_builder_spec.rb +0 -252
  63. data/spec/printing/tables/table_formatter_spec.rb +0 -1190
  64. data/spec/printing/tables_spec.rb +0 -1069
  65. data/spec/printing_spec.rb +0 -106
  66. data/spec/program_name_spec.rb +0 -70
  67. data/spec/spec_helper.rb +0 -3
  68. data/spec/stdio_spec.rb +0 -264
  69. data/spec/sudo_spec.rb +0 -51
  70. data/spec/terminal_spec.rb +0 -231
  71. data/spec/usage_spec.rb +0 -237
  72. data/spec/xdg_spec.rb +0 -191
@@ -1,106 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/printing'
3
- require 'command_kit/command_name'
4
-
5
- require 'stringio'
6
-
7
- describe CommandKit::Printing do
8
- module TestPrinting
9
- class TestCmd
10
-
11
- include CommandKit::Printing
12
-
13
- end
14
- end
15
-
16
- let(:command_class) { TestPrinting::TestCmd }
17
- subject { command_class.new }
18
-
19
- describe "EOL" do
20
- subject { described_class::EOL }
21
-
22
- it "must equal $/" do
23
- expect(subject).to eq($/)
24
- end
25
- end
26
-
27
- describe ".included" do
28
- subject { command_class }
29
-
30
- it { expect(command_class).to include(CommandKit::Stdio) }
31
- end
32
-
33
- let(:nl) { $/ }
34
-
35
- describe "#print_error" do
36
- let(:message) { "oh no!" }
37
-
38
- it "must print the error message to stderr" do
39
- expect {
40
- subject.print_error(message)
41
- }.to output("#{message}#{nl}").to_stderr
42
- end
43
-
44
- context "and when CommandKit::CommandName is included" do
45
- module TestPrinting
46
- class TestCmdWithCommandName
47
-
48
- include CommandKit::CommandName
49
- include CommandKit::Printing
50
-
51
- command_name 'foo'
52
-
53
- end
54
- end
55
-
56
- let(:command_class) { TestPrinting::TestCmdWithCommandName }
57
-
58
- it "must print the command_name and the error message" do
59
- expect {
60
- subject.print_error(message)
61
- }.to output("#{subject.command_name}: #{message}#{nl}").to_stderr
62
- end
63
- end
64
- end
65
-
66
- describe "#print_exception" do
67
- let(:message) { "error!" }
68
- let(:backtrace) do
69
- [
70
- "/path/to/test1.rb:1 in `test1'",
71
- "/path/to/test2.rb:2 in `test2'",
72
- "/path/to/test3.rb:3 in `test3'",
73
- "/path/to/test4.rb:4 in `test4'"
74
- ]
75
- end
76
- let(:exception) do
77
- error = RuntimeError.new(message)
78
- error.set_backtrace(backtrace)
79
- error
80
- end
81
-
82
- subject { command_class.new(stderr: StringIO.new) }
83
-
84
- context "when stderr is a TTY" do
85
- before { expect(subject.stderr).to receive(:tty?).and_return(true) }
86
-
87
- it "must print a highlighted exception" do
88
- subject.print_exception(exception)
89
-
90
- expect(subject.stderr.string).to eq(
91
- exception.full_message(highlight: true)
92
- )
93
- end
94
- end
95
-
96
- context "when stderr is not a TTY" do
97
- it "must not highlight the exception" do
98
- subject.print_exception(exception)
99
-
100
- expect(subject.stderr.string).to eq(
101
- exception.full_message(highlight: false)
102
- )
103
- end
104
- end
105
- end
106
- end
@@ -1,70 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/program_name'
3
-
4
- describe CommandKit::ProgramName do
5
- module TestProgramName
6
- class TestCmd
7
- include CommandKit::ProgramName
8
- end
9
- end
10
-
11
- let(:command_class) { TestProgramName::TestCmd }
12
- let(:program_name) { 'foo' }
13
-
14
- before do
15
- @original_program_name = $PROGRAM_NAME
16
- $PROGRAM_NAME = program_name
17
- end
18
-
19
- describe ".program_name" do
20
- subject { command_class }
21
-
22
- it "must return $PROGRAM_NAME" do
23
- expect(subject.program_name).to eq(program_name)
24
- end
25
-
26
- context "when $PROGRAM_NAME is '-e'" do
27
- let(:program_name) { '-e' }
28
-
29
- it "must return nil" do
30
- expect(subject.program_name).to be(nil)
31
- end
32
- end
33
-
34
- context "when $PROGRAM_NAME is 'irb'" do
35
- let(:program_name) { 'irb' }
36
-
37
- it "must return nil" do
38
- expect(subject.program_name).to be(nil)
39
- end
40
- end
41
-
42
- context "when $PROGRAM_NAME is 'rspec'" do
43
- let(:program_name) { 'rspec' }
44
-
45
- it "must return nil" do
46
- expect(subject.program_name).to be(nil)
47
- end
48
- end
49
- end
50
-
51
- describe "#program_name" do
52
- subject { command_class.new }
53
-
54
- it "should be the same as .program_name" do
55
- expect(subject.program_name).to eq(command_class.program_name)
56
- end
57
- end
58
-
59
- describe "#command_name" do
60
- subject { command_class.new }
61
-
62
- it "should be the same as #program_name" do
63
- expect(subject.command_name).to eq(subject.program_name)
64
- end
65
- end
66
-
67
- after do
68
- $PROGRAM_NAME = @original_program_name
69
- end
70
- end
data/spec/spec_helper.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'rspec'
2
- require 'simplecov'
3
- SimpleCov.start
data/spec/stdio_spec.rb DELETED
@@ -1,264 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/stdio'
3
-
4
- describe CommandKit::Stdio do
5
- module TestStdio
6
- class TestCommand
7
- include CommandKit::Stdio
8
- end
9
- end
10
-
11
- let(:command_class) { TestStdio::TestCommand }
12
-
13
- describe "#initialize" do
14
- module TestStdio
15
- class TestCommandWithInitialize
16
- include CommandKit::Stdio
17
-
18
- attr_reader :var
19
-
20
- def initialize(**kwargs)
21
- super(**kwargs)
22
-
23
- @var = 'foo'
24
- end
25
- end
26
-
27
- class TestCommandWithInitializeAndKeywordArgs
28
- include CommandKit::Stdio
29
-
30
- attr_reader :var
31
-
32
- def initialize(var: "foo", **kwargs)
33
- super(**kwargs)
34
-
35
- @var = var
36
- end
37
- end
38
- end
39
-
40
- context "when given no arguments" do
41
- subject { command_class.new() }
42
-
43
- it "must initialize #stdin to $stdin" do
44
- expect(subject.stdin).to be($stdin)
45
- end
46
-
47
- it "must initialize #stdout to $stdout" do
48
- expect(subject.stdout).to be($stdout)
49
- end
50
-
51
- it "must initialize #stderr to $stderr" do
52
- expect(subject.stderr).to be($stderr)
53
- end
54
-
55
- context "and the including class defines it's own #initialize method" do
56
- let(:command_class) { TestStdio::TestCommandWithInitialize }
57
-
58
- it "must initialize #stdin to $stdin" do
59
- expect(subject.stdin).to be($stdin)
60
- end
61
-
62
- it "must initialize #stdout to $stdout" do
63
- expect(subject.stdout).to be($stdout)
64
- end
65
-
66
- it "must initialize #stderr to $stderr" do
67
- expect(subject.stderr).to be($stderr)
68
- end
69
-
70
- it "must also call the class'es #initialize method" do
71
- expect(subject.var).to eq('foo')
72
- end
73
-
74
- context "and it accepts keyword arguments" do
75
- let(:command_class) { TestStdio::TestCommandWithInitializeAndKeywordArgs }
76
- let(:var) { 'custom value' }
77
-
78
- subject { command_class.new(var: var) }
79
-
80
- it "must initialize #stdin to $stdin" do
81
- expect(subject.stdin).to be($stdin)
82
- end
83
-
84
- it "must initialize #stdout to $stdout" do
85
- expect(subject.stdout).to be($stdout)
86
- end
87
-
88
- it "must initialize #stderr to $stderr" do
89
- expect(subject.stderr).to be($stderr)
90
- end
91
-
92
- it "must also call the class'es #initialize method with any additional keyword arguments" do
93
- expect(subject.var).to eq(var)
94
- end
95
- end
96
- end
97
- end
98
-
99
- context "when given a custom env: value" do
100
- let(:custom_stdin) { StringIO.new }
101
- let(:custom_stdout) { StringIO.new }
102
- let(:custom_stderr) { StringIO.new }
103
-
104
- subject do
105
- command_class.new(
106
- stdin: custom_stdin,
107
- stdout: custom_stdout,
108
- stderr: custom_stderr
109
- )
110
- end
111
-
112
- it "must initialize #stdin to the stdin: value" do
113
- expect(subject.stdin).to eq(custom_stdin)
114
- end
115
-
116
- it "must initialize #stdout to the stdout: value" do
117
- expect(subject.stdout).to eq(custom_stdout)
118
- end
119
-
120
- it "must initialize #stderr to the stderr: value" do
121
- expect(subject.stderr).to eq(custom_stderr)
122
- end
123
-
124
- context "and the including class defines it's own #initialize method" do
125
- let(:command_class) { TestStdio::TestCommandWithInitialize }
126
-
127
- it "must initialize #stdin to the stdin: value" do
128
- expect(subject.stdin).to eq(custom_stdin)
129
- end
130
-
131
- it "must initialize #stdout to the stdout: value" do
132
- expect(subject.stdout).to eq(custom_stdout)
133
- end
134
-
135
- it "must initialize #stderr to the stderr: value" do
136
- expect(subject.stderr).to eq(custom_stderr)
137
- end
138
-
139
- it "must also call the class'es #initialize method" do
140
- expect(subject.var).to eq('foo')
141
- end
142
-
143
- context "and it accepts keyword arguments" do
144
- let(:command_class) { TestStdio::TestCommandWithInitializeAndKeywordArgs }
145
- let(:var) { 'custom value' }
146
-
147
- subject do
148
- command_class.new(
149
- stdin: custom_stdin,
150
- stdout: custom_stdout,
151
- stderr: custom_stderr,
152
- var: var
153
- )
154
- end
155
-
156
- it "must initialize #stdin to the stdin: value" do
157
- expect(subject.stdin).to eq(custom_stdin)
158
- end
159
-
160
- it "must initialize #stdout to the stdout: value" do
161
- expect(subject.stdout).to eq(custom_stdout)
162
- end
163
-
164
- it "must initialize #stderr to the stderr: value" do
165
- expect(subject.stderr).to eq(custom_stderr)
166
- end
167
-
168
- it "must also call the class'es #initialize method with any additional keyword arguments" do
169
- expect(subject.var).to eq(var)
170
- end
171
- end
172
- end
173
- end
174
- end
175
-
176
- describe "#stdin" do
177
- let(:command_class) { TestStdio::TestCommand }
178
- let(:stdin) { StringIO.new }
179
-
180
- subject { command_class.new(stdin: stdin) }
181
-
182
- it "must return the initialized stdin: value" do
183
- expect(subject.stdin).to eq(stdin)
184
- end
185
- end
186
-
187
- describe "#stdout" do
188
- let(:command_class) { TestStdio::TestCommand }
189
- let(:stdout) { StringIO.new }
190
-
191
- subject { command_class.new(stdout: stdout) }
192
-
193
- it "must return the initialized stdout: value" do
194
- expect(subject.stdout).to eq(stdout)
195
- end
196
- end
197
-
198
- describe "#stderr" do
199
- let(:command_class) { TestStdio::TestCommand }
200
- let(:stderr) { StringIO.new }
201
-
202
- subject { command_class.new(stderr: stderr) }
203
-
204
- it "must return the initialized stderr: value" do
205
- expect(subject.stderr).to eq(stderr)
206
- end
207
- end
208
-
209
- [:gets, :readline, :readlines].each do |method|
210
- describe "##{method}" do
211
- let(:stdin) { StringIO.new }
212
- let(:args) { [double(:arg1), double(:arg2)] }
213
- let(:ret) { double(:return_value) }
214
-
215
- subject { command_class.new(stdin: stdin) }
216
-
217
- it "must pass all arguments ot stdin.#{method}" do
218
- expect(stdin).to receive(method).with(*args).and_return(ret)
219
-
220
- expect(subject.send(method,*args)).to be(ret)
221
- end
222
- end
223
- end
224
-
225
- [:putc, :puts, :print, :printf].each do |method|
226
- describe "##{method}" do
227
- let(:stdout) { StringIO.new }
228
- let(:args) { [double(:arg1), double(:arg2)] }
229
- let(:ret) { double(:return_value) }
230
-
231
- subject { command_class.new(stdout: stdout) }
232
-
233
- it "must pass all arguments ot stdout.#{method}" do
234
- expect(stdout).to receive(method).with(*args).and_return(ret)
235
-
236
- expect(subject.send(method,*args)).to be(ret)
237
- end
238
- end
239
- end
240
-
241
- describe "#abort" do
242
- let(:stderr) { StringIO.new }
243
- subject { command_class.new(stderr: stderr) }
244
-
245
- context "when given an abort message" do
246
- let(:message) { 'fail' }
247
-
248
- it "must print the message to stderr and exit with 1" do
249
- expect(subject.stderr).to receive(:puts).with(message)
250
- expect(subject).to receive(:exit).with(1)
251
-
252
- subject.abort(message)
253
- end
254
- end
255
-
256
- context "when called without any arguments" do
257
- it "must exit with 1" do
258
- expect(subject).to receive(:exit).with(1)
259
-
260
- subject.abort
261
- end
262
- end
263
- end
264
- end
data/spec/sudo_spec.rb DELETED
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/sudo'
3
-
4
- describe CommandKit::Sudo do
5
- module TestSudo
6
- class TestCommand
7
- include CommandKit::Sudo
8
- end
9
- end
10
-
11
- let(:command_class) { TestSudo::TestCommand }
12
- subject { command_class.new }
13
-
14
- describe "#sudo" do
15
- let(:command) { "ls" }
16
- let(:arguments) { ["-la", "~root"] }
17
- let(:status) { double(:status) }
18
-
19
- context "on UNIX" do
20
- context "when the UID is 0" do
21
- before { allow(Process).to receive(:uid).and_return(0) }
22
-
23
- it "must execute the command without sudo" do
24
- expect(subject).to receive(:system).with(command,*arguments).and_return(status)
25
-
26
- expect(subject.sudo(command,*arguments)).to be(status)
27
- end
28
- end
29
-
30
- context "when the UID is not 0" do
31
- before { allow(Process).to receive(:uid).and_return(1000) }
32
-
33
- it "must execute the command with 'sudo ...'" do
34
- expect(subject).to receive(:system).with('sudo',command,*arguments).and_return(status)
35
-
36
- expect(subject.sudo(command,*arguments)).to be(status)
37
- end
38
- end
39
- end
40
-
41
- context "on Windows" do
42
- subject { command_class.new(os: :windows) }
43
-
44
- it "must execute the command with 'runas /user:administrator ...'" do
45
- expect(subject).to receive(:system).with('runas','/user:administrator',command,*arguments).and_return(status)
46
-
47
- expect(subject.sudo(command,*arguments)).to be(status)
48
- end
49
- end
50
- end
51
- end