gli 2.12.0 → 2.12.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
  SHA1:
3
- metadata.gz: e3051959ac78b44c2e6c7d8be0701aebcb375700
4
- data.tar.gz: 5ef912011fd093bf0afc55b7642d7eaa85f84d4f
3
+ metadata.gz: 740fe97d64c94c7962a740ec92d11c677ccfde7f
4
+ data.tar.gz: d4d3801f9a9dab26bff27b0cb49754ae383040c1
5
5
  SHA512:
6
- metadata.gz: 464e43336b07485f3824dbacdeb8fbe5f5ebce4bd41af6f2dbc06406560b6c1b2d4b6ea1dc413de364ddba2d0d37576e121dcc0bebf962fef2f4d1c57221f4d8
7
- data.tar.gz: 03296c0c993306c51903bc142cd8478348cd616aa735b4799c27dfb7b53bd048e115b32434644c3462f63742bd4b46730cb227936baafbef7ceed4d0bf9ad62b
6
+ metadata.gz: ea0caedb0cc36eca2d59f29281bb8720615815cc10eadfdfa9b8537510a5432636ad5ef31418e8eead58d5ed578e88ae792462f3ce81850bc968c5ca527a5f14
7
+ data.tar.gz: 89c5d72a1bd8576518b72e70b12fc12363a14aa0c6bd539495628c5af6efbb1e81596463cab37f8640f9c0d38864a4cb8b6d1a10c56995466d5d67f44feb2995
@@ -1 +1 @@
1
- 2.0.0
1
+ ruby-2.1
@@ -6,7 +6,7 @@ rvm:
6
6
  - 1.9.3
7
7
  - 1.8.7
8
8
  - 2.0.0
9
- - 2.1.0
9
+ - 2.1
10
10
  branches:
11
11
  only:
12
12
  - 'gli-2'
@@ -291,9 +291,13 @@ module GLI
291
291
  @subcommand_option_handling_strategy = handling_strategy
292
292
  end
293
293
 
294
- # How to handle argument validation. Either +:loose+ (which does not validate argument at all)
295
- # or +:strict+ (which will validate the number of arguments).
296
- # If nothing is specified, +:loose+ is assumed
294
+ # How to handle argument validation.
295
+ #
296
+ # handling_strategy:: One of:
297
+ # +:loose+:: no argument validation. Use of `arg` or `arg_name` is for documentation purposes only. (Default)
298
+ # +:strict+:: arguments are validated according to their specification. +action+ blocks may assume
299
+ # the value of `arguments` matches the specification provided in `arg`. Note that to use
300
+ # this strategy, you must also be sure that +subcommand_option_handling+ is set.
297
301
  def arguments(handling_strategy)
298
302
  @argument_handling_strategy = handling_strategy
299
303
  end
@@ -284,7 +284,7 @@ program_desc 'Describe your application here'
284
284
 
285
285
  version #{project_name_as_module_name(project_name)}::VERSION
286
286
 
287
- # Use argument validation
287
+ subcommand_option_handling :normal
288
288
  arguments :strict
289
289
 
290
290
  desc 'Describe some switch here'
@@ -7,6 +7,9 @@ module GLI
7
7
  @accepts = accepts
8
8
  @subcommand_option_handling_strategy = subcommand_option_handling_strategy
9
9
  @argument_handling_strategy = argument_handling_strategy
10
+ if @argument_handling_strategy == :strict && @subcommand_option_handling_strategy != :normal
11
+ raise ArgumentError, "To use strict argument handling, you must enable normal subcommand_option_handling, e.g. subcommand_option_handling :normal"
12
+ end
10
13
  end
11
14
 
12
15
  # Given the command-line argument array, returns an OptionParsingResult
@@ -1,5 +1,5 @@
1
1
  module GLI
2
2
  unless const_defined? :VERSION
3
- VERSION = '2.12.0'
3
+ VERSION = '2.12.1'
4
4
  end
5
5
  end
@@ -83,41 +83,62 @@ class TC_testSubCommandParsing < Clean::Test::TestCase
83
83
  When :run_app_with_X_arguments, 0
84
84
  Then {
85
85
  with_clue {
86
- assert_equal 0, @results[:nbargs]
86
+ assert_equal 0, @results[:number_of_args_give_to_action]
87
87
  assert_equal 0, @exit_code
88
88
  }
89
89
  }
90
90
  end
91
91
 
92
+ test_that "in strict mode, subcommand_option_handling must be normal" do
93
+ Given :app_with_arguments, 1, 1, false, :strict, :legacy
94
+ When :run_app_with_X_arguments, 1
95
+ Then {
96
+ with_clue {
97
+ assert_nil @results[:number_of_args_give_to_action]
98
+ assert_equal 1, @exit_code
99
+ assert @fake_stderr.contained?(/you must enable normal subcommand_option_handling/)
100
+ }
101
+ }
102
+ end
103
+
92
104
  ix = -1
93
105
  [
94
- [1, 1, false, 0, :not_enough], [1, 1, false, 1, :success],
95
- [1, 1, false, 2, :success], [1, 1, false, 3, :too_many],
96
- [1, 1, true, 0, :not_enough], [1, 1, true, 1, :success],
97
- [1, 1, true, 2, :success], [1, 1, true, 3, :success],
98
- [1, 1, true, 30, :success], [0, 0, false, 0, :success],
99
- [0, 0, false, 1, :too_many], [0, 1, false, 1, :success],
100
- [0, 1, false, 0, :success], [1, 0, false, 1, :success],
101
- [1, 0, false, 0, :not_enough], [0, 0, true, 0, :success],
102
- [0, 0, true, 10, :success]
103
- ].each do |nb_required, nb_optional, has_multiple, nb_generated, status|
106
+ [1 , 1 , false , 0 , :not_enough] ,
107
+ [1 , 1 , false , 1 , :success] ,
108
+ [1 , 1 , false , 2 , :success] ,
109
+ [1 , 1 , false , 3 , :too_many] ,
110
+ [1 , 1 , true , 0 , :not_enough] ,
111
+ [1 , 1 , true , 1 , :success] ,
112
+ [1 , 1 , true , 2 , :success] ,
113
+ [1 , 1 , true , 3 , :success] ,
114
+ [1 , 1 , true , 30 , :success] ,
115
+ [0 , 0 , false , 0 , :success] ,
116
+ [0 , 0 , false , 1 , :too_many] ,
117
+ [0 , 1 , false , 1 , :success] ,
118
+ [0 , 1 , false , 0 , :success] ,
119
+ [1 , 0 , false , 1 , :success] ,
120
+ [1 , 0 , false , 0 , :not_enough] ,
121
+ [0 , 0 , true , 0 , :success] ,
122
+ [0 , 0 , true , 10 , :success]
123
+
124
+ ].each do |number_required, number_optional, has_multiple, number_generated, status|
104
125
  ix = ix + 1
105
- test_that "in strict mode, number of arguments is validated -- #{ix}" do
106
- Given :app_with_arguments, nb_required, nb_optional, has_multiple, :strict
107
- When :run_app_with_X_arguments, nb_generated
126
+ test_that "in strict mode, with #{number_required} required, #{number_optional} optional, #{ has_multiple ? 'multiple' : 'not multiple' } and #{number_generated} generated, it should be #{status}" do
127
+ Given :app_with_arguments, number_required, number_optional, has_multiple, :strict
128
+ When :run_app_with_X_arguments, number_generated
108
129
  Then {
109
130
  with_clue {
110
131
  if status == :success then
111
- assert_equal nb_generated, @results[:nbargs]
132
+ assert_equal number_generated, @results[:number_of_args_give_to_action]
112
133
  assert_equal 0, @exit_code
113
134
  assert !@fake_stderr.contained?(/Not enough arguments for command/)
114
135
  assert !@fake_stderr.contained?(/Too many arguments for command/)
115
136
  elsif status == :not_enough then
116
- assert_equal nil, @results[:nbargs]
137
+ assert_equal nil, @results[:number_of_args_give_to_action]
117
138
  assert_equal 64, @exit_code
118
139
  assert @fake_stderr.contained?(/Not enough arguments for command/)
119
140
  elsif status == :too_many then
120
- assert_equal nil, @results[:nbargs]
141
+ assert_equal nil, @results[:number_of_args_give_to_action]
121
142
  assert_equal 64, @exit_code
122
143
  assert @fake_stderr.contained?(/Too many arguments for command/)
123
144
  else
@@ -176,24 +197,24 @@ private
176
197
  end
177
198
  end
178
199
 
179
- def app_with_arguments(nb_required_arguments, nb_optional_arguments, has_argument_multiple, arguments_handling_strategy = :loose)
200
+ def app_with_arguments(number_required_arguments, number_optional_arguments, has_argument_multiple, arguments_handling_strategy = :loose, subcommand_option_handling_strategy = :normal)
180
201
  @app.arguments arguments_handling_strategy
181
- @app.subcommand_option_handling :normal
202
+ @app.subcommand_option_handling subcommand_option_handling_strategy
182
203
 
183
- nb_required_arguments.times { |i| @app.arg("needed#{i}") }
184
- nb_optional_arguments.times { |i| @app.arg("optional#{i}", :optional) }
204
+ number_required_arguments.times { |i| @app.arg("needed#{i}") }
205
+ number_optional_arguments.times { |i| @app.arg("optional#{i}", :optional) }
185
206
  @app.arg :multiple, [:multiple, :optional] if has_argument_multiple
186
207
 
187
208
  @app.command :cmd do |c|
188
209
  c.action do |g,o,a|
189
210
  @results = {
190
- :nbargs => a.size
211
+ :number_of_args_give_to_action => a.size
191
212
  }
192
213
  end
193
214
  end
194
215
  end
195
216
 
196
- def run_app_with_X_arguments(nb_arguments)
197
- @exit_code = @app.run [].tap{|args| args << "cmd"; nb_arguments.times {|i| args << "arg#{i}"}}
217
+ def run_app_with_X_arguments(number_arguments)
218
+ @exit_code = @app.run [].tap{|args| args << "cmd"; number_arguments.times {|i| args << "arg#{i}"}}
198
219
  end
199
220
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.0
4
+ version: 2.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Copeland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-29 00:00:00.000000000 Z
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake