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,179 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/description'
3
-
4
- describe CommandKit::Description do
5
- module TestDescription
6
- class ImplicitCmd
7
- include CommandKit::Description
8
- end
9
- end
10
-
11
- let(:command_class) { TestDescription::ImplicitCmd }
12
-
13
- describe ".description" do
14
- subject { TestDescription::ImplicitCmd }
15
-
16
- context "when no description have been set" do
17
- it "should default to nil" do
18
- expect(subject.description).to be_nil
19
- end
20
- end
21
-
22
- context "when a description is explicitly set" do
23
- module TestDescription
24
- class ExplicitCmd
25
- include CommandKit::Description
26
- description "Example command"
27
- end
28
- end
29
-
30
- subject { TestDescription::ExplicitCmd }
31
-
32
- it "must return the explicitly set description" do
33
- expect(subject.description).to eq("Example command")
34
- end
35
- end
36
-
37
- context "when the command class inherites from another class" do
38
- context "but no description is set" do
39
- module TestDescription
40
- class BaseCmd
41
- include CommandKit::Description
42
- end
43
-
44
- class InheritedCmd < BaseCmd
45
- end
46
- end
47
-
48
- subject { TestDescription::InheritedCmd }
49
-
50
- it "must search each class then return nil "do
51
- expect(subject.description).to be_nil
52
- end
53
- end
54
-
55
- module TestDescription
56
- class ExplicitBaseCmd
57
- include CommandKit::Description
58
- description "Example base command"
59
- end
60
- end
61
-
62
- context "when the superclass defines an explicit description" do
63
- module TestDescription
64
- class ImplicitInheritedCmd < ExplicitBaseCmd
65
- end
66
- end
67
-
68
- let(:super_subject) { TestDescription::ExplicitBaseCmd }
69
- subject { TestDescription::ImplicitInheritedCmd }
70
-
71
- it "must inherit the superclass'es description" do
72
- expect(subject.description).to eq(super_subject.description)
73
- end
74
-
75
- it "must not change the superclass'es description" do
76
- expect(super_subject.description).to eq("Example base command")
77
- end
78
- end
79
-
80
- context "when the subclass defines an explicit description" do
81
- module TestDescription
82
- class ImplicitBaseCmd
83
- include CommandKit::Description
84
- end
85
-
86
- class ExplicitInheritedCmd < ImplicitBaseCmd
87
- description "Example inherited command"
88
- end
89
- end
90
-
91
- let(:super_subject) { TestDescription::ImplicitBaseCmd }
92
- subject { TestDescription::ExplicitInheritedCmd }
93
-
94
- it "must return the subclass'es description" do
95
- expect(subject.description).to eq("Example inherited command")
96
- end
97
-
98
- it "must not change the superclass'es description" do
99
- expect(super_subject.description).to be_nil
100
- end
101
- end
102
-
103
- context "when both the subclass overrides the superclass's descriptions" do
104
- module TestDescription
105
- class ExplicitOverridingInheritedCmd < ExplicitBaseCmd
106
- description "Example overrided description"
107
- end
108
- end
109
-
110
- let(:super_subject) { TestDescription::ExplicitBaseCmd }
111
- subject { TestDescription::ExplicitOverridingInheritedCmd }
112
-
113
- it "must return the subclass'es description" do
114
- expect(subject.description).to eq("Example overrided description")
115
- end
116
-
117
- it "must not change the superclass'es description" do
118
- expect(super_subject.description).to eq("Example base command")
119
- end
120
- end
121
- end
122
- end
123
-
124
- subject { command_class.new }
125
-
126
- describe "#description" do
127
- it "must be the same as .description" do
128
- expect(subject.description).to eq(command_class.description)
129
- end
130
- end
131
-
132
- describe "#help_description" do
133
- context "when #description returns nil" do
134
- module TestDescription
135
- class NoDescription
136
- include CommandKit::Description
137
- end
138
- end
139
-
140
- let(:command_class) { TestDescription::NoDescription }
141
- subject { command_class.new }
142
-
143
- it "must print out the description" do
144
- expect { subject.help_description }.to_not output.to_stdout
145
- end
146
- end
147
-
148
- context "when #description returns a String" do
149
- module TestDescription
150
- class DefinesDescription
151
- include CommandKit::Description
152
-
153
- description "Example command"
154
- end
155
- end
156
-
157
- let(:command_class) { TestDescription::DefinesDescription }
158
- subject { command_class.new }
159
-
160
- it "must print out the description" do
161
- expect { subject.help_description }.to output(
162
- [
163
- '',
164
- subject.description,
165
- ''
166
- ].join($/)
167
- ).to_stdout
168
- end
169
- end
170
- end
171
-
172
- describe "#help" do
173
- it "must call #help_description" do
174
- expect(subject).to receive(:help_description)
175
-
176
- subject.help
177
- end
178
- end
179
- end
data/spec/edit_spec.rb DELETED
@@ -1,72 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/edit'
3
-
4
- describe CommandKit::Edit do
5
- module TestEdit
6
- class TestCommand
7
- include CommandKit::Edit
8
- end
9
- end
10
-
11
- let(:command_class) { TestEdit::TestCommand }
12
-
13
- it "must also include CommandKit::Env" do
14
- expect(command_class).to include(CommandKit::Env)
15
- end
16
-
17
- describe "#editor" do
18
- subject { command_class.new(env: env) }
19
-
20
- context "when env['EDITOR'] is set" do
21
- let(:editor) { 'vim' }
22
- let(:env) do
23
- {'EDITOR' => editor}
24
- end
25
-
26
- it "must return env['EDITOR']" do
27
- expect(subject.editor).to eq(env['EDITOR'])
28
- end
29
- end
30
-
31
- context "when env['EDITOR'] is not set" do
32
- let(:env) do
33
- {}
34
- end
35
-
36
- it "must return 'nano'" do
37
- expect(subject.editor).to eq('nano')
38
- end
39
- end
40
- end
41
-
42
- describe "#edit" do
43
- subject { command_class.new(env: env) }
44
-
45
- let(:arguments) { ['file.txt'] }
46
-
47
- context "when env['EDITOR'] is set" do
48
- let(:editor) { 'vim' }
49
- let(:env) do
50
- {'EDITOR' => editor}
51
- end
52
-
53
- it "must invoke system with #editor and the additional arguments" do
54
- expect(subject).to receive(:system).with(subject.editor,*arguments)
55
-
56
- subject.edit(*arguments)
57
- end
58
- end
59
-
60
- context "when env['EDITOR'] is not set" do
61
- let(:env) do
62
- {}
63
- end
64
-
65
- it "must invoke system with 'nano' and the additional arguments" do
66
- expect(subject).to receive(:system).with('nano',*arguments)
67
-
68
- subject.edit(*arguments)
69
- end
70
- end
71
- end
72
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/env/home'
3
-
4
- describe CommandKit::Env::Home do
5
- module TestEnvHome
6
- class TestCommand
7
- include CommandKit::Env::Home
8
- end
9
- end
10
-
11
- let(:command_class) { TestEnvHome::TestCommand }
12
-
13
- describe ".included" do
14
- it "must include CommandKit::Env" do
15
- expect(command_class).to be_include(CommandKit::Env)
16
- end
17
- end
18
-
19
- describe ".home_dir" do
20
- subject { command_class }
21
-
22
- it "must return Gem.user_home" do
23
- expect(subject.home_dir).to eq(Gem.user_home)
24
- end
25
- end
26
-
27
- describe "#home_dir" do
28
- context "when env['HOME'] is set" do
29
- let(:home_dir) { '/path/to/home_dir' }
30
-
31
- subject { command_class.new(env: {'HOME' => home_dir}) }
32
-
33
- it "must return the env['HOME'] value" do
34
- expect(subject.home_dir).to eq(home_dir)
35
- end
36
- end
37
-
38
- context "when env['HOME'] is not set" do
39
- subject { command_class.new(env: {}) }
40
-
41
- it "must return .home_dir" do
42
- expect(subject.home_dir).to eq(subject.class.home_dir)
43
- end
44
- end
45
- end
46
- end
@@ -1,84 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/env/path'
3
-
4
- describe CommandKit::Env::Path do
5
- module TestEnvPath
6
- class TestCommand
7
-
8
- include CommandKit::Env::Path
9
-
10
- end
11
- end
12
-
13
- let(:command_class) { TestEnvPath::TestCommand }
14
- subject { command_class.new }
15
-
16
- describe ".included" do
17
- it "must include CommandKit::Env" do
18
- expect(command_class).to be_include(CommandKit::Env)
19
- end
20
- end
21
-
22
- describe "#initialize" do
23
- it "must split ENV['PATH'] into an Array of directories" do
24
- expect(subject.path_dirs).to eq(ENV['PATH'].split(File::PATH_SEPARATOR))
25
- end
26
-
27
- context "when given a custom 'PATH variable" do
28
- let(:path_dirs) { %w[/bin /usr/bin] }
29
- let(:path) { path_dirs.join(File::PATH_SEPARATOR) }
30
-
31
- subject { command_class.new(env: {'PATH' => path}) }
32
-
33
- it "must split env['PATH'] into an Array of directories" do
34
- expect(subject.path_dirs).to eq(path_dirs)
35
- end
36
- end
37
-
38
- context "when given an empty 'PATH' env variable" do
39
- subject { command_class.new(env: {'PATH' => ''}) }
40
-
41
- it "must set #path_dirs to []" do
42
- expect(subject.path_dirs).to eq([])
43
- end
44
- end
45
- end
46
-
47
- describe "#find_command" do
48
- context "when given a valid command name" do
49
- it "must search #path_dirs for the command" do
50
- command = subject.find_command('ruby')
51
-
52
- expect(subject.path_dirs).to include(File.dirname(command))
53
- end
54
-
55
- it "must return the path to the command" do
56
- command = subject.find_command('ruby')
57
-
58
- expect(command).to_not be(nil)
59
- expect(File.file?(command)).to be(true)
60
- expect(File.executable?(command)).to be(true)
61
- end
62
- end
63
-
64
- context "when given an unknown command name" do
65
- it "must return nil" do
66
- expect(subject.find_command('does_not_exist')).to be(nil)
67
- end
68
- end
69
- end
70
-
71
- describe "#command_installed?" do
72
- context "when given a valid command name" do
73
- it do
74
- expect(subject.command_installed?('ruby')).to be(true)
75
- end
76
- end
77
-
78
- context "when given an unknown command name" do
79
- it "must return nil" do
80
- expect(subject.command_installed?('does_not_exist')).to be(false)
81
- end
82
- end
83
- end
84
- end
data/spec/env_spec.rb DELETED
@@ -1,123 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/env'
3
-
4
- describe CommandKit::Env do
5
- module TestEnv
6
- class TestCommand
7
- include CommandKit::Env
8
- end
9
- end
10
-
11
- let(:command_class) { TestEnv::TestCommand }
12
-
13
- describe "#initialize" do
14
- module TestEnv
15
- class TestCommandWithInitialize
16
- include CommandKit::Env
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::Env
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 #env to ENV" do
44
- expect(subject.env).to be(ENV)
45
- end
46
-
47
- context "and the including class defines it's own #initialize method" do
48
- let(:command_class) { TestEnv::TestCommandWithInitialize }
49
-
50
- it "must initialize #env to ENV" do
51
- expect(subject.env).to be(ENV)
52
- end
53
-
54
- it "must also call the class'es #initialize method" do
55
- expect(subject.var).to eq('foo')
56
- end
57
-
58
- context "and it accepts keyword arguments" do
59
- let(:command_class) { TestEnv::TestCommandWithInitializeAndKeywordArgs }
60
- let(:var) { 'custom value' }
61
-
62
- subject { command_class.new(var: var) }
63
-
64
- it "must initialize #env to ENV" do
65
- expect(subject.env).to be(ENV)
66
- end
67
-
68
- it "must also call the class'es #initialize method with any additional keyword arguments" do
69
- expect(subject.var).to eq(var)
70
- end
71
- end
72
- end
73
- end
74
-
75
- context "when given a custom env: value" do
76
- let(:custom_env) { {'FOO' => 'bar'} }
77
-
78
- subject { command_class.new(env: custom_env) }
79
-
80
- it "must initialize #env to the env: value" do
81
- expect(subject.env).to eq(custom_env)
82
- end
83
-
84
- context "and the including class defines it's own #initialize method" do
85
- let(:command_class) { TestEnv::TestCommandWithInitialize }
86
-
87
- it "must initialize #env to the env: value" do
88
- expect(subject.env).to eq(custom_env)
89
- end
90
-
91
- it "must also call the class'es #initialize method" do
92
- expect(subject.var).to eq('foo')
93
- end
94
-
95
- context "and it accepts keyword arguments" do
96
- let(:command_class) { TestEnv::TestCommandWithInitializeAndKeywordArgs }
97
- let(:var) { 'custom value' }
98
-
99
- subject { command_class.new(env: custom_env, var: var) }
100
-
101
- it "must initialize #env to the env: value" do
102
- expect(subject.env).to eq(custom_env)
103
- end
104
-
105
- it "must also call the class'es #initialize method with any additional keyword arguments" do
106
- expect(subject.var).to eq(var)
107
- end
108
- end
109
- end
110
- end
111
- end
112
-
113
- describe "#env" do
114
- let(:command_class) { TestEnv::TestCommand }
115
- let(:env) { {"FOO" => "bar" } }
116
-
117
- subject { command_class.new(env: env) }
118
-
119
- it "must return the initialized env: value" do
120
- expect(subject.env).to eq(env)
121
- end
122
- end
123
- end
@@ -1,211 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/examples'
3
-
4
- describe CommandKit::Examples do
5
- module TestExamples
6
- class ImplicitCmd
7
- include CommandKit::Examples
8
- end
9
- end
10
-
11
- let(:command_class) { TestExamples::ImplicitCmd }
12
-
13
- describe ".examples" do
14
- subject { TestExamples::ImplicitCmd }
15
-
16
- context "when no examples have been set" do
17
- it "should default to nil" do
18
- expect(subject.examples).to be_nil
19
- end
20
- end
21
-
22
- context "when a examples is explicitly set" do
23
- module TestExamples
24
- class ExplicitCmd
25
- include CommandKit::Examples
26
- examples [
27
- '--example 1',
28
- '--example 2'
29
- ]
30
- end
31
- end
32
-
33
- subject { TestExamples::ExplicitCmd }
34
-
35
- it "must return the explicitly set examples" do
36
- expect(subject.examples).to eq([
37
- '--example 1',
38
- '--example 2'
39
- ])
40
- end
41
- end
42
-
43
- context "when the command class inherites from another class" do
44
- context "but no examples is set" do
45
- module TestExamples
46
- class BaseCmd
47
- include CommandKit::Examples
48
- end
49
-
50
- class InheritedCmd < BaseCmd
51
- end
52
- end
53
-
54
- subject { TestExamples::InheritedCmd }
55
-
56
- it "must search each class then return nil "do
57
- expect(subject.examples).to be_nil
58
- end
59
- end
60
-
61
- module TestExamples
62
- class ExplicitBaseCmd
63
- include CommandKit::Examples
64
- examples [
65
- '--example 1',
66
- '--example 2'
67
- ]
68
- end
69
- end
70
-
71
- context "when the superclass defines an explicit examples" do
72
- module TestExamples
73
- class ImplicitInheritedCmd < ExplicitBaseCmd
74
- end
75
- end
76
-
77
- let(:super_subject) { TestExamples::ExplicitBaseCmd }
78
- subject { TestExamples::ImplicitInheritedCmd }
79
-
80
- it "must inherit the superclass'es examples" do
81
- expect(subject.examples).to eq(super_subject.examples)
82
- end
83
-
84
- it "must not change the superclass'es examples" do
85
- expect(super_subject.examples).to eq([
86
- '--example 1',
87
- '--example 2'
88
- ])
89
- end
90
- end
91
-
92
- context "when the subclass defines an explicit examples" do
93
- module TestExamples
94
- class ImplicitBaseCmd
95
- include CommandKit::Examples
96
- end
97
-
98
- class ExplicitInheritedCmd < ImplicitBaseCmd
99
- examples [
100
- '--example 1',
101
- '--example 2'
102
- ]
103
- end
104
- end
105
-
106
- let(:super_subject) { TestExamples::ImplicitBaseCmd }
107
- subject { TestExamples::ExplicitInheritedCmd }
108
-
109
- it "must return the subclass'es examples" do
110
- expect(subject.examples).to eq([
111
- '--example 1',
112
- '--example 2'
113
- ])
114
- end
115
-
116
- it "must not change the superclass'es examples" do
117
- expect(super_subject.examples).to be_nil
118
- end
119
- end
120
-
121
- context "when both the subclass overrides the superclass's exampless" do
122
- module TestExamples
123
- class ExplicitOverridingInheritedCmd < ExplicitBaseCmd
124
- examples [
125
- '--example override'
126
- ]
127
- end
128
- end
129
-
130
- let(:super_subject) { TestExamples::ExplicitBaseCmd }
131
- subject { TestExamples::ExplicitOverridingInheritedCmd }
132
-
133
- it "must return the subclass'es examples" do
134
- expect(subject.examples).to eq([
135
- '--example override'
136
- ])
137
- end
138
-
139
- it "must not change the superclass'es examples" do
140
- expect(super_subject.examples).to eq([
141
- '--example 1',
142
- '--example 2'
143
- ])
144
- end
145
- end
146
- end
147
- end
148
-
149
- subject { command_class.new }
150
-
151
- describe "#examples" do
152
- it "must be the same as .examples" do
153
- expect(subject.examples).to eq(command_class.examples)
154
- end
155
- end
156
-
157
- describe "#help_examples" do
158
- context "when #examples returns nil" do
159
- module TestExamples
160
- class NoExamples
161
- include CommandKit::Examples
162
- end
163
- end
164
-
165
- let(:command_class) { TestExamples::NoExamples }
166
- subject { command_class.new }
167
-
168
- it "must print out the examples" do
169
- expect { subject.help_examples }.to_not output.to_stdout
170
- end
171
- end
172
-
173
- context "when #examples returns an Array" do
174
- module TestExamples
175
- class MultipleExamples
176
- include CommandKit::Examples
177
-
178
- examples [
179
- '--example 1',
180
- '--example 2',
181
- '--example 3'
182
- ]
183
- end
184
- end
185
-
186
- let(:command_class) { TestExamples::MultipleExamples }
187
- subject { command_class.new }
188
-
189
- it "must print out the 'Examples:' section header and the examples" do
190
- expect { subject.help_examples }.to output(
191
- [
192
- '',
193
- "Examples:",
194
- " #{subject.command_name} #{subject.examples[0]}",
195
- " #{subject.command_name} #{subject.examples[1]}",
196
- " #{subject.command_name} #{subject.examples[2]}",
197
- ''
198
- ].join($/)
199
- ).to_stdout
200
- end
201
- end
202
- end
203
-
204
- describe "#help" do
205
- it "must call #help_examples" do
206
- expect(subject).to receive(:help_examples)
207
-
208
- subject.help
209
- end
210
- end
211
- end