clamp 1.4.0 → 1.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.
- checksums.yaml +4 -4
- data/CHANGES.md +8 -0
- data/README.md +44 -0
- data/examples/gitdown +1 -0
- data/lib/clamp/completion/bash_generator.rb +207 -0
- data/lib/clamp/completion/fish_generator.rb +176 -0
- data/lib/clamp/completion/zsh_generator.rb +123 -0
- data/lib/clamp/completion.rb +187 -0
- data/lib/clamp/version.rb +1 -1
- metadata +5 -21
- data/.autotest +0 -11
- data/.editorconfig +0 -10
- data/.github/workflows/ci.yml +0 -31
- data/.gitignore +0 -9
- data/.rspec +0 -2
- data/.rubocop.yml +0 -74
- data/CODEOWNERS +0 -1
- data/Gemfile +0 -20
- data/Guardfile +0 -45
- data/Rakefile +0 -18
- data/clamp.gemspec +0 -28
- data/spec/clamp/command_group_spec.rb +0 -438
- data/spec/clamp/command_option_module_spec.rb +0 -40
- data/spec/clamp/command_option_reordering_spec.rb +0 -58
- data/spec/clamp/command_spec.rb +0 -1280
- data/spec/clamp/help/builder_spec.rb +0 -81
- data/spec/clamp/messages_spec.rb +0 -50
- data/spec/clamp/option/definition_spec.rb +0 -343
- data/spec/clamp/parameter/definition_spec.rb +0 -314
- data/spec/spec_helper.rb +0 -65
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
describe Clamp::Parameter::Definition do
|
|
6
|
-
|
|
7
|
-
context "when regular" do
|
|
8
|
-
|
|
9
|
-
let(:parameter) do
|
|
10
|
-
described_class.new("COLOR", "hue of choice")
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "has a name" do
|
|
14
|
-
expect(parameter.name).to eq "COLOR"
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "has a description" do
|
|
18
|
-
expect(parameter.description).to eq "hue of choice"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "is single-valued" do
|
|
22
|
-
expect(parameter).not_to be_multivalued
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe "#attribute_name" do
|
|
26
|
-
|
|
27
|
-
it "is derived from the name" do
|
|
28
|
-
expect(parameter.attribute_name).to eq "color"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "can be overridden" do
|
|
32
|
-
parameter = described_class.new("COLOR", "hue of choice", attribute_name: "hue")
|
|
33
|
-
expect(parameter.attribute_name).to eq "hue"
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe "#consume" do
|
|
39
|
-
|
|
40
|
-
subject(:consume) { parameter.consume(arguments) }
|
|
41
|
-
|
|
42
|
-
context "with arguments" do
|
|
43
|
-
let(:arguments) { %w[a b c] }
|
|
44
|
-
|
|
45
|
-
it "returns one consumed argument" do
|
|
46
|
-
expect(consume).to eq ["a"]
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe "arguments after consume" do
|
|
50
|
-
|
|
51
|
-
before do
|
|
52
|
-
consume
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "has only non-consumed" do
|
|
56
|
-
expect(arguments).to eq %w[b c]
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context "without arguments" do
|
|
64
|
-
|
|
65
|
-
let(:arguments) { [] }
|
|
66
|
-
|
|
67
|
-
it "raises an Argument error" do
|
|
68
|
-
expect { consume }.to raise_error(ArgumentError)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
context "when optional (name in square brackets)" do
|
|
78
|
-
|
|
79
|
-
let(:parameter) do
|
|
80
|
-
described_class.new("[COLOR]", "hue of choice")
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "is single-valued" do
|
|
84
|
-
expect(parameter).not_to be_multivalued
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
describe "#attribute_name" do
|
|
88
|
-
|
|
89
|
-
it "omits the brackets" do
|
|
90
|
-
expect(parameter.attribute_name).to eq "color"
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
describe "#consume" do
|
|
96
|
-
|
|
97
|
-
subject(:consume) { parameter.consume(arguments) }
|
|
98
|
-
|
|
99
|
-
context "with arguments" do
|
|
100
|
-
|
|
101
|
-
let(:arguments) { %w[a b c] }
|
|
102
|
-
|
|
103
|
-
it "returns one consumed argument" do
|
|
104
|
-
expect(consume).to eq ["a"]
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
describe "arguments after consume" do
|
|
108
|
-
|
|
109
|
-
before do
|
|
110
|
-
consume
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it "has only non-consumed" do
|
|
114
|
-
expect(arguments).to eq %w[b c]
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
context "without arguments" do
|
|
121
|
-
|
|
122
|
-
let(:arguments) { [] }
|
|
123
|
-
|
|
124
|
-
it "consumes nothing" do
|
|
125
|
-
expect(consume).to be_empty
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
context "when list (name followed by ellipsis)" do
|
|
135
|
-
|
|
136
|
-
let(:parameter) do
|
|
137
|
-
described_class.new("FILE ...", "files to process")
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it "is multi-valued" do
|
|
141
|
-
expect(parameter).to be_multivalued
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
describe "#attribute_name" do
|
|
145
|
-
|
|
146
|
-
it "gets a _list suffix" do
|
|
147
|
-
expect(parameter.attribute_name).to eq "file_list"
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
describe "#append_method" do
|
|
153
|
-
|
|
154
|
-
it "is derived from the attribute_name" do
|
|
155
|
-
expect(parameter.append_method).to eq "append_to_file_list"
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
describe "#consume" do
|
|
161
|
-
|
|
162
|
-
subject(:consume) { parameter.consume(arguments) }
|
|
163
|
-
|
|
164
|
-
context "with arguments" do
|
|
165
|
-
|
|
166
|
-
let(:arguments) { %w[a b c] }
|
|
167
|
-
|
|
168
|
-
it "returns all the consumed arguments" do
|
|
169
|
-
expect(consume).to eq %w[a b c]
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
describe "arguments after consume" do
|
|
173
|
-
|
|
174
|
-
before do
|
|
175
|
-
consume
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
it "empty" do
|
|
179
|
-
expect(arguments).to be_empty
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
describe "without arguments" do
|
|
187
|
-
|
|
188
|
-
let(:arguments) { [] }
|
|
189
|
-
|
|
190
|
-
it "raises an Argument error" do
|
|
191
|
-
expect { consume }.to raise_error(ArgumentError)
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
context "with a weird parameter name, and an explicit attribute_name" do
|
|
199
|
-
|
|
200
|
-
let(:parameter) do
|
|
201
|
-
described_class.new("KEY=VALUE ...", "config-settings", attribute_name: :config_settings)
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
describe "#attribute_name" do
|
|
205
|
-
|
|
206
|
-
it "is the specified one" do
|
|
207
|
-
expect(parameter.attribute_name).to eq "config_settings"
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
context "when optional list" do
|
|
217
|
-
|
|
218
|
-
let(:parameter) do
|
|
219
|
-
described_class.new("[FILES] ...", "files to process")
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
it "is multi-valued" do
|
|
223
|
-
expect(parameter).to be_multivalued
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
describe "#attribute_name" do
|
|
227
|
-
|
|
228
|
-
it "gets a _list suffix" do
|
|
229
|
-
expect(parameter.attribute_name).to eq "files_list"
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
describe "#default_value" do
|
|
235
|
-
|
|
236
|
-
it "is an empty list" do
|
|
237
|
-
expect(parameter.default_value).to be_empty
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
describe "#help" do
|
|
243
|
-
|
|
244
|
-
it "does not include default" do
|
|
245
|
-
expect(parameter.help_rhs).not_to include("default:")
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
end
|
|
249
|
-
|
|
250
|
-
context "with specified default value" do
|
|
251
|
-
|
|
252
|
-
let(:parameter) do
|
|
253
|
-
described_class.new("[FILES] ...", "files to process", default: %w[a b c])
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
describe "#default_value" do
|
|
257
|
-
|
|
258
|
-
it "is that specified" do
|
|
259
|
-
expect(parameter.default_value).to eq %w[a b c]
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
describe "#help" do
|
|
265
|
-
|
|
266
|
-
it "includes the default value" do
|
|
267
|
-
expect(parameter.help_rhs).to include("default:")
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
describe "#consume" do
|
|
273
|
-
|
|
274
|
-
subject(:consume) { parameter.consume(arguments) }
|
|
275
|
-
|
|
276
|
-
context "with arguments" do
|
|
277
|
-
|
|
278
|
-
let(:arguments) { %w[a b c] }
|
|
279
|
-
|
|
280
|
-
it "returns all the consumed arguments" do
|
|
281
|
-
expect(consume).to eq %w[a b c]
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
describe "arguments after consume" do
|
|
285
|
-
|
|
286
|
-
before do
|
|
287
|
-
consume
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
it "empty" do
|
|
291
|
-
expect(arguments).to be_empty
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
end
|
|
297
|
-
|
|
298
|
-
context "without arguments" do
|
|
299
|
-
|
|
300
|
-
let(:arguments) { [] }
|
|
301
|
-
|
|
302
|
-
it "don't override defaults" do
|
|
303
|
-
expect(consume).to be_empty
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
end
|
|
309
|
-
|
|
310
|
-
end
|
|
311
|
-
|
|
312
|
-
end
|
|
313
|
-
|
|
314
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rspec"
|
|
4
|
-
require "clamp"
|
|
5
|
-
require "stringio"
|
|
6
|
-
require "pry-byebug"
|
|
7
|
-
|
|
8
|
-
RSpec.configure do |config|
|
|
9
|
-
|
|
10
|
-
config.around do |example|
|
|
11
|
-
example.run
|
|
12
|
-
rescue SystemExit => e
|
|
13
|
-
raise "Unexpected exit with status #{e.status}"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
module OutputCapture
|
|
19
|
-
|
|
20
|
-
def self.included(target)
|
|
21
|
-
target.before do
|
|
22
|
-
$stdout = @out = StringIO.new
|
|
23
|
-
$stderr = @err = StringIO.new
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
target.after do
|
|
27
|
-
$stdout = STDOUT
|
|
28
|
-
$stderr = STDERR
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def stdout
|
|
33
|
-
@out.string
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def stderr
|
|
37
|
-
@err.string
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
module CommandFactory
|
|
43
|
-
|
|
44
|
-
def given_command(name, &block)
|
|
45
|
-
let(:command_class) do
|
|
46
|
-
Class.new(Clamp::Command, &block)
|
|
47
|
-
end
|
|
48
|
-
let(:command) do
|
|
49
|
-
command_class.new(name)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
module SetEnv
|
|
56
|
-
|
|
57
|
-
def set_env(name, value)
|
|
58
|
-
if value
|
|
59
|
-
ENV[name] = value
|
|
60
|
-
else
|
|
61
|
-
ENV.delete(name)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
end
|