cri 2.15.0 → 2.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 146523ca2691641e1484d4765e730e990d70d7d32b2ab5aaf9e6911e089fab8b
4
- data.tar.gz: 9d77fc29f799f5a18d13089bd41c2c309bebfaa6620b63f07be57b354c5e33aa
3
+ metadata.gz: 13bfd2fd90ec81e8bcc39c154881b0e54ac05696fce5a237cf17d3204b543c9c
4
+ data.tar.gz: d14b7481ce82280b035fd0f20a78e62c417e47efe545d24bebf5302b1668fb3d
5
5
  SHA512:
6
- metadata.gz: ccb3ac10e23d38eda1f739f6b33ac68540d9ab9895ac66870fba15f4b7c6ae2ff159c706627996bc8ee9f566fed0068a11b708df2747df77400070ad48ed0163
7
- data.tar.gz: 0464fc3a9942c35b7f6477af69495a716d06abd6bf5c2197d955342b2d77f001b3a52b795ebe4b2a186f45eaea3cb5b13fe22458fed986706dae756a1092fd18
6
+ metadata.gz: 06ba0a5ab7632765e40bcf3b3245418f90e414b106fad162cbd4b59e50af3152bfed637da0fb9ed3b074922dcecb8e78d6d7501a849a6763d980be3030aee7b4
7
+ data.tar.gz: 273ef37de868f8b546d084b48073a8f13d67b7fb57f765b4764bf4305c5992e863b46e016e45fbf4888b48291dc017a1892d6394a564374402a0466cafdb1e41
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cri (2.15.0)
4
+ cri (2.15.1)
5
5
  colored (~> 1.2)
6
6
 
7
7
  GEM
data/NEWS.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Cri News
2
2
 
