cri 2.12.0 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0e63fb09fa1cd1a483f34f9f535adca0ce5f543e975163584ecf43a509e4195
4
- data.tar.gz: be17d3d95165270a73992dfa8a819704750d3b73b973a176f2d5c553a1934829
3
+ metadata.gz: 2aa633b78bf3bb39d2ddc9c5abc1ce94f27dd57bb1d130336acc58c1ae83ffcf
4
+ data.tar.gz: 2cc7102d387382bdfe15a0ccdb080d92c989f77716d217c0899a3ec688090886
5
5
  SHA512:
6
- metadata.gz: 55dc3514760d66bf2c4a7edf8e06ba37947dc278efaf339ac8de24afc5c6f8ecfa4d651557351433763800327907ec4c25859c335350a95adcb2decad9cd313f
7
- data.tar.gz: 3bda1e11790abbe1d2187961a1868ffcb1d255cf4d82a4f514e1a966bf72280fc34a0fe9f41303d7905024b092570220615120386940c7c429bad81ac5bd29ef
6
+ metadata.gz: 82e32293ba6c802449eeb1731742250bb5f5503cfdd1d05d8fd2e1b113ee3704e39a684cf9d87adf02c26becb95209bb34f32bc749e09017fb31b10dc5abde72
7
+ data.tar.gz: 5a51c230c68d3a4612eaae905605448997133418b12a703a1b154ac6c39a7e67e94305bbd680edfd6332b8fa806d9e3b94eb7d7c54529b0bc868f081f295d246
data/NEWS.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Cri News
2
2
  ========
3
3
 
4
+ ## 2.13.0
5
+
6
+ Features:
7
+
8
+ * Added support for explicitly specifying zero parameters using `#no_params` (#71)
9
+
4
10
  ## 2.12.0
5
11
 
6
12
  Features:
data/README.md CHANGED
@@ -257,6 +257,30 @@ end
257
257
  The command in this example has one parameter named `filename`. This means that
258
258
  the command takes a single argument, named `filename`.
259
259
 
260
+ If no parameters are specified, Cri performs no argument parsing or validation; any number of arguments is allowed. To explicitly specify that a command has no parameters, use `#no_params`:
261
+
262
+ ```ruby
263
+ name 'reset'
264
+ usage 'reset'
265
+ summary 'resets the site'
266
+ description '…'
267
+ no_params
268
+
269
+ run do |opts, args, cmd|
270
+ puts "Resetting…"
271
+ end
272
+ ```
273
+
274
+ ```
275
+ % my-tool reset x
276
+ reset: incorrect number of arguments given: expected 0, but got 1
277
+ % my-tool reset
278
+ Resetting…
279
+ %
280
+ ```
281
+
282
+ A future version of Cri will likely make `#no_params` the default behavior.
283
+
260
284
  (*Why the distinction between argument and parameter?* A parameter is a name, e.g. `filename`, while an argument is a value for a parameter, e.g. `kitten.jpg`.)
261
285
 
262
286
  ### The run block
@@ -17,8 +17,9 @@ module Cri
17
17
 
18
18
  include Enumerable
19
19
 
20
- def initialize(raw_arguments, param_defns)
20
+ def initialize(raw_arguments, explicitly_no_params, param_defns)
21
21
  @raw_arguments = raw_arguments
22
+ @explicitly_no_params = explicitly_no_params
22
23
  @param_defns = param_defns
23
24
 
24
25
  load
@@ -56,8 +57,8 @@ module Cri
56
57
  @arguments_array = @raw_arguments.reject { |a| a == '--' }.freeze
57
58
  @arguments_hash = {}
58
59
 
59
- if @param_defns.empty?
60
- # For now, don’t check arguments when no parameter definitions are given.
60
+ if !@explicitly_no_params && @param_defns.empty?
61
+ # No parameters defined; ignore
61
62
  return
62
63
  end
63
64
 
@@ -93,6 +93,10 @@ module Cri
93
93
  # @return [Array<Hash>] The list of parameter definitions
94
94
  attr_accessor :parameter_definitions
95
95
 
96
+ # @return [Boolean] Whether or not this command has parameters
97
+ attr_accessor :explicitly_no_params
98
+ alias explicitly_no_params? explicitly_no_params
99
+
96
100
  # @return [Proc] The block that should be executed when invoking this
97
101
  # command (ignored for commands with subcommands)
98
102
  attr_accessor :block
@@ -151,6 +155,7 @@ module Cri
151
155
  @commands = Set.new
152
156
  @option_definitions = Set.new
153
157
  @parameter_definitions = []
158
+ @explicitly_no_params = false
154
159
  @default_subcommand_name = nil
155
160
  end
156
161
 
@@ -319,6 +324,7 @@ module Cri
319
324
  opts_and_args,
320
325
  global_option_definitions,
321
326
  parameter_definitions,
327
+ explicitly_no_params?,
322
328
  )
323
329
  handle_errors_while { parser.run }
324
330
  local_opts = parser.options
@@ -378,6 +384,7 @@ module Cri
378
384
  opts_and_args,
379
385
  global_option_definitions,
380
386
  parameter_definitions,
387
+ explicitly_no_params?,
381
388
  )
382
389
  parser.delegate = delegate
383
390
  handle_errors_while { parser.run }
@@ -4,6 +4,31 @@ module Cri
4
4
  # The command DSL is a class that is used for building and modifying
5
5
  # commands.
6
6
  class CommandDSL
7
+ # Error that will be raised when specifying a parameter after the command is
8
+ # already declared as taken no params.
9
+ class AlreadySpecifiedAsNoParams < Cri::Error
10
+ def initialize(param, command)
11
+ @param = param
12
+ @command = command
13
+ end
14
+
15
+ def message
16
+ "Attempted to specify a parameter #{@param.inspect} to the command #{@command.name.inspect}, which is already specified as taking no params. Suggestion: remove the #no_params call."
17
+ end
18
+ end
19
+
20
+ # Error that will be raised when declaring the command as taking no
21
+ # parameters, when the command is already declared with parameters.
22
+ class AlreadySpecifiedWithParams < Cri::Error
23
+ def initialize(command)
24
+ @command = command
25
+ end
26
+
27
+ def message
28
+ "Attempted to declare the command #{@command.name.inspect} as taking no parameters, but some parameters are already declared for this command. Suggestion: remove the #no_params call."
29
+ end
30
+ end
31
+
7
32
  # @return [Cri::Command] The built command
8
33
  attr_reader :command
9
34
 
@@ -146,9 +171,21 @@ module Cri
146
171
  #
147
172
  # @param [Symbol] name The name of the parameter
148
173
  def param(name)
174
+ if @command.explicitly_no_params?
175
+ raise AlreadySpecifiedAsNoParams.new(name, @command)
176
+ end
177
+
149
178
  @command.parameter_definitions << Cri::ParamDefinition.new(name: name)
150
179
  end
151
180
 
181
+ def no_params
182
+ if @command.parameter_definitions.any?
183
+ raise AlreadySpecifiedWithParams.new(@command)
184
+ end
185
+
186
+ @command.explicitly_no_params = true
187
+ end
188
+
152
189
  # Adds a new option with a required argument to the command. If a block is
153
190
  # given, it will be executed when the option is successfully parsed.
154
191
  #
@@ -114,10 +114,11 @@ module Cri
114
114
  #
115
115
  # @param [Array<Cri::ParamDefinition>] param_defns An array of parameter
116
116
  # definitions
117
- def initialize(arguments_and_options, option_defns, param_defns)
117
+ def initialize(arguments_and_options, option_defns, param_defns, explicitly_no_params)
118
118
  @unprocessed_arguments_and_options = arguments_and_options.dup
119
119
  @option_defns = option_defns
120
120
  @param_defns = param_defns
121
+ @explicitly_no_params = explicitly_no_params
121
122
 
122
123
  @options = {}
123
124
  @raw_arguments = []
@@ -179,7 +180,7 @@ module Cri
179
180
  # @return [Cri::ArgumentList] The list of arguments that have already been
180
181
  # parsed, excluding the -- separator.
181
182
  def arguments
182
- ArgumentList.new(@raw_arguments, @param_defns)
183
+ ArgumentList.new(@raw_arguments, @explicitly_no_params, @param_defns)
183
184
  end
184
185
 
185
186
  private
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Cri
4
4
  # The current Cri version.
5
- VERSION = '2.12.0'
5
+ VERSION = '2.13.0'
6
6
  end
@@ -5,7 +5,7 @@ require 'helper'
5
5
  module Cri
6
6
  class ArgumentListTestCase < Cri::TestCase
7
7
  def test_empty
8
- args = Cri::ArgumentList.new([], [])
8
+ args = Cri::ArgumentList.new([], false, [])
9
9
 
10
10
  assert_equal([], args.to_a)
11
11
  assert(args.empty?)
@@ -15,7 +15,7 @@ module Cri
15
15
  end
16
16
 
17
17
  def test_no_param_defns
18
- args = Cri::ArgumentList.new(%w[a b c], [])
18
+ args = Cri::ArgumentList.new(%w[a b c], false, [])
19
19
 
