command_kit 0.4.1 → 0.5.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.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.rubocop.yml +7 -1
  4. data/ChangeLog.md +11 -0
  5. data/Gemfile +2 -0
  6. data/README.md +3 -0
  7. data/Rakefile +2 -0
  8. data/command_kit.gemspec +8 -6
  9. data/lib/command_kit/arguments/argument.rb +3 -1
  10. data/lib/command_kit/arguments/argument_value.rb +2 -0
  11. data/lib/command_kit/arguments.rb +5 -5
  12. data/lib/command_kit/bug_report.rb +4 -2
  13. data/lib/command_kit/colors.rb +2 -2
  14. data/lib/command_kit/command.rb +13 -11
  15. data/lib/command_kit/command_name.rb +3 -1
  16. data/lib/command_kit/commands/auto_load/subcommand.rb +3 -1
  17. data/lib/command_kit/commands/auto_load.rb +3 -3
  18. data/lib/command_kit/commands/auto_require.rb +5 -3
  19. data/lib/command_kit/commands/command.rb +4 -2
  20. data/lib/command_kit/commands/help.rb +2 -2
  21. data/lib/command_kit/commands/parent_command.rb +2 -0
  22. data/lib/command_kit/commands/subcommand.rb +2 -0
  23. data/lib/command_kit/commands.rb +8 -8
  24. data/lib/command_kit/completion/install.rb +277 -0
  25. data/lib/command_kit/description.rb +3 -1
  26. data/lib/command_kit/edit.rb +1 -1
  27. data/lib/command_kit/env/home.rb +1 -1
  28. data/lib/command_kit/env/path.rb +1 -1
  29. data/lib/command_kit/env/prefix.rb +41 -0
  30. data/lib/command_kit/env/shell.rb +58 -0
  31. data/lib/command_kit/env.rb +2 -0
  32. data/lib/command_kit/examples.rb +4 -2
  33. data/lib/command_kit/exception_handler.rb +4 -2
  34. data/lib/command_kit/file_utils.rb +2 -0
  35. data/lib/command_kit/help/man.rb +4 -4
  36. data/lib/command_kit/help.rb +2 -0
  37. data/lib/command_kit/interactive.rb +1 -1
  38. data/lib/command_kit/main.rb +2 -0
  39. data/lib/command_kit/open_app.rb +4 -2
  40. data/lib/command_kit/options/option.rb +3 -1
  41. data/lib/command_kit/options/option_value.rb +2 -2
  42. data/lib/command_kit/options/parser.rb +3 -3
  43. data/lib/command_kit/options/quiet.rb +3 -1
  44. data/lib/command_kit/options/verbose.rb +3 -1
  45. data/lib/command_kit/options/version.rb +3 -1
  46. data/lib/command_kit/options.rb +5 -3
  47. data/lib/command_kit/os/linux.rb +3 -1
  48. data/lib/command_kit/os.rb +2 -0
  49. data/lib/command_kit/package_manager.rb +6 -4
  50. data/lib/command_kit/pager.rb +4 -4
  51. data/lib/command_kit/printing/fields.rb +3 -1
  52. data/lib/command_kit/printing/indent.rb +2 -0
  53. data/lib/command_kit/printing/lists.rb +1 -1
  54. data/lib/command_kit/printing/tables/border_style.rb +2 -0
  55. data/lib/command_kit/printing/tables/row_builder.rb +3 -1
  56. data/lib/command_kit/printing/tables/style.rb +1 -1
  57. data/lib/command_kit/printing/tables/table_builder.rb +3 -1
  58. data/lib/command_kit/printing/tables.rb +4 -4
  59. data/lib/command_kit/printing.rb +1 -1
  60. data/lib/command_kit/program_name.rb +2 -0
  61. data/lib/command_kit/stdio.rb +2 -0
  62. data/lib/command_kit/sudo.rb +1 -1
  63. data/lib/command_kit/terminal.rb +4 -2
  64. data/lib/command_kit/usage.rb +4 -2
  65. data/lib/command_kit/version.rb +3 -1
  66. data/lib/command_kit/xdg.rb +4 -2
  67. data/lib/command_kit.rb +4 -2
  68. metadata +5 -65
  69. data/spec/arguments/argument_spec.rb +0 -133
  70. data/spec/arguments/argument_value_spec.rb +0 -66
  71. data/spec/arguments_spec.rb +0 -279
  72. data/spec/bug_report_spec.rb +0 -266
  73. data/spec/colors_spec.rb +0 -771
  74. data/spec/command_kit_spec.rb +0 -8
  75. data/spec/command_name_spec.rb +0 -130
  76. data/spec/command_spec.rb +0 -123
  77. data/spec/commands/auto_load/subcommand_spec.rb +0 -82
  78. data/spec/commands/auto_load_spec.rb +0 -159
  79. data/spec/commands/auto_require_spec.rb +0 -142
  80. data/spec/commands/fixtures/test_auto_load/cli/commands/test1.rb +0 -10
  81. data/spec/commands/fixtures/test_auto_load/cli/commands/test2.rb +0 -10
  82. data/spec/commands/fixtures/test_auto_require/lib/test_auto_require/cli/commands/test1.rb +0 -10
  83. data/spec/commands/help_spec.rb +0 -66
  84. data/spec/commands/parent_command_spec.rb +0 -40
  85. data/spec/commands/subcommand_spec.rb +0 -99
  86. data/spec/commands_spec.rb +0 -865
  87. data/spec/description_spec.rb +0 -179
  88. data/spec/edit_spec.rb +0 -72
  89. data/spec/env/home_spec.rb +0 -46
  90. data/spec/env/path_spec.rb +0 -84
  91. data/spec/env_spec.rb +0 -123
  92. data/spec/examples_spec.rb +0 -211
  93. data/spec/exception_handler_spec.rb +0 -103
  94. data/spec/file_utils_spec.rb +0 -59
  95. data/spec/fixtures/template.erb +0 -5
  96. data/spec/help/man_spec.rb +0 -345
  97. data/spec/help_spec.rb +0 -94
  98. data/spec/inflector_spec.rb +0 -166
  99. data/spec/interactive_spec.rb +0 -415
  100. data/spec/main_spec.rb +0 -179
  101. data/spec/man_spec.rb +0 -46
  102. data/spec/open_app_spec.rb +0 -85
  103. data/spec/options/option_spec.rb +0 -343
  104. data/spec/options/option_value_spec.rb +0 -171
  105. data/spec/options/parser_spec.rb +0 -274
  106. data/spec/options/quiet_spec.rb +0 -51
  107. data/spec/options/verbose_spec.rb +0 -51
  108. data/spec/options/version_spec.rb +0 -146
  109. data/spec/options_spec.rb +0 -465
  110. data/spec/os/linux_spec.rb +0 -164
  111. data/spec/os_spec.rb +0 -233
  112. data/spec/package_manager_spec.rb +0 -806
  113. data/spec/pager_spec.rb +0 -217
  114. data/spec/printing/fields_spec.rb +0 -167
  115. data/spec/printing/indent_spec.rb +0 -132
  116. data/spec/printing/lists_spec.rb +0 -99
  117. data/spec/printing/tables/border_style.rb +0 -43
  118. data/spec/printing/tables/cell_builer_spec.rb +0 -135
  119. data/spec/printing/tables/row_builder_spec.rb +0 -165
  120. data/spec/printing/tables/style_spec.rb +0 -377
  121. data/spec/printing/tables/table_builder_spec.rb +0 -252
  122. data/spec/printing/tables/table_formatter_spec.rb +0 -1190
  123. data/spec/printing/tables_spec.rb +0 -1069
  124. data/spec/printing_spec.rb +0 -106
  125. data/spec/program_name_spec.rb +0 -70
  126. data/spec/spec_helper.rb +0 -3
  127. data/spec/stdio_spec.rb +0 -264
  128. data/spec/sudo_spec.rb +0 -51
  129. data/spec/terminal_spec.rb +0 -231
  130. data/spec/usage_spec.rb +0 -237
  131. data/spec/xdg_spec.rb +0 -191
@@ -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
@@ -1,66 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/arguments/argument_value'
3
-
4
- describe CommandKit::Arguments::ArgumentValue do
5
- let(:required) { false }
6
- let(:usage) { 'FOO' }
7
-
8
- subject do
9
- described_class.new(
10
- required: required,
11
- usage: usage
12
- )
13
- end
14
-
15
- describe "#initialize" do
16
- it "must require a usage: keyword"do
17
- expect {
18
- described_class.new(required: required)
19
- }.to raise_error(ArgumentError)
20
- end
21
-
22
- context "when required: is given" do
23
- subject { described_class.new(required: required, usage: usage) }
24
-
25
- it "must set #required" do
26
- expect(subject.required).to eq(required)
27
- end
28
- end
29
-
30
- context "when required: is not given" do
31
- subject { described_class.new(usage: usage) }
32
-
33
- it "must default to true" do
34
- expect(subject.required).to be(true)
35
- end
36
- end
37
- end
38
-
39
- describe "#required?" do
40
- context "when required: is initialized with true" do
41
- let(:required) { true }
42
-
43
- it { expect(subject.required?).to be(true) }
44
- end
45
-
46
- context "when required: is initialized with false" do
47
- let(:required) { false }
48
-
49
- it { expect(subject.required?).to be(false) }
50
- end
51
- end
52
-
53
- describe "#optional?" do
54
- context "when required: is initialized with true" do
55
- let(:required) { true }
56
-
57
- it { expect(subject.optional?).to be(false) }
58
- end
59
-
60
- context "when required: is initialized with false" do
61
- let(:required) { false }
62
-
63
- it { expect(subject.optional?).to be(true) }
64
- end
65
- end
66
- end
@@ -1,279 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/arguments'
3
-
4
- describe CommandKit::Arguments do
5
- module TestArguments
6
- class ImplicitCmd
7
- include CommandKit::Arguments
8
- end
9
- end
10
-
11
- let(:command_class) { TestArguments::ImplicitCmd }
12
-
13
- describe ".included" do
14
- subject { command_class }
15
-
16
- it { expect(subject).to include(CommandKit::Main) }
17
- it { expect(subject).to include(CommandKit::Help) }
18
- end
19
-
20
- describe ".arguments" do
21
- subject { TestArguments::ImplicitCmd }
22
-
23
- context "when no arguments have been defined" do
24
- it "should default to {}" do
25
- expect(subject.arguments).to eq({})
26
- end
27
- end
28
-
29
- context "when a arguments is explicitly set" do
30
- module TestArguments
31
- class ExplicitCmd
32
- include CommandKit::Arguments
33
- argument :foo, desc: 'Foo option'
34
- argument :bar, desc: 'Bar option'
35
- end
36
- end
37
-
38
- subject { TestArguments::ExplicitCmd }
39
-
40
- it "must return the explicitly set arguments" do
41
- expect(subject.arguments.keys).to eq([:foo, :bar])
42
- end
43
- end
44
-
45
- context "when the command class inherites from another class" do
46
- context "but no arguments are defined" do
47
- module TestArguments
48
- class BaseCmd
49
- include CommandKit::Arguments
50
- end
51
-
52
- class InheritedCmd < BaseCmd
53
- end
54
- end
55
-
56
- subject { TestArguments::InheritedCmd }
57
-
58
- it "must search each class then return {}"do
59
- expect(subject.arguments).to eq({})
60
- end
61
- end
62
-
63
- module TestArguments
64
- class ExplicitBaseCmd
65
- include CommandKit::Arguments
66
- argument :foo, desc: 'Foo option'
67
- argument :bar, desc: 'Bar option'
68
- end
69
- end
70
-
71
- context "when the superclass defines arguments" do
72
- module TestArguments
73
- class ImplicitInheritedCmd < ExplicitBaseCmd
74
- end
75
- end
76
-
77
- let(:super_subject) { TestArguments::ExplicitBaseCmd }
78
- subject { TestArguments::ImplicitInheritedCmd }
79
-
80
- it "must inherit the superclass'es arguments" do
81
- expect(subject.arguments).to eq(super_subject.arguments)
82
- end
83
-
84
- it "must not change the superclass'es arguments" do
85
- expect(super_subject.arguments.keys).to eq([:foo, :bar])
86
- end
87
- end
88
-
89
- context "when the subclass defines arguments" do
90
- module TestArguments
91
- class ImplicitBaseCmd
92
- include CommandKit::Arguments
93
- end
94
-
95
- class ExplicitInheritedCmd < ImplicitBaseCmd
96
- argument :baz, desc: 'Baz option'
97
- argument :qux, desc: 'Qux option'
98
- end
99
- end
100
-
101
- let(:super_subject) { TestArguments::ImplicitBaseCmd }
102
- subject { TestArguments::ExplicitInheritedCmd }
103
-
104
- it "must return the subclass'es arguments" do
105
- expect(subject.arguments.keys).to eq([:baz, :qux])
106
- end
107
-
108
- it "must not change the superclass'es arguments" do
109
- expect(super_subject.arguments).to eq({})
110
- end
111
- end
112
-
113
- context "when subclass overrides the superclass's argumentss" do
114
- module TestArguments
115
- class ExplicitOverridingInheritedCmd < ExplicitBaseCmd
116
- argument :foo, desc: "Overriden foo option"
117
- end
118
- end
119
-
120
- let(:super_subject) { TestArguments::ExplicitBaseCmd }
121
- subject { TestArguments::ExplicitOverridingInheritedCmd }
122
-
123
- it "must combine the superclass'es arguments with the subclass'es" do
124
- expect(subject.arguments.keys).to eq([:foo, :bar])
125
- expect(subject.arguments[:foo].desc).to eq("Overriden foo option")
126
- expect(subject.arguments[:bar].desc).to eq("Bar option")
127
- end
128
-
129
- it "must not change the superclass'es arguments" do
130
- expect(super_subject.arguments.keys).to eq([:foo, :bar])
131
- expect(super_subject.arguments[:foo].desc).to eq("Foo option")
132
- expect(super_subject.arguments[:bar].desc).to eq("Bar option")
133
- end
134
- end
135
- end
136
- end
137
-
138
- subject { command_class.new }
139
-
140
- describe "#main" do
141
- module TestArguments
142
- class TestCommand
143
-
144
- include CommandKit::Arguments
145
-
146
- argument :argument1, required: true,
147
- usage: 'ARG1',
148
- desc: "Argument 1"
149
-
150
- argument :argument2, required: false,
151
- usage: 'ARG2',
152
- desc: "Argument 2"
153
-
154
- end
155
- end
156
-
157
- let(:command_class) { TestArguments::TestCommand }
158
-
159
- context "when given the correct number of arguments" do
160
- let(:argv) { %w[arg1 arg2] }
161
-
162
- it "must parse options before validating the number of arguments" do
163
- expect {
164
- expect(subject.main(argv)).to eq(0)
165
- }.to_not output.to_stderr
166
- end
167
- end
168
-
169
- context "when given fewer than the required number of arguments" do
170
- let(:argv) { %w[] }
171
-
172
- it "must print an error message and return 1" do
173
- expect {
174
- expect(subject.main(argv)).to eq(1)
175
- }.to output("#{subject.command_name}: insufficient number of arguments.#{$/}").to_stderr
176
- end
177
- end
178
-
179
- context "when given more than the total number of arguments" do
180
- let(:argv) { %w[foo bar baz] }
181
-
182
- it "must print an error message and return 1" do
183
- expect {
184
- expect(subject.main(argv)).to eq(1)
185
- }.to output("#{subject.command_name}: too many arguments given.#{$/}").to_stderr
186
- end
187
- end
188
- end
189
-
190
- describe "#help_arguments" do
191
- context "when #arguments returns {}" do
192
- module TestArguments
193
- class NoArguments
194
- include CommandKit::Arguments
195
- end
196
- end
197
-
198
- let(:command_class) { TestArguments::NoArguments }
199
- subject { command_class.new }
200
-
201
- it "must print out the arguments" do
202
- expect { subject.help_arguments }.to_not output.to_stdout
203
- end
204
- end
205
-
206
- context "when #arguments returns a Hash" do
207
- module TestArguments
208
- class MultipleArguments
209
- include CommandKit::Arguments
210
-
211
- argument :foo, desc: "Foo option"
212
- argument :bar, desc: "Bar option"
213
- argument :baz, desc: "Baz option"
214
- end
215
- end
216
-
217
- let(:command_class) { TestArguments::MultipleArguments }
218
- subject { command_class.new }
219
-
220
- let(:foo_argument) { command_class.arguments[:foo] }
221
- let(:bar_argument) { command_class.arguments[:bar] }
222
- let(:baz_argument) { command_class.arguments[:baz] }
223
-
224
- it "must print out the 'Arguments:' section header and the arguments" do
225
- expect { subject.help_arguments }.to output(
226
- [
227
- '',
228
- "Arguments:",
229
- " #{foo_argument.usage.ljust(33)}#{foo_argument.desc}",
230
- " #{bar_argument.usage.ljust(33)}#{bar_argument.desc}",
231
- " #{baz_argument.usage.ljust(33)}#{baz_argument.desc}",
232
- ''
233
- ].join($/)
234
- ).to_stdout
235
- end
236
-
237
- context "when one the argument has an Array for a description" do
238
- module TestArguments
239
- class MultiLineArgumentDescription
240
- include CommandKit::Arguments
241
-
242
- argument :foo, desc: "Foo option"
243
- argument :bar, desc: [
244
- "Bar option",
245
- "Line 2",
246
- "Line 3"
247
- ]
248
- argument :baz, desc: "Baz option"
249
- end
250
- end
251
-
252
- let(:command_class) { TestArguments::MultiLineArgumentDescription }
253
-
254
- it "must print out each line of a multi-line argument description" do
255
- expect { subject.help_arguments }.to output(
256
- [
257
- '',
258
- "Arguments:",
259
- " #{foo_argument.usage.ljust(33)}#{foo_argument.desc}",
260
- " #{bar_argument.usage.ljust(33)}#{bar_argument.desc[0]}",
261
- " #{' '.ljust(33)}#{bar_argument.desc[1]}",
262
- " #{' '.ljust(33)}#{bar_argument.desc[2]}",
263
- " #{baz_argument.usage.ljust(33)}#{baz_argument.desc}",
264
- ''
265
- ].join($/)
266
- ).to_stdout
267
- end
268
- end
269
- end
270
- end
271
-
272
- describe "#help" do
273
- it "must call #help_arguments" do
274
- expect(subject).to receive(:help_arguments)
275
-
276
- subject.help
277
- end
278
- end
279
- end