3
+ ## 2.15.1
4
+
5
+ Fixes:
6
+
7
+ * Made -h/--help not fail when parameters are defined for the command that -h/--help is called on (#76, #78)
8
+
9
+ Enhancements:
10
+
11
+ * Made `#option` raise an error when unrecognised parameters are passed to it (#77) [Marc-André Lafortune]
12
+
3
13
  ## 2.15.0
4
14
 
5
15
  Features:
@@ -345,10 +345,10 @@ module Cri
345
345
  handle_errors_while { parser.run }
346
346
  local_opts = parser.options
347
347
  global_opts = parent_opts.merge(parser.options)
348
- args = handle_errors_while { parser.arguments }
349
348
 
350
349
  # Handle options
351
350
  handle_options(local_opts)
351
+ args = handle_errors_while { parser.gen_argument_list }
352
352
  end
353
353
 
354
354
  # Execute
@@ -152,17 +152,23 @@ module Cri
152
152
  # be printed in the help output
153
153
  #
154
154
  # @return [void]
155
- def option(short, long, desc, params = {}, &block)
155
+ def option(short, long, desc,
156
+ argument: :forbidden,
157
+ multiple: false,
158
+ hidden: false,
159
+ default: nil,
160
+ transform: nil,
161
+ &block)
156
162
  @command.option_definitions << Cri::OptionDefinition.new(
157
163
  short: short&.to_s,
158
164
  long: long&.to_s,
159
165
  desc: desc,
160
- argument: params.fetch(:argument, :forbidden),
161
- multiple: params.fetch(:multiple, false),
166
+ argument: argument,
167
+ multiple: multiple,
168
+ hidden: hidden,
169
+ default: default,
170
+ transform: transform,
162
171
  block: block,
163
- hidden: params.fetch(:hidden, false),
164
- default: params.fetch(:default, nil),
165
- transform: params.fetch(:transform, nil),
166
172
  )
167
173
  end
168
174
  alias opt option
@@ -127,7 +127,7 @@ module Cri
127
127
 
128
128
  # @return [Cri::ArgumentList] The list of arguments that have already been
129
129
  # parsed, excluding the -- separator.
130
- def arguments
130
+ def gen_argument_list
131
131
  ArgumentList.new(@raw_arguments, @explicitly_no_params, @param_defns)
132
132
  end
133
133
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Cri
4
4
  # The current Cri version.
5
- VERSION = '2.15.0'
5
+ VERSION = '2.15.1'
6
6
  end
@@ -830,5 +830,33 @@ module Cri
830
830
  assert_equal('moo', cmd.name)
831
831
  end
832
832
  end
833
+
834
+ def test_required_args_with_dash_h
835
+ dsl = Cri::CommandDSL.new
836
+ dsl.instance_eval do
837
+ name 'moo'
838
+ usage 'dunno whatever'
839
+ summary 'does stuff'
840
+ description 'This command does a lot of stuff.'
841
+
842
+ param :foo
843
+
844
+ option :h, :help, 'show help' do
845
+ $helped = true
846
+ exit 0
847
+ end
848
+ end
849
+ command = dsl.command
850
+
851
+ $helped = false
852
+ out, err = capture_io_while do
853
+ assert_raises SystemExit do
854
+ command.run(['-h'])
855
+ end
856
+ end
857
+ assert $helped
858
+ assert_equal [], lines(out)
859
+ assert_equal [], lines(err)
860
+ end
833
861
  end
834
862
  end
@@ -138,6 +138,14 @@ module Cri
138
138
  assert_equal expected_option_definitions, actual_option_definitions
139
139
  end
140
140
 
141
+ def test_raises_on_unrecognized_option
142
+ # Define
143
+ dsl = Cri::CommandDSL.new
144
+ assert_raises ArgumentError do
145
+ dsl.option :s, :long, 'desc', unrecognized: true
146
+ end
147
+ end
148
+
141
149
  def test_required_short_and_long
142
150
  # Define
143
151
  dsl = Cri::CommandDSL.new
@@ -11,7 +11,7 @@ module Cri
11
11
  parser = Cri::Parser.new(input, opt_defns, [], false).run
12
12
 
13
13
  assert_equal({}, parser.options)
14
- assert_equal(%w[foo bar baz], parser.arguments.to_a)
14
+ assert_equal(%w[foo bar baz], parser.gen_argument_list.to_a)
15
15
  end
16
16
 
17
17
  def test_parse_with_invalid_option
@@ -43,7 +43,7 @@ module Cri
43
43
  parser = Cri::Parser.new(input, opt_defns, [], false).run
44
44
 
45
45
  assert(parser.options[:aaa])
46
- assert_equal(%w[foo bar], parser.arguments.to_a)
46
+ assert_equal(%w[foo bar], parser.gen_argument_list.to_a)
47
47
  end
48
48
 
49
49
  def test_parse_with_long_valueful_option
@@ -55,7 +55,7 @@ module Cri
55
55
  parser = Cri::Parser.new(input, opt_defns, [], false).run
56
56
 
57
57
  assert_equal({ aaa: 'xxx' }, parser.options)
58
- assert_equal(%w[foo bar], parser.arguments.to_a)
58
+ assert_equal(%w[foo bar], parser.gen_argument_list.to_a)
59
59
  end
60
60
 
61
61
  def test_parse_with_long_valueful_equalsign_option
@@ -67,7 +67,7 @@ module Cri
67
67
  parser = Cri::Parser.new(input, opt_defns, [], false).run
68
68
 
69
69
  assert_equal({ aaa: 'xxx' }, parser.options)
70
- assert_equal(%w[foo bar], parser.arguments.to_a)
70
+ assert_equal(%w[foo bar], parser.gen_argument_list.to_a)
71
71
  end
72
72
 
73
73
  def test_parse_with_long_valueful_option_with_missing_value
@@ -102,7 +102,7 @@ module Cri
102
102
  parser = Cri::Parser.new(input, opt_defns, [], false).run
103
103
 
104
104
  assert(parser.options[:aaa])
105
- assert_equal(['foo'], parser.arguments.to_a)
105
+ assert_equal(['foo'], parser.gen_argument_list.to_a)
106
106
  end
107
107
 
108
108
  def test_parse_with_long_valueful_option_with_optional_value
@@ -114,7 +114,7 @@ module Cri
114
114
  parser = Cri::Parser.new(input, opt_defns, [], false).run
115
115
 
116
116
  assert_equal({ aaa: 'xxx' }, parser.options)
117
- assert_equal(['foo'], parser.arguments.to_a)
117
+ assert_equal(['foo'], parser.gen_argument_list.to_a)
118
118
  end
119
119
 
120
120
  def test_parse_with_long_valueless_option_with_optional_value_and_more_options
@@ -130,7 +130,7 @@ module Cri
130
130
  assert(parser.options[:aaa])
131
131
  assert(parser.options[:bbb])
132
132
  assert(parser.options[:ccc])
133
- assert_equal(['foo'], parser.arguments.to_a)
133
+ assert_equal(['foo'], parser.gen_argument_list.to_a)
134
134
  end
135
135
 
136
136
  def test_parse_with_short_valueless_options
@@ -142,7 +142,7 @@ module Cri
142
142
  parser = Cri::Parser.new(input, opt_defns, [], false).run
143
143
 
144
144
  assert(parser.options[:aaa])
145
- assert_equal(%w[foo bar], parser.arguments.to_a)
145
+ assert_equal(%w[foo bar], parser.gen_argument_list.to_a)
146
146
  end
147
147
 
148
148
  def test_parse_with_short_valueful_option_with_missing_value
@@ -169,7 +169,7 @@ module Cri
169
169
  assert(parser.options[:aaa])
170
170
  assert(parser.options[:bbb])
171
171
  assert(parser.options[:ccc])
172
- assert_equal(%w[foo bar], parser.arguments.to_a)
172
+ assert_equal(%w[foo bar], parser.gen_argument_list.to_a)
173
173
  end
174
174
 
175
175
  def test_parse_with_short_combined_valueful_options_with_missing_value
@@ -185,7 +185,7 @@ module Cri
185
185
  assert_equal('bar', parser.options[:aaa])
186
186
  assert(parser.options[:bbb])
187
187
  assert(parser.options[:ccc])
188
- assert_equal(%w[foo qux], parser.arguments.to_a)
188
+ assert_equal(%w[foo qux], parser.gen_argument_list.to_a)
189
189
  end
190
190
 
191
191
  def test_parse_with_two_short_valueful_options
@@ -209,7 +209,7 @@ module Cri
209
209
  parser = Cri::Parser.new(input, opt_defns, [], false).run
210
210
 
211
211
  assert(parser.options[:aaa])
212
- assert_equal(['foo'], parser.arguments.to_a)
212
+ assert_equal(['foo'], parser.gen_argument_list.to_a)
213
213
  end
214
214
 
215
215
  def test_parse_with_short_valueful_option_with_optional_value
@@ -221,7 +221,7 @@ module Cri
221
221
  parser = Cri::Parser.new(input, opt_defns, [], false).run
222
222
 
223
223
  assert_equal({ aaa: 'xxx' }, parser.options)
224
- assert_equal(['foo'], parser.arguments.to_a)
224
+ assert_equal(['foo'], parser.gen_argument_list.to_a)
225
225
  end
226
226
 
227
227
  def test_parse_with_short_valueless_option_with_optional_value_and_more_options
@@ -237,7 +237,7 @@ module Cri
237
237
  assert(parser.options[:aaa])
238
238
  assert(parser.options[:bbb])
239
239
  assert(parser.options[:ccc])
240
- assert_equal(['foo'], parser.arguments.to_a)
240
+ assert_equal(['foo'], parser.gen_argument_list.to_a)
241
241
  end
242
242
 
243
243
  def test_parse_with_single_hyphen
@@ -247,7 +247,7 @@ module Cri
247
247
  parser = Cri::Parser.new(input, opt_defns, [], false).run
248
248
 
249
249
  assert_equal({}, parser.options)
250
- assert_equal(['foo', '-', 'bar'], parser.arguments.to_a)
250
+ assert_equal(['foo', '-', 'bar'], parser.gen_argument_list.to_a)
251
251
  end
252
252
 
253
253
  def test_parse_with_end_marker
@@ -257,7 +257,7 @@ module Cri
257
257
  parser = Cri::Parser.new(input, opt_defns, [], false).run
258
258
 
259
259
  assert_equal({}, parser.options)
260
- assert_equal(['foo', 'bar', '-x', '--yyy', '-abc'], parser.arguments.to_a)
260
+ assert_equal(['foo', 'bar', '-x', '--yyy', '-abc'], parser.gen_argument_list.to_a)
261
261
  end
262
262
 
263
263
  def test_parse_with_end_marker_between_option_key_and_value
@@ -293,7 +293,7 @@ module Cri
293
293
  parser = Cri::Parser.new(input, opt_defns, [], false).run
294
294
 
295
295
  assert_equal({ animal: 'donkey' }, parser.options)
296
- assert_equal(['foo'], parser.arguments.to_a)
296
+ assert_equal(['foo'], parser.gen_argument_list.to_a)
297
297
  end
298
298
 
299
299
  def test_parse_with_default_required_no_value
@@ -316,7 +316,7 @@ module Cri
316
316
  parser = Cri::Parser.new(input, opt_defns, [], false).run
317
317
 
318
318
  assert_equal({ animal: 'giraffe' }, parser.options)
319
- assert_equal(['foo'], parser.arguments.to_a)
319
+ assert_equal(['foo'], parser.gen_argument_list.to_a)
320
320
  end
321
321
 
322
322
  def test_parse_with_default_optional_unspecified
@@ -328,7 +328,7 @@ module Cri
328
328
  parser = Cri::Parser.new(input, opt_defns, [], false).run
329
329
 
330
330
  assert_equal({ animal: 'donkey' }, parser.options)
331
- assert_equal(['foo'], parser.arguments.to_a)
331
+ assert_equal(['foo'], parser.gen_argument_list.to_a)
332
332
  end
333
333
 
334
334
  def test_parse_with_default_optional_no_value
@@ -340,7 +340,7 @@ module Cri
340
340
  parser = Cri::Parser.new(input, opt_defns, [], false).run
341
341
 
342
342
  assert_equal({ animal: 'donkey' }, parser.options)
343
- assert_equal(['foo'], parser.arguments.to_a)
343
+ assert_equal(['foo'], parser.gen_argument_list.to_a)
344
344
  end
345
345
 
346
346
  def test_parse_with_default_optional_value
@@ -352,7 +352,7 @@ module Cri
352
352
  parser = Cri::Parser.new(input, opt_defns, [], false).run
353
353
 
354
354
  assert_equal({ animal: 'giraffe' }, parser.options)
355
- assert_equal(['foo'], parser.arguments.to_a)
355
+ assert_equal(['foo'], parser.gen_argument_list.to_a)
356
356
  end
357
357
 
358
358
  def test_parse_with_default_optional_value_and_arg
@@ -364,7 +364,7 @@ module Cri
364
364
  parser = Cri::Parser.new(input, opt_defns, [], false).run
365
365
 
366
366
  assert_equal({ animal: 'gi' }, parser.options)
367
- assert_equal(%w[foo raffe], parser.arguments.to_a)
367
+ assert_equal(%w[foo raffe], parser.gen_argument_list.to_a)
368
368
  end
369
369
 
370
370
  def test_parse_with_combined_required_options
@@ -378,7 +378,7 @@ module Cri
378
378
  parser = Cri::Parser.new(input, opt_defns, [], false).run
379
379
 
380
380
  assert_equal({ aaa: true, bbb: 'xxx', ccc: 'yyy' }, parser.options)
381
- assert_equal(%w[foo zzz], parser.arguments.to_a)
381
+ assert_equal(%w[foo zzz], parser.gen_argument_list.to_a)
382
382
  end
383
383
 
384
384
  def test_parse_with_combined_optional_options
@@ -392,7 +392,7 @@ module Cri
392
392
  parser = Cri::Parser.new(input, opt_defns, [], false).run
393
393
 
394
394
  assert_equal({ aaa: true, bbb: 'xxx', ccc: 'yyy' }, parser.options)
395
- assert_equal(%w[foo zzz], parser.arguments.to_a)
395
+ assert_equal(%w[foo zzz], parser.gen_argument_list.to_a)
396
396
  end
397
397
 
398
398
  def test_parse_with_combined_optional_options_with_missing_value
@@ -406,7 +406,7 @@ module Cri
406
406
  parser = Cri::Parser.new(input, opt_defns, [], false).run
407
407
 
408
408
  assert_equal({ aaa: true, bbb: 'xxx', ccc: 'c default' }, parser.options)
409
- assert_equal(%w[foo], parser.arguments.to_a)
409
+ assert_equal(%w[foo], parser.gen_argument_list.to_a)
410
410
  end
411
411
 
412
412
  def test_parse_with_transform_proc
@@ -418,7 +418,7 @@ module Cri
418
418
  parser = Cri::Parser.new(input, opt_defns, [], false).run
419
419
 
420
420
  assert_equal({ port: 123 }, parser.options)
421
- assert_equal([], parser.arguments.to_a)
421
+ assert_equal([], parser.gen_argument_list.to_a)
422
422
  end
423
423
 
424
424
  def test_parse_with_transform_method
@@ -430,7 +430,7 @@ module Cri
430
430
  parser = Cri::Parser.new(input, opt_defns, [], false).run
431
431
 
432
432
  assert_equal({ port: 123 }, parser.options)
433
- assert_equal([], parser.arguments.to_a)
433
+ assert_equal([], parser.gen_argument_list.to_a)
434
434
  end
435
435
 
436
436
  def test_parse_with_transform_object
@@ -448,7 +448,7 @@ module Cri
448
448
  parser = Cri::Parser.new(input, opt_defns, [], false).run
449
449
 
450
450
  assert_equal({ port: 123 }, parser.options)
451
- assert_equal([], parser.arguments.to_a)
451
+ assert_equal([], parser.gen_argument_list.to_a)
452
452
  end
453
453
 
454
454
  def test_parse_with_transform_default
@@ -467,7 +467,7 @@ module Cri
467
467
  parser = Cri::Parser.new(input, opt_defns, [], false).run
468
468
 
469
469
  assert_equal({ port: 8080 }, parser.options)
470
- assert_equal([], parser.arguments.to_a)
470
+ assert_equal([], parser.gen_argument_list.to_a)
471
471
  end
472
472
 
473
473
  def test_parse_with_transform_exception
@@ -490,8 +490,8 @@ module Cri
490
490
 
491
491
  parser = Cri::Parser.new(input, [], param_defns, false).run
492
492
  assert_equal({}, parser.options)
493
- assert_equal('localhost', parser.arguments[0])
494
- assert_equal('localhost', parser.arguments[:host])
493
+ assert_equal('localhost', parser.gen_argument_list[0])
494
+ assert_equal('localhost', parser.gen_argument_list[:host])
495
495
  end
496
496
 
497
497
  def test_parse_with_param_defns_too_few_args
@@ -502,7 +502,7 @@ module Cri
502
502
 
503
503
  parser = Cri::Parser.new(input, [], param_defns, false).run
504
504
  exception = assert_raises(Cri::ArgumentList::ArgumentCountMismatchError) do
505
- parser.arguments
505
+ parser.gen_argument_list
506
506
  end
507
507
  assert_equal('incorrect number of arguments given: expected 1, but got 0', exception.message)
508
508
  end
@@ -515,7 +515,7 @@ module Cri
515
515
 
516
516
  parser = Cri::Parser.new(input, [], param_defns, false).run
517
517
  exception = assert_raises(Cri::ArgumentList::ArgumentCountMismatchError) do
518
- parser.arguments
518
+ parser.gen_argument_list
519
519
  end
520
520
  assert_equal('incorrect number of arguments given: expected 1, but got 2', exception.message)
521
521
  end
@@ -529,7 +529,7 @@ module Cri
529
529
  parser = Cri::Parser.new(input, [], param_defns, false).run
530
530
 
531
531
  exception = assert_raises(ArgumentError) do
532
- parser.arguments['oink']
532
+ parser.gen_argument_list['oink']
533
533
  end
534
534
  assert_equal('argument lists can be indexed using a Symbol or an Integer, but not a String', exception.message)
535
535
  end
@@ -543,10 +543,10 @@ module Cri
543
543
 
544
544
  parser = Cri::Parser.new(input, [], param_defns, false).run
545
545
  assert_equal({}, parser.options)
546
- assert_equal('localhost', parser.arguments[0])
547
- assert_equal('localhost', parser.arguments[:source])
548
- assert_equal('example.com', parser.arguments[1])
549
- assert_equal('example.com', parser.arguments[:target])
546
+ assert_equal('localhost', parser.gen_argument_list[0])
547
+ assert_equal('localhost', parser.gen_argument_list[:source])
548
+ assert_equal('example.com', parser.gen_argument_list[1])
549
+ assert_equal('example.com', parser.gen_argument_list[:target])
550
550
  end
551
551
 
552
552
  def make_opt_defn(hash)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cri
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.0
4
+ version: 2.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-26 00:00:00.000000000 Z
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored