clamp 1.3.2 → 1.3.3
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/.editorconfig +1 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +12 -8
- data/.travis.yml +2 -1
- data/CHANGES.md +4 -0
- data/CODEOWNERS +1 -0
- data/Gemfile +8 -5
- data/Guardfile +2 -2
- data/Rakefile +1 -3
- data/clamp.gemspec +2 -1
- data/lib/clamp/attribute/declaration.rb +1 -0
- data/lib/clamp/attribute/definition.rb +4 -2
- data/lib/clamp/attribute/instance.rb +2 -1
- data/lib/clamp/help.rb +4 -5
- data/lib/clamp/messages.rb +3 -3
- data/lib/clamp/option/declaration.rb +2 -0
- data/lib/clamp/option/definition.rb +10 -5
- data/lib/clamp/option/parsing.rb +8 -3
- data/lib/clamp/parameter/declaration.rb +3 -0
- data/lib/clamp/parameter/definition.rb +8 -5
- data/lib/clamp/parameter/parsing.rb +4 -6
- data/lib/clamp/subcommand/declaration.rb +3 -1
- data/lib/clamp/subcommand/execution.rb +2 -0
- data/lib/clamp/subcommand/parsing.rb +1 -0
- data/lib/clamp/truthy.rb +1 -1
- data/lib/clamp/version.rb +1 -1
- data/spec/clamp/command_group_spec.rb +64 -45
- data/spec/clamp/{option_module_spec.rb → command_option_module_spec.rb} +2 -1
- data/spec/clamp/{option_reordering_spec.rb → command_option_reordering_spec.rb} +3 -3
- data/spec/clamp/command_spec.rb +364 -148
- data/spec/clamp/{help_spec.rb → help/builder_spec.rb} +22 -4
- data/spec/clamp/messages_spec.rb +11 -6
- data/spec/clamp/option/definition_spec.rb +92 -40
- data/spec/clamp/parameter/definition_spec.rb +120 -50
- data/spec/spec_helper.rb +5 -6
- metadata +14 -21
@@ -4,52 +4,68 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
describe Clamp::Parameter::Definition do
|
6
6
|
|
7
|
-
context "
|
7
|
+
context "when regular" do
|
8
8
|
|
9
9
|
let(:parameter) do
|
10
10
|
described_class.new("COLOR", "hue of choice")
|
11
11
|
end
|
12
12
|
|
13
13
|
it "has a name" do
|
14
|
-
expect(parameter.name).to
|
14
|
+
expect(parameter.name).to eq "COLOR"
|
15
15
|
end
|
16
16
|
|
17
17
|
it "has a description" do
|
18
|
-
expect(parameter.description).to
|
18
|
+
expect(parameter.description).to eq "hue of choice"
|
19
19
|
end
|
20
20
|
|
21
21
|
it "is single-valued" do
|
22
|
-
expect(parameter).
|
22
|
+
expect(parameter).not_to be_multivalued
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "#attribute_name" do
|
26
26
|
|
27
27
|
it "is derived from the name" do
|
28
|
-
expect(parameter.attribute_name).to
|
28
|
+
expect(parameter.attribute_name).to eq "color"
|
29
29
|
end
|
30
30
|
|
31
31
|
it "can be overridden" do
|
32
32
|
parameter = described_class.new("COLOR", "hue of choice", attribute_name: "hue")
|
33
|
-
expect(parameter.attribute_name).to
|
33
|
+
expect(parameter.attribute_name).to eq "hue"
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "#consume" do
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
+
|
44
61
|
end
|
45
62
|
|
46
|
-
|
63
|
+
context "without arguments" do
|
64
|
+
|
65
|
+
let(:arguments) { [] }
|
47
66
|
|
48
67
|
it "raises an Argument error" do
|
49
|
-
|
50
|
-
expect do
|
51
|
-
parameter.consume(arguments)
|
52
|
-
end.to raise_error(ArgumentError)
|
68
|
+
expect { consume }.to raise_error(ArgumentError)
|
53
69
|
end
|
54
70
|
|
55
71
|
end
|
@@ -58,37 +74,55 @@ describe Clamp::Parameter::Definition do
|
|
58
74
|
|
59
75
|
end
|
60
76
|
|
61
|
-
context "optional (name in square brackets)" do
|
77
|
+
context "when optional (name in square brackets)" do
|
62
78
|
|
63
79
|
let(:parameter) do
|
64
80
|
described_class.new("[COLOR]", "hue of choice")
|
65
81
|
end
|
66
82
|
|
67
83
|
it "is single-valued" do
|
68
|
-
expect(parameter).
|
84
|
+
expect(parameter).not_to be_multivalued
|
69
85
|
end
|
70
86
|
|
71
87
|
describe "#attribute_name" do
|
72
88
|
|
73
89
|
it "omits the brackets" do
|
74
|
-
expect(parameter.attribute_name).to
|
90
|
+
expect(parameter.attribute_name).to eq "color"
|
75
91
|
end
|
76
92
|
|
77
93
|
end
|
78
94
|
|
79
95
|
describe "#consume" do
|
80
96
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
85
118
|
end
|
86
119
|
|
87
|
-
|
120
|
+
context "without arguments" do
|
121
|
+
|
122
|
+
let(:arguments) { [] }
|
88
123
|
|
89
124
|
it "consumes nothing" do
|
90
|
-
|
91
|
-
expect(parameter.consume(arguments)).to eql []
|
125
|
+
expect(consume).to be_empty
|
92
126
|
end
|
93
127
|
|
94
128
|
end
|
@@ -97,7 +131,7 @@ describe Clamp::Parameter::Definition do
|
|
97
131
|
|
98
132
|
end
|
99
133
|
|
100
|
-
context "list (name followed by ellipsis)" do
|
134
|
+
context "when list (name followed by ellipsis)" do
|
101
135
|
|
102
136
|
let(:parameter) do
|
103
137
|
described_class.new("FILE ...", "files to process")
|
@@ -110,7 +144,7 @@ describe Clamp::Parameter::Definition do
|
|
110
144
|
describe "#attribute_name" do
|
111
145
|
|
112
146
|
it "gets a _list suffix" do
|
113
|
-
expect(parameter.attribute_name).to
|
147
|
+
expect(parameter.attribute_name).to eq "file_list"
|
114
148
|
end
|
115
149
|
|
116
150
|
end
|
@@ -118,26 +152,43 @@ describe Clamp::Parameter::Definition do
|
|
118
152
|
describe "#append_method" do
|
119
153
|
|
120
154
|
it "is derived from the attribute_name" do
|
121
|
-
expect(parameter.append_method).to
|
155
|
+
expect(parameter.append_method).to eq "append_to_file_list"
|
122
156
|
end
|
123
157
|
|
124
158
|
end
|
125
159
|
|
126
160
|
describe "#consume" do
|
127
161
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|
+
|
132
184
|
end
|
133
185
|
|
134
|
-
describe "
|
186
|
+
describe "without arguments" do
|
187
|
+
|
188
|
+
let(:arguments) { [] }
|
135
189
|
|
136
190
|
it "raises an Argument error" do
|
137
|
-
|
138
|
-
expect do
|
139
|
-
parameter.consume(arguments)
|
140
|
-
end.to raise_error(ArgumentError)
|
191
|
+
expect { consume }.to raise_error(ArgumentError)
|
141
192
|
end
|
142
193
|
|
143
194
|
end
|
@@ -153,7 +204,7 @@ describe Clamp::Parameter::Definition do
|
|
153
204
|
describe "#attribute_name" do
|
154
205
|
|
155
206
|
it "is the specified one" do
|
156
|
-
expect(parameter.attribute_name).to
|
207
|
+
expect(parameter.attribute_name).to eq "config_settings"
|
157
208
|
end
|
158
209
|
|
159
210
|
end
|
@@ -162,7 +213,7 @@ describe Clamp::Parameter::Definition do
|
|
162
213
|
|
163
214
|
end
|
164
215
|
|
165
|
-
context "optional list" do
|
216
|
+
context "when optional list" do
|
166
217
|
|
167
218
|
let(:parameter) do
|
168
219
|
described_class.new("[FILES] ...", "files to process")
|
@@ -175,7 +226,7 @@ describe Clamp::Parameter::Definition do
|
|
175
226
|
describe "#attribute_name" do
|
176
227
|
|
177
228
|
it "gets a _list suffix" do
|
178
|
-
expect(parameter.attribute_name).to
|
229
|
+
expect(parameter.attribute_name).to eq "files_list"
|
179
230
|
end
|
180
231
|
|
181
232
|
end
|
@@ -183,7 +234,7 @@ describe Clamp::Parameter::Definition do
|
|
183
234
|
describe "#default_value" do
|
184
235
|
|
185
236
|
it "is an empty list" do
|
186
|
-
expect(parameter.default_value).to
|
237
|
+
expect(parameter.default_value).to be_empty
|
187
238
|
end
|
188
239
|
|
189
240
|
end
|
@@ -191,7 +242,7 @@ describe Clamp::Parameter::Definition do
|
|
191
242
|
describe "#help" do
|
192
243
|
|
193
244
|
it "does not include default" do
|
194
|
-
expect(parameter.help_rhs).
|
245
|
+
expect(parameter.help_rhs).not_to include("default:")
|
195
246
|
end
|
196
247
|
|
197
248
|
end
|
@@ -205,7 +256,7 @@ describe Clamp::Parameter::Definition do
|
|
205
256
|
describe "#default_value" do
|
206
257
|
|
207
258
|
it "is that specified" do
|
208
|
-
expect(parameter.default_value).to
|
259
|
+
expect(parameter.default_value).to eq %w[a b c]
|
209
260
|
end
|
210
261
|
|
211
262
|
end
|
@@ -220,17 +271,36 @@ describe Clamp::Parameter::Definition do
|
|
220
271
|
|
221
272
|
describe "#consume" do
|
222
273
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
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
|
+
|
227
296
|
end
|
228
297
|
|
229
|
-
context "
|
298
|
+
context "without arguments" do
|
299
|
+
|
300
|
+
let(:arguments) { [] }
|
230
301
|
|
231
302
|
it "don't override defaults" do
|
232
|
-
|
233
|
-
expect(parameter.consume(arguments)).to eql []
|
303
|
+
expect(consume).to be_empty
|
234
304
|
end
|
235
305
|
|
236
306
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,15 +3,14 @@
|
|
3
3
|
require "rspec"
|
4
4
|
require "clamp"
|
5
5
|
require "stringio"
|
6
|
+
require "pry-byebug"
|
6
7
|
|
7
8
|
RSpec.configure do |config|
|
8
9
|
|
9
|
-
config.around
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
raise "Unexpected exit with status #{e.status}"
|
14
|
-
end
|
10
|
+
config.around do |example|
|
11
|
+
example.run
|
12
|
+
rescue SystemExit => e
|
13
|
+
raise "Unexpected exit with status #{e.status}"
|
15
14
|
end
|
16
15
|
|
17
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Williams
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: |
|
14
13
|
Clamp provides an object-model for command-line utilities.
|
@@ -25,6 +24,7 @@ files:
|
|
25
24
|
- ".rubocop.yml"
|
26
25
|
- ".travis.yml"
|
27
26
|
- CHANGES.md
|
27
|
+
- CODEOWNERS
|
28
28
|
- Gemfile
|
29
29
|
- Guardfile
|
30
30
|
- LICENSE
|
@@ -61,19 +61,19 @@ files:
|
|
61
61
|
- lib/clamp/truthy.rb
|
62
62
|
- lib/clamp/version.rb
|
63
63
|
- spec/clamp/command_group_spec.rb
|
64
|
+
- spec/clamp/command_option_module_spec.rb
|
65
|
+
- spec/clamp/command_option_reordering_spec.rb
|
64
66
|
- spec/clamp/command_spec.rb
|
65
|
-
- spec/clamp/
|
67
|
+
- spec/clamp/help/builder_spec.rb
|
66
68
|
- spec/clamp/messages_spec.rb
|
67
69
|
- spec/clamp/option/definition_spec.rb
|
68
|
-
- spec/clamp/option_module_spec.rb
|
69
|
-
- spec/clamp/option_reordering_spec.rb
|
70
70
|
- spec/clamp/parameter/definition_spec.rb
|
71
71
|
- spec/spec_helper.rb
|
72
72
|
homepage: https://github.com/mdub/clamp
|
73
73
|
licenses:
|
74
74
|
- MIT
|
75
|
-
metadata:
|
76
|
-
|
75
|
+
metadata:
|
76
|
+
rubygems_mfa_required: 'true'
|
77
77
|
rdoc_options: []
|
78
78
|
require_paths:
|
79
79
|
- lib
|
@@ -81,24 +81,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
81
|
requirements:
|
82
82
|
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version: '
|
84
|
+
version: '2.5'
|
85
|
+
- - "<"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '4'
|
85
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
89
|
requirements:
|
87
90
|
- - ">="
|
88
91
|
- !ruby/object:Gem::Version
|
89
92
|
version: '0'
|
90
93
|
requirements: []
|
91
|
-
rubygems_version: 3.1
|
92
|
-
signing_key:
|
94
|
+
rubygems_version: 3.7.1
|
93
95
|
specification_version: 4
|
94
96
|
summary: a minimal framework for command-line utilities
|
95
|
-
test_files:
|
96
|
-
- spec/clamp/command_group_spec.rb
|
97
|
-
- spec/clamp/command_spec.rb
|
98
|
-
- spec/clamp/help_spec.rb
|
99
|
-
- spec/clamp/messages_spec.rb
|
100
|
-
- spec/clamp/option/definition_spec.rb
|
101
|
-
- spec/clamp/option_module_spec.rb
|
102
|
-
- spec/clamp/option_reordering_spec.rb
|
103
|
-
- spec/clamp/parameter/definition_spec.rb
|
104
|
-
- spec/spec_helper.rb
|
97
|
+
test_files: []
|