cri 2.9.0 → 2.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/NEWS.md +6 -0
- data/lib/cri/command_dsl.rb +2 -2
- data/lib/cri/option_parser.rb +28 -1
- data/lib/cri/version.rb +1 -1
- data/test/test_command_dsl.rb +4 -7
- data/test/test_option_parser.rb +24 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4071cb78d426c77cba1c810c77e618098fd0ff5
|
4
|
+
data.tar.gz: d1d4bc176390cbbceab6b6f79ce12c907e27ae37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5a100be8c1fab79a67893e7e8ee63eccb3258159526fb9624292d8d713e7a4ed05b21c7074056c4eadb71106044a006ff931a2aaec14749c33acf94f844733f
|
7
|
+
data.tar.gz: ae2e7d5e146c463344c8a445977a949b0f676a88bcc993a663d5d6add5083fee76bf2015a8a10e7d5c77b4b46e158fa4976bdcb99307d7115e4578e97efba3f2
|
data/Gemfile.lock
CHANGED
data/NEWS.md
CHANGED
data/lib/cri/command_dsl.rb
CHANGED
@@ -127,8 +127,8 @@ module Cri
|
|
127
127
|
raise ArgumentError, 'short and long options cannot both be nil'
|
128
128
|
end
|
129
129
|
|
130
|
-
if default && requiredness
|
131
|
-
raise ArgumentError,
|
130
|
+
if default && requiredness == :forbidden
|
131
|
+
raise ArgumentError, 'a default value cannot be specified for flag options'
|
132
132
|
end
|
133
133
|
|
134
134
|
@command.option_definitions << {
|
data/lib/cri/option_parser.rb
CHANGED
@@ -173,6 +173,9 @@ module Cri
|
|
173
173
|
add_argument(e)
|
174
174
|
end
|
175
175
|
end
|
176
|
+
|
177
|
+
add_defaults
|
178
|
+
|
176
179
|
self
|
177
180
|
ensure
|
178
181
|
@running = false
|
@@ -180,6 +183,10 @@ module Cri
|
|
180
183
|
|
181
184
|
private
|
182
185
|
|
186
|
+
def add_defaults
|
187
|
+
@definitions.each { |d| add_default_option(d) }
|
188
|
+
end
|
189
|
+
|
183
190
|
def handle_dashdash(e)
|
184
191
|
add_argument(e)
|
185
192
|
@no_more_options = true
|
@@ -252,7 +259,8 @@ module Cri
|
|
252
259
|
end
|
253
260
|
|
254
261
|
def add_option(definition, value)
|
255
|
-
key = (definition
|
262
|
+
key = key_for(definition)
|
263
|
+
|
256
264
|
if definition[:multiple]
|
257
265
|
options[key] ||= []
|
258
266
|
options[key] << value
|
@@ -263,6 +271,25 @@ module Cri
|
|
263
271
|
delegate.option_added(key, value, self) unless delegate.nil?
|
264
272
|
end
|
265
273
|
|
274
|
+
def add_default_option(definition)
|
275
|
+
key = key_for(definition)
|
276
|
+
return if options.key?(key)
|
277
|
+
|
278
|
+
value = definition[:default]
|
279
|
+
return unless value
|
280
|
+
|
281
|
+
if definition[:multiple]
|
282
|
+
options[key] ||= []
|
283
|
+
options[key] << value
|
284
|
+
else
|
285
|
+
options[key] = value
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
def key_for(definition)
|
290
|
+
(definition[:long] || definition[:short]).to_sym
|
291
|
+
end
|
292
|
+
|
266
293
|
def add_argument(value)
|
267
294
|
@raw_arguments << value
|
268
295
|
|
data/lib/cri/version.rb
CHANGED
data/test/test_command_dsl.rb
CHANGED
@@ -161,15 +161,12 @@ module Cri
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
-
def
|
164
|
+
def test_default_value_with_equiredness_is_required
|
165
165
|
dsl = Cri::CommandDSL.new
|
166
166
|
|
167
|
-
|
168
|
-
|
169
|
-
required 'a', 'animal', 'Specify animal', default: 'giraffe'
|
170
|
-
end
|
167
|
+
dsl.instance_eval do
|
168
|
+
required 'a', 'animal', 'Specify animal', default: 'giraffe'
|
171
169
|
end
|
172
|
-
assert_equal('a default value cannot be specified for options with required values', err.message)
|
173
170
|
end
|
174
171
|
|
175
172
|
def test_default_value_errors_when_requiredness_is_forbidden
|
@@ -180,7 +177,7 @@ module Cri
|
|
180
177
|
flag 'a', 'animal', 'Allow animal', default: 'giraffe'
|
181
178
|
end
|
182
179
|
end
|
183
|
-
assert_equal('a default value cannot be specified for options
|
180
|
+
assert_equal('a default value cannot be specified for flag options', err.message)
|
184
181
|
end
|
185
182
|
|
186
183
|
def test_subcommand
|
data/test/test_option_parser.rb
CHANGED
@@ -282,6 +282,18 @@ module Cri
|
|
282
282
|
assert_equal(3, parser.options[:verbose].size)
|
283
283
|
end
|
284
284
|
|
285
|
+
def test_parse_with_default_required_unspecified
|
286
|
+
input = %w[foo]
|
287
|
+
definitions = [
|
288
|
+
{ long: 'animal', short: 'a', argument: :required, default: 'donkey' },
|
289
|
+
]
|
290
|
+
|
291
|
+
parser = Cri::OptionParser.parse(input, definitions)
|
292
|
+
|
293
|
+
assert_equal({ animal: 'donkey' }, parser.options)
|
294
|
+
assert_equal(['foo'], parser.arguments)
|
295
|
+
end
|
296
|
+
|
285
297
|
def test_parse_with_default_required_no_value
|
286
298
|
input = %w[foo -a]
|
287
299
|
definitions = [
|
@@ -305,6 +317,18 @@ module Cri
|
|
305
317
|
assert_equal(['foo'], parser.arguments)
|
306
318
|
end
|
307
319
|
|
320
|
+
def test_parse_with_default_optional_unspecified
|
321
|
+
input = %w[foo]
|
322
|
+
definitions = [
|
323
|
+
{ long: 'animal', short: 'a', argument: :optional, default: 'donkey' },
|
324
|
+
]
|
325
|
+
|
326
|
+
parser = Cri::OptionParser.parse(input, definitions)
|
327
|
+
|
328
|
+
assert_equal({ animal: 'donkey' }, parser.options)
|
329
|
+
assert_equal(['foo'], parser.arguments)
|
330
|
+
end
|
331
|
+
|
308
332
|
def test_parse_with_default_optional_no_value
|
309
333
|
input = %w[foo -a]
|
310
334
|
definitions = [
|