20
20
  assert_equal(%w[a b c], args.to_a)
21
21
  refute(args.empty?)
@@ -28,13 +28,13 @@ module Cri
28
28
  end
29
29
 
30
30
  def test_enum
31
- args = Cri::ArgumentList.new(%w[a b c], [])
31
+ args = Cri::ArgumentList.new(%w[a b c], false, [])
32
32
 
33
33
  assert_equal(%w[A B C], args.map(&:upcase))
34
34
  end
35
35
 
36
36
  def test_no_method_error
37
- args = Cri::ArgumentList.new(%w[a b c], [])
37
+ args = Cri::ArgumentList.new(%w[a b c], false, [])
38
38
 
39
39
  refute args.respond_to?(:oink)
40
40
  assert_raises(NoMethodError, 'x') do
@@ -43,14 +43,14 @@ module Cri
43
43
  end
44
44
 
45
45
  def test_dash_dash
46
- args = Cri::ArgumentList.new(%w[a -- b -- c], [])
46
+ args = Cri::ArgumentList.new(%w[a -- b -- c], false, [])
47
47
 
48
48
  assert_equal(%w[a b c], args.to_a)
49
49
  end
50
50
 
51
51
  def test_one_param_defn_matched
52
52
  param_defns = [Cri::ParamDefinition.new(name: 'filename')]
53
- args = Cri::ArgumentList.new(%w[notbad.jpg], param_defns)
53
+ args = Cri::ArgumentList.new(%w[notbad.jpg], false, param_defns)
54
54
 
55
55
  assert_equal(['notbad.jpg'], args.to_a)
56
56
  assert_equal(1, args.size)
@@ -62,7 +62,7 @@ module Cri
62
62
  param_defns = [Cri::ParamDefinition.new(name: 'filename')]
63
63
 
64
64
  exception = assert_raises(Cri::ArgumentList::ArgumentCountMismatchError) do
65
- Cri::ArgumentList.new(%w[notbad.jpg verybad.jpg], param_defns)
65
+ Cri::ArgumentList.new(%w[notbad.jpg verybad.jpg], false, param_defns)
66
66
  end
67
67
  assert_equal('incorrect number of arguments given: expected 1, but got 2', exception.message)
68
68
  end
@@ -71,9 +71,24 @@ module Cri
71
71
  param_defns = [Cri::ParamDefinition.new(name: 'filename')]
72
72
 
73
73
  exception = assert_raises(Cri::ArgumentList::ArgumentCountMismatchError) do
74
- Cri::ArgumentList.new(%w[], param_defns)
74
+ Cri::ArgumentList.new(%w[], false, param_defns)
75
75
  end
76
76
  assert_equal('incorrect number of arguments given: expected 1, but got 0', exception.message)
77
77
  end
78
+
79
+ def test_zero_params_zero_args
80
+ args = Cri::ArgumentList.new(%w[], false, [])
81
+
82
+ assert_equal([], args.to_a)
83
+ assert args.empty?
84
+ assert_equal(0, args.size)
85
+ end
86
+
87
+ def test_zero_params_one_arg
88
+ exception = assert_raises(Cri::ArgumentList::ArgumentCountMismatchError) do
89
+ Cri::ArgumentList.new(%w[a], true, [])
90
+ end
91
+ assert_equal('incorrect number of arguments given: expected 0, but got 1', exception.message)
92
+ end
78
93
  end
79
94
  end
@@ -714,5 +714,47 @@ module Cri
714
714
  assert_equal [], lines(out)
715
715
  assert_equal ['publish: incorrect number of arguments given: expected 1, but got 0'], lines(err)
716
716
  end
717
+
718
+ def test_no_params_zero_args
719
+ dsl = Cri::CommandDSL.new
720
+ dsl.instance_eval do
721
+ name 'moo'
722
+ usage 'dunno whatever'
723
+ summary 'does stuff'
724
+ description 'This command does a lot of stuff.'
725
+ no_params
726
+
727
+ run do |_opts, args|
728
+ end
729
+ end
730
+ command = dsl.command
731
+
732
+ command.run([])
733
+ end
734
+
735
+ def test_no_params_one_arg
736
+ dsl = Cri::CommandDSL.new
737
+ dsl.instance_eval do
738
+ name 'moo'
739
+ usage 'dunno whatever'
740
+ summary 'does stuff'
741
+ description 'This command does a lot of stuff.'
742
+ no_params
743
+
744
+ run do |_opts, args|
745
+ end
746
+ end
747
+ command = dsl.command
748
+
749
+ out, err = capture_io_while do
750
+ err = assert_raises SystemExit do
751
+ command.run(['a'])
752
+ end
753
+ assert_equal 1, err.status
754
+ end
755
+
756
+ assert_equal [], lines(out)
757
+ assert_equal ['moo: incorrect number of arguments given: expected 0, but got 1'], lines(err)
758
+ end
717
759
  end
