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 +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -1
- data/lib/gli/app.rb +7 -3
- data/lib/gli/commands/scaffold.rb +1 -1
- data/lib/gli/gli_option_parser.rb +3 -0
- data/lib/gli/version.rb +1 -1
- data/test/tc_subcommand_parsing.rb +45 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 740fe97d64c94c7962a740ec92d11c677ccfde7f
|
4
|
+
data.tar.gz: d4d3801f9a9dab26bff27b0cb49754ae383040c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea0caedb0cc36eca2d59f29281bb8720615815cc10eadfdfa9b8537510a5432636ad5ef31418e8eead58d5ed578e88ae792462f3ce81850bc968c5ca527a5f14
|
7
|
+
data.tar.gz: 89c5d72a1bd8576518b72e70b12fc12363a14aa0c6bd539495628c5af6efbb1e81596463cab37f8640f9c0d38864a4cb8b6d1a10c56995466d5d67f44feb2995
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
ruby-2.1
|
data/.travis.yml
CHANGED
data/lib/gli/app.rb
CHANGED
@@ -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.
|
295
|
-
#
|
296
|
-
#
|
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
|
@@ -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
|
data/lib/gli/version.rb
CHANGED
@@ -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[:
|
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]
|
95
|
-
[1, 1, false
|
96
|
-
[1, 1
|
97
|
-
[1, 1
|
98
|
-
[1, 1, true,
|
99
|
-
[
|
100
|
-
[
|
101
|
-
[1
|
102
|
-
[
|
103
|
-
|
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,
|
106
|
-
Given :app_with_arguments,
|
107
|
-
When :run_app_with_X_arguments,
|
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
|
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[:
|
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[:
|
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(
|
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
|
202
|
+
@app.subcommand_option_handling subcommand_option_handling_strategy
|
182
203
|
|
183
|
-
|
184
|
-
|
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
|
-
:
|
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(
|
197
|
-
@exit_code = @app.run [].tap{|args| args << "cmd";
|
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.
|
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-
|
11
|
+
date: 2014-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|