718
760
  end
@@ -268,5 +268,35 @@ module Cri
268
268
  assert_equal({ foo: 'a', bar: 'b', qux: 'c' }, $args_num)
269
269
  assert_equal({ foo: 'a', bar: 'b', qux: 'c' }, $args_sym)
270
270
  end
271
+
272
+ def test_no_params_with_one_param_specified
273
+ dsl = Cri::CommandDSL.new
274
+ err = assert_raises Cri::CommandDSL::AlreadySpecifiedWithParams do
275
+ dsl.instance_eval do
276
+ name 'moo'
277
+ usage 'dunno whatever'
278
+ summary 'does stuff'
279
+ description 'This command does a lot of stuff.'
280
+ param :oink
281
+ no_params
282
+ end
283
+ end
284
+ assert_equal('Attempted to declare the command "moo" as taking no parameters, but some parameters are already declared for this command. Suggestion: remove the #no_params call.', err.message)
285
+ end
286
+
287
+ def test_one_param_with_no_params_specified
288
+ dsl = Cri::CommandDSL.new
289
+ err = assert_raises Cri::CommandDSL::AlreadySpecifiedAsNoParams do
290
+ dsl.instance_eval do
291
+ name 'moo'
292
+ usage 'dunno whatever'
293
+ summary 'does stuff'
294
+ description 'This command does a lot of stuff.'
295
+ no_params
296
+ param :oink
297
+ end
298
+ end
299
+ assert_equal('Attempted to specify a parameter :oink to the command "moo", which is already specified as taking no params. Suggestion: remove the #no_params call.', err.message)
300
+ end
271
301
  end
272
302
  end
@@ -8,7 +8,7 @@ module Cri
8
8
  input = %w[foo bar baz]
9
9
  opt_defns = []
10
10
 
11
- parser = Cri::OptionParser.new(input, opt_defns, []).run
11
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
12
12
 
13
13
  assert_equal({}, parser.options)
14
14
  assert_equal(%w[foo bar baz], parser.arguments.to_a)
@@ -19,7 +19,7 @@ module Cri
19
19
  opt_defns = []
20
20
 
21
21
  assert_raises(Cri::OptionParser::IllegalOptionError) do
22
- Cri::OptionParser.new(input, opt_defns, []).run
22
+ Cri::OptionParser.new(input, opt_defns, [], false).run
23
23
  end
24
24
  end
25
25
 
@@ -29,7 +29,7 @@ module Cri
29
29
  { long: 'aaa', short: 'a', argument: :forbidden },
30
30
  ].map { |hash| make_opt_defn(hash) }
31
31
 
32
- parser = Cri::OptionParser.new(input, opt_defns, []).run
32
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
33
33
 
34
34
  assert(!parser.options[:aaa])
35
35
  end
@@ -40,7 +40,7 @@ module Cri
40
40
  { long: 'aaa', short: 'a', argument: :forbidden },
41
41
  ].map { |hash| make_opt_defn(hash) }
42
42
 
43
- parser = Cri::OptionParser.new(input, opt_defns, []).run
43
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
44
44
 
45
45
  assert(parser.options[:aaa])
46
46
  assert_equal(%w[foo bar], parser.arguments.to_a)
@@ -52,7 +52,7 @@ module Cri
52
52
  { long: 'aaa', short: 'a', argument: :required },
53
53
  ].map { |hash| make_opt_defn(hash) }
54
54
 
55
- parser = Cri::OptionParser.new(input, opt_defns, []).run
55
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
56
56
 
57
57
  assert_equal({ aaa: 'xxx' }, parser.options)
58
58
  assert_equal(%w[foo bar], parser.arguments.to_a)
@@ -64,7 +64,7 @@ module Cri
64
64
  { long: 'aaa', short: 'a', argument: :required },
65
65
  ].map { |hash| make_opt_defn(hash) }
66
66
 
67
- parser = Cri::OptionParser.new(input, opt_defns, []).run
67
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
68
68
 
69
69
  assert_equal({ aaa: 'xxx' }, parser.options)
70
70
  assert_equal(%w[foo bar], parser.arguments.to_a)
@@ -77,7 +77,7 @@ module Cri
77
77
  ].map { |hash| make_opt_defn(hash) }
78
78
 
79
79
  assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
80
- Cri::OptionParser.new(input, opt_defns, []).run
80
+ Cri::OptionParser.new(input, opt_defns, [], false).run
81
81
  end
82
82
  end
83
83
 
@@ -89,7 +89,7 @@ module Cri
89
89
  ].map { |hash| make_opt_defn(hash) }
90
90
 
91
91
  assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
92
- Cri::OptionParser.new(input, opt_defns, []).run
92
+ Cri::OptionParser.new(input, opt_defns, [], false).run
93
93
  end
94
94
  end
95
95
 
@@ -99,7 +99,7 @@ module Cri
99
99
  { long: 'aaa', short: 'a', argument: :optional },
100
100
  ].map { |hash| make_opt_defn(hash) }
101
101
 
102
- parser = Cri::OptionParser.new(input, opt_defns, []).run
102
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
103
103
 
104
104
  assert(parser.options[:aaa])
105
105
  assert_equal(['foo'], parser.arguments.to_a)
@@ -111,7 +111,7 @@ module Cri
111
111
  { long: 'aaa', short: 'a', argument: :optional },
112
112
  ].map { |hash| make_opt_defn(hash) }
113
113
 
114
- parser = Cri::OptionParser.new(input, opt_defns, []).run
114
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
115
115
 
116
116
  assert_equal({ aaa: 'xxx' }, parser.options)
117
117
  assert_equal(['foo'], parser.arguments.to_a)
@@ -125,7 +125,7 @@ module Cri
125
125
  { long: 'ccc', short: 'c', argument: :forbidden },
126
126
  ].map { |hash| make_opt_defn(hash) }
127
127
 
128
- parser = Cri::OptionParser.new(input, opt_defns, []).run
128
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
129
129
 
130
130
  assert(parser.options[:aaa])
131
131
  assert(parser.options[:bbb])
@@ -139,7 +139,7 @@ module Cri
139
139
  { long: 'aaa', short: 'a', argument: :forbidden },
140
140
  ].map { |hash| make_opt_defn(hash) }
141
141
 
142
- parser = Cri::OptionParser.new(input, opt_defns, []).run
142
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
143
143
 
144
144
  assert(parser.options[:aaa])
145
145
  assert_equal(%w[foo bar], parser.arguments.to_a)
@@ -152,7 +152,7 @@ module Cri
152
152
  ].map { |hash| make_opt_defn(hash) }
153
153
 
154
154
  assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
155
- Cri::OptionParser.new(input, opt_defns, []).run
155
+ Cri::OptionParser.new(input, opt_defns, [], false).run
156
156
  end
157
157
  end
158
158
 
@@ -164,7 +164,7 @@ module Cri
164
164
  { long: 'ccc', short: 'c', argument: :forbidden },
165
165
  ].map { |hash| make_opt_defn(hash) }
166
166
 
167
- parser = Cri::OptionParser.new(input, opt_defns, []).run
167
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
168
168
 
169
169
  assert(parser.options[:aaa])
170
170
  assert(parser.options[:bbb])
@@ -180,7 +180,7 @@ module Cri
180
180
  { long: 'ccc', short: 'c', argument: :forbidden },
181
181
  ].map { |hash| make_opt_defn(hash) }
182
182
 
183
- parser = Cri::OptionParser.new(input, opt_defns, []).run
183
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
184
184
 
185
185
  assert_equal('bar', parser.options[:aaa])
186
186
  assert(parser.options[:bbb])
@@ -196,7 +196,7 @@ module Cri
196
196
  ].map { |hash| make_opt_defn(hash) }
197
197
 
198
198
  assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
199
- Cri::OptionParser.new(input, opt_defns, []).run
199
+ Cri::OptionParser.new(input, opt_defns, [], false).run
200
200
  end
201
201
  end
202
202
 
@@ -206,7 +206,7 @@ module Cri
206
206
  { long: 'aaa', short: 'a', argument: :optional },
207
207
  ].map { |hash| make_opt_defn(hash) }
208
208
 
209
- parser = Cri::OptionParser.new(input, opt_defns, []).run
209
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
210
210
 
211
211
  assert(parser.options[:aaa])
212
212
  assert_equal(['foo'], parser.arguments.to_a)
@@ -218,7 +218,7 @@ module Cri
218
218
  { long: 'aaa', short: 'a', argument: :optional },
219
219
  ].map { |hash| make_opt_defn(hash) }
220
220
 
221
- parser = Cri::OptionParser.new(input, opt_defns, []).run
221
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
222
222
 
223
223
  assert_equal({ aaa: 'xxx' }, parser.options)
224
224
  assert_equal(['foo'], parser.arguments.to_a)
@@ -232,7 +232,7 @@ module Cri
232
232
  { long: 'ccc', short: 'c', argument: :forbidden },
233
233
  ].map { |hash| make_opt_defn(hash) }
234
234
 
235
- parser = Cri::OptionParser.new(input, opt_defns, []).run
235
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
236
236
 
237
237
  assert(parser.options[:aaa])
238
238
  assert(parser.options[:bbb])
@@ -244,7 +244,7 @@ module Cri
244
244
  input = %w[foo - bar]
245
245
  opt_defns = []
246
246
 
247
- parser = Cri::OptionParser.new(input, opt_defns, []).run
247
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
248
248
 
249
249
  assert_equal({}, parser.options)
250
250
  assert_equal(['foo', '-', 'bar'], parser.arguments.to_a)
@@ -254,7 +254,7 @@ module Cri
254
254
  input = %w[foo bar -- -x --yyy -abc]
255
255
  opt_defns = []
256
256
 
257
- parser = Cri::OptionParser.new(input, opt_defns, []).run
257
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
258
258
 
259
259
  assert_equal({}, parser.options)
260
260
  assert_equal(['foo', 'bar', '-x', '--yyy', '-abc'], parser.arguments.to_a)
@@ -267,7 +267,7 @@ module Cri
267
267
  ].map { |hash| make_opt_defn(hash) }
268
268
 
269
269
  assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
270
- Cri::OptionParser.new(input, opt_defns, []).run
270
+ Cri::OptionParser.new(input, opt_defns, [], false).run
271
271
  end
272
272
  end
273
273
 
@@ -278,7 +278,7 @@ module Cri
278
278
  { long: 'verbose', short: 'v', multiple: true },
279
279
  ].map { |hash| make_opt_defn(hash) }
280
280
 
281
- parser = Cri::OptionParser.new(input, opt_defns, []).run
281
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
282
282
 
283
283
  assert_equal(%w[test test2], parser.options[:long])
284
284
  assert_equal(3, parser.options[:verbose].size)
@@ -290,7 +290,7 @@ module Cri
290
290
  { long: 'animal', short: 'a', argument: :required, default: 'donkey' },
291
291
  ].map { |hash| make_opt_defn(hash) }
292
292
 
293
- parser = Cri::OptionParser.new(input, opt_defns, []).run
293
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
294
294
 
295
295
  assert_equal({ animal: 'donkey' }, parser.options)
296
296
  assert_equal(['foo'], parser.arguments.to_a)
@@ -303,7 +303,7 @@ module Cri
303
303
  ].map { |hash| make_opt_defn(hash) }
304
304
 
305
305
  assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
306
- Cri::OptionParser.new(input, opt_defns, []).run
306
+ Cri::OptionParser.new(input, opt_defns, [], false).run
307
307
  end
308
308
  end
309
309
 
@@ -313,7 +313,7 @@ module Cri
313
313
  { long: 'animal', short: 'a', argument: :required, default: 'donkey' },
314
314
  ].map { |hash| make_opt_defn(hash) }
315
315
 
316
- parser = Cri::OptionParser.new(input, opt_defns, []).run
316
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
317
317
 
318
318
  assert_equal({ animal: 'giraffe' }, parser.options)
319
319
  assert_equal(['foo'], parser.arguments.to_a)
@@ -325,7 +325,7 @@ module Cri
325
325
  { long: 'animal', short: 'a', argument: :optional, default: 'donkey' },
326
326
  ].map { |hash| make_opt_defn(hash) }
327
327
 
328
- parser = Cri::OptionParser.new(input, opt_defns, []).run
328
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
329
329
 
330
330
  assert_equal({ animal: 'donkey' }, parser.options)
331
331
  assert_equal(['foo'], parser.arguments.to_a)
@@ -337,7 +337,7 @@ module Cri
337
337
  { long: 'animal', short: 'a', argument: :optional, default: 'donkey' },
338
338
  ].map { |hash| make_opt_defn(hash) }
339
339
 
340
- parser = Cri::OptionParser.new(input, opt_defns, []).run
340
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
341
341
 
342
342
  assert_equal({ animal: 'donkey' }, parser.options)
343
343
  assert_equal(['foo'], parser.arguments.to_a)
@@ -349,7 +349,7 @@ module Cri
349
349
  { long: 'animal', short: 'a', argument: :optional, default: 'donkey' },
350
350
  ].map { |hash| make_opt_defn(hash) }
351
351
 
352
- parser = Cri::OptionParser.new(input, opt_defns, []).run
352
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
353
353
 
354
354
  assert_equal({ animal: 'giraffe' }, parser.options)
355
355
  assert_equal(['foo'], parser.arguments.to_a)
@@ -361,7 +361,7 @@ module Cri
361
361
  { long: 'animal', short: 'a', argument: :optional, default: 'donkey' },
362
362
  ].map { |hash| make_opt_defn(hash) }
363
363
 
364
- parser = Cri::OptionParser.new(input, opt_defns, []).run
364
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
365
365
 
366
366
  assert_equal({ animal: 'gi' }, parser.options)
367
367
  assert_equal(%w[foo raffe], parser.arguments.to_a)
@@ -375,7 +375,7 @@ module Cri
375
375
  { long: 'ccc', short: 'c', argument: :required },
376
376
  ].map { |hash| make_opt_defn(hash) }
377
377
 
378
- parser = Cri::OptionParser.new(input, opt_defns, []).run
378
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
379
379
 
380
380
  assert_equal({ aaa: true, bbb: 'xxx', ccc: 'yyy' }, parser.options)
381
381
  assert_equal(%w[foo zzz], parser.arguments.to_a)
@@ -389,7 +389,7 @@ module Cri
389
389
  { long: 'ccc', short: 'c', argument: :required },
390
390
  ].map { |hash| make_opt_defn(hash) }
391
391
 
392
- parser = Cri::OptionParser.new(input, opt_defns, []).run
392
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
393
393
 
394
394
  assert_equal({ aaa: true, bbb: 'xxx', ccc: 'yyy' }, parser.options)
395
395
  assert_equal(%w[foo zzz], parser.arguments.to_a)
@@ -403,7 +403,7 @@ module Cri
403
403
  { long: 'ccc', short: 'c', argument: :optional, default: 'c default' },
404
404
  ].map { |hash| make_opt_defn(hash) }
405
405
 
406
- parser = Cri::OptionParser.new(input, opt_defns, []).run
406
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
407
407
 
408
408
  assert_equal({ aaa: true, bbb: 'xxx', ccc: 'c default' }, parser.options)
409
409
  assert_equal(%w[foo], parser.arguments.to_a)
@@ -415,7 +415,7 @@ module Cri
415
415
  { long: 'port', short: 'p', argument: :required, transform: ->(x) { Integer(x) } },
416
416
  ].map { |hash| make_opt_defn(hash) }
417
417
 
418
- parser = Cri::OptionParser.new(input, opt_defns, []).run
418
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
419
419
 
420
420
  assert_equal({ port: 123 }, parser.options)
421
421
  assert_equal([], parser.arguments.to_a)
@@ -427,7 +427,7 @@ module Cri
427
427
  { long: 'port', short: 'p', argument: :required, transform: method(:Integer) },
428
428
  ].map { |hash| make_opt_defn(hash) }
429
429
 
430
- parser = Cri::OptionParser.new(input, opt_defns, []).run
430
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
431
431
 
432
432
  assert_equal({ port: 123 }, parser.options)
433
433
  assert_equal([], parser.arguments.to_a)
@@ -445,7 +445,7 @@ module Cri
445
445
  { long: 'port', short: 'p', argument: :required, transform: port },
446
446
  ].map { |hash| make_opt_defn(hash) }
447
447
 
448
- parser = Cri::OptionParser.new(input, opt_defns, []).run
448
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
449
449
 
450
450
  assert_equal({ port: 123 }, parser.options)
451
451
  assert_equal([], parser.arguments.to_a)
@@ -464,7 +464,7 @@ module Cri
464
464
  { long: 'port', short: 'p', argument: :required, default: 8080, transform: port },
465
465
  ].map { |hash| make_opt_defn(hash) }
466
466
 
467
- parser = Cri::OptionParser.new(input, opt_defns, []).run
467
+ parser = Cri::OptionParser.new(input, opt_defns, [], false).run
468
468
 
469
469
  assert_equal({ port: 8080 }, parser.options)
470
470
  assert_equal([], parser.arguments.to_a)
@@ -477,7 +477,7 @@ module Cri
477
477
  ].map { |hash| make_opt_defn(hash) }
478
478
 
479
479
  exception = assert_raises(Cri::OptionParser::IllegalOptionValueError) do
480
- Cri::OptionParser.new(input, opt_defns, []).run
480
+ Cri::OptionParser.new(input, opt_defns, [], false).run
481
481
  end
482
482
  assert_equal('invalid value "one_hundred_and_twenty_three" for --port option', exception.message)
483
483
  end
@@ -488,7 +488,7 @@ module Cri
488
488
  { name: 'host' },
489
489
  ].map { |hash| Cri::ParamDefinition.new(hash) }
490
490
 
491
- parser = Cri::OptionParser.new(input, [], param_defns).run
491
+ parser = Cri::OptionParser.new(input, [], param_defns, false).run
492
492
  assert_equal({}, parser.options)
493
493
  assert_equal('localhost', parser.arguments[0])
494
494
  assert_equal('localhost', parser.arguments[:host])
@@ -500,7 +500,7 @@ module Cri
500
500
  { name: 'host' },
501
501
  ].map { |hash| Cri::ParamDefinition.new(hash) }
502
502
 
503
- parser = Cri::OptionParser.new(input, [], param_defns).run
503
+ parser = Cri::OptionParser.new(input, [], param_defns, false).run
504
504
  exception = assert_raises(Cri::ArgumentList::ArgumentCountMismatchError) do
505
505
  parser.arguments
506
506
  end
@@ -513,7 +513,7 @@ module Cri
513
513
  { name: 'host' },
514
514
  ].map { |hash| Cri::ParamDefinition.new(hash) }
515
515
 
516
- parser = Cri::OptionParser.new(input, [], param_defns).run
516
+ parser = Cri::OptionParser.new(input, [], param_defns, false).run
517
517
  exception = assert_raises(Cri::ArgumentList::ArgumentCountMismatchError) do
518
518
  parser.arguments
519
519
  end
@@ -526,7 +526,7 @@ module Cri
526
526
  { name: 'host' },
527
527
  ].map { |hash| Cri::ParamDefinition.new(hash) }
528
528
 
529
- parser = Cri::OptionParser.new(input, [], param_defns).run
529
+ parser = Cri::OptionParser.new(input, [], param_defns, false).run
530
530
 
531
531
  exception = assert_raises(ArgumentError) do
532
532
  parser.arguments['oink']
@@ -541,7 +541,7 @@ module Cri
541
541
  { name: 'target' },
542
542
  ].map { |hash| Cri::ParamDefinition.new(hash) }
543
543
 
544
- parser = Cri::OptionParser.new(input, [], param_defns).run
544
+ parser = Cri::OptionParser.new(input, [], param_defns, false).run
545
545
  assert_equal({}, parser.options)
546
546
  assert_equal('localhost', parser.arguments[0])
547
547
  assert_equal('localhost', parser.arguments[:source])
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.12.0
4
+ version: 2.13.0
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-12 00:00:00.000000000 Z
11
+ date: 2018-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored
@@ -50,7 +50,6 @@ extra_rdoc_files:
50
50
  files:
51
51
  - CODE_OF_CONDUCT.md
52
52
  - Gemfile
53
- - Gemfile.lock
54
53
  - LICENSE
55
54
  - NEWS.md
56
55
  - README.md
@@ -1,64 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- cri (2.12.0)
5
- colored (~> 1.2)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- asciidoctor (1.5.7.1)
11
- ast (2.4.0)
12
- colored (1.2)
13
- coveralls (0.8.22)
14
- json (>= 1.8, < 3)
15
- simplecov (~> 0.16.1)
16
- term-ansicolor (~> 1.3)
17
- thor (~> 0.19.4)
18
- tins (~> 1.6)
19
- docile (1.3.1)
20
- jaro_winkler (1.5.1)
21
- json (2.1.0)
22
- minitest (5.11.3)
23
- parallel (1.12.1)
24
- parser (2.5.1.2)
25
- ast (~> 2.4.0)
26
- powerpack (0.1.2)
27
- rainbow (3.0.0)
28
- rake (12.3.1)
29
- rubocop (0.58.2)
30
- jaro_winkler (~> 1.5.1)
31
- parallel (~> 1.10)
32
- parser (>= 2.5, != 2.5.1.1)
33
- powerpack (~> 0.1)
34
- rainbow (>= 2.2.2, < 4.0)
35
- ruby-progressbar (~> 1.7)
36
- unicode-display_width (~> 1.0, >= 1.0.1)
37
- ruby-progressbar (1.10.0)
38
- simplecov (0.16.1)
39
- docile (~> 1.1)
40
- json (>= 1.8, < 3)
41
- simplecov-html (~> 0.10.0)
42
- simplecov-html (0.10.2)
43
- term-ansicolor (1.6.0)
44
- tins (~> 1.0)
45
- thor (0.19.4)
46
- tins (1.16.3)
47
- unicode-display_width (1.4.0)
48
- yard (0.9.16)
49
-
50
- PLATFORMS
51
- ruby
52
-
53
- DEPENDENCIES
54
- asciidoctor
55
- bundler (~> 1.6)
56
- coveralls
57
- cri!
58
- minitest
59
- rake
60
- rubocop
61
- yard
62
-
63
- BUNDLED WITH
64
- 1.16.3