gli 2.18.0 → 2.18.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.tool-versions +1 -0
- data/lib/gli/gli_option_parser.rb +9 -9
- data/lib/gli/version.rb +1 -1
- data/test/tc_subcommand_parsing.rb +60 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5687d6e6cfea1165eba186bdee08325eaa1588d21e7d0ef5b0aa283a6fcb79ab
|
4
|
+
data.tar.gz: 3f157eef5e5e3d8fe7137adb71ec1885e723705574a87229bbf34fd2b46ecfb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 071cd902d777a38f668edbbe0d71814d56d727b9238b0e40e6601fe35e50f29bf7f9ab382a073a21dc17801d4351ea1379f2d0467148bbbd885e5ef5a5dd3fb1
|
7
|
+
data.tar.gz: 45b16d82f3410716380cda524b631fdf38b44ce702c7a2f92ded226a42932eeff274b8afbf9e735a40bc515add4328ad940f22b82e98c61634f51b8cf73de0fd
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.6.3
|
@@ -29,7 +29,7 @@ module GLI
|
|
29
29
|
OptionParsingResult.new.tap { |parsing_result|
|
30
30
|
parsing_result.arguments = args
|
31
31
|
parsing_result = @global_option_parser.parse!(parsing_result)
|
32
|
-
option_parser_class.new(@accepts).parse!(parsing_result, options[:argument_handling_strategy])
|
32
|
+
option_parser_class.new(@accepts).parse!(parsing_result, options[:argument_handling_strategy], options[:autocomplete])
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
@@ -117,7 +117,7 @@ module GLI
|
|
117
117
|
}
|
118
118
|
end
|
119
119
|
|
120
|
-
def parse!(parsing_result,argument_handling_strategy)
|
120
|
+
def parse!(parsing_result,argument_handling_strategy,autocomplete)
|
121
121
|
parsed_command_options = {}
|
122
122
|
command = parsing_result.command
|
123
123
|
arguments = nil
|
@@ -131,7 +131,7 @@ module GLI
|
|
131
131
|
arguments = option_block_parser.parse!(arguments)
|
132
132
|
|
133
133
|
parsed_command_options[command] = option_parser_factory.options_hash_with_defaults_set!
|
134
|
-
command_finder = CommandFinder.new(command.commands, :default_command => command.get_default_command)
|
134
|
+
command_finder = CommandFinder.new(command.commands, :default_command => command.get_default_command, :autocomplete => autocomplete)
|
135
135
|
next_command_name = arguments.shift
|
136
136
|
|
137
137
|
verify_required_options!(command.flags, command, parsed_command_options[command])
|
@@ -178,7 +178,7 @@ module GLI
|
|
178
178
|
end
|
179
179
|
|
180
180
|
class LegacyCommandOptionParser < NormalCommandOptionParser
|
181
|
-
def parse!(parsing_result,argument_handling_strategy)
|
181
|
+
def parse!(parsing_result,argument_handling_strategy,autocomplete)
|
182
182
|
command = parsing_result.command
|
183
183
|
option_parser_factory = OptionParserFactory.for_command(command,@accepts)
|
184
184
|
option_block_parser = LegacyCommandOptionBlockParser.new(option_parser_factory, self.error_handler)
|
@@ -187,7 +187,7 @@ module GLI
|
|
187
187
|
parsing_result.arguments = option_block_parser.parse!(parsing_result.arguments)
|
188
188
|
parsing_result.command_options = option_parser_factory.options_hash_with_defaults_set!
|
189
189
|
|
190
|
-
subcommand,args = find_subcommand(command,parsing_result.arguments)
|
190
|
+
subcommand,args = find_subcommand(command,parsing_result.arguments,autocomplete)
|
191
191
|
parsing_result.command = subcommand
|
192
192
|
parsing_result.arguments = args
|
193
193
|
verify_required_options!(command.flags, parsing_result.command, parsing_result.command_options)
|
@@ -195,7 +195,7 @@ module GLI
|
|
195
195
|
|
196
196
|
private
|
197
197
|
|
198
|
-
def find_subcommand(command,arguments)
|
198
|
+
def find_subcommand(command,arguments,autocomplete)
|
199
199
|
arguments = Array(arguments)
|
200
200
|
command_name = if arguments.empty?
|
201
201
|
nil
|
@@ -204,15 +204,15 @@ module GLI
|
|
204
204
|
end
|
205
205
|
|
206
206
|
default_command = command.get_default_command
|
207
|
-
finder = CommandFinder.new(command.commands, :default_command => default_command.to_s)
|
207
|
+
finder = CommandFinder.new(command.commands, :default_command => default_command.to_s, :autocomplete => autocomplete)
|
208
208
|
|
209
209
|
begin
|
210
210
|
results = [finder.find_command(command_name),arguments[1..-1]]
|
211
|
-
find_subcommand(results[0],results[1])
|
211
|
+
find_subcommand(results[0],results[1],autocomplete)
|
212
212
|
rescue UnknownCommand, AmbiguousCommand
|
213
213
|
begin
|
214
214
|
results = [finder.find_command(default_command.to_s),arguments]
|
215
|
-
find_subcommand(results[0],results[1])
|
215
|
+
find_subcommand(results[0],results[1],autocomplete)
|
216
216
|
rescue UnknownCommand, AmbiguousCommand
|
217
217
|
[command,arguments]
|
218
218
|
end
|
data/lib/gli/version.rb
CHANGED
@@ -78,6 +78,31 @@ class TC_testSubCommandParsing < Clean::Test::TestCase
|
|
78
78
|
}
|
79
79
|
end
|
80
80
|
|
81
|
+
test_that "in loose mode with autocomplete false, it doesn't autocorrect a sub command" do
|
82
|
+
Given :app_with_subcommand_storing_results, :normal, false, :loose
|
83
|
+
When {
|
84
|
+
@app.run(%w(-f global command -f flag -s subcomm -f subflag))
|
85
|
+
}
|
86
|
+
Then {
|
87
|
+
with_clue {
|
88
|
+
assert_equal "command",@results[:command_name]
|
89
|
+
}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
test_that "in strict mode with autocomplete false, it doesn't autocorrect a sub command" do
|
94
|
+
Given :app_with_subcommand_storing_results, :normal, false, :strict
|
95
|
+
When {
|
96
|
+
@app.run(%w(-f global command -f flag -s subcomm -f subflag))
|
97
|
+
}
|
98
|
+
Then {
|
99
|
+
with_clue {
|
100
|
+
assert_equal nil,@results[:command_name]
|
101
|
+
assert @fake_stderr.contained?(/error: Too many arguments for command/)
|
102
|
+
}
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
81
106
|
test_that "in loose mode, argument validation is ignored" do
|
82
107
|
Given :app_with_arguments, 1, 1, false, :loose
|
83
108
|
When :run_app_with_X_arguments, 0
|
@@ -160,6 +185,41 @@ private
|
|
160
185
|
raise
|
161
186
|
end
|
162
187
|
|
188
|
+
def app_with_subcommand_storing_results(subcommand_option_handling_strategy, autocomplete, arguments_handling_strategy)
|
189
|
+
@app.subcommand_option_handling subcommand_option_handling_strategy
|
190
|
+
@app.autocomplete_commands autocomplete
|
191
|
+
@app.arguments arguments_handling_strategy
|
192
|
+
@app.flag ['f','flag']
|
193
|
+
@app.switch ['s','switch']
|
194
|
+
|
195
|
+
@app.command "command" do |c|
|
196
|
+
c.flag ['f','flag']
|
197
|
+
c.switch ['s','switch']
|
198
|
+
c.action do |global,options,args|
|
199
|
+
@results = {
|
200
|
+
:command_name => "command",
|
201
|
+
:global_options => global,
|
202
|
+
:command_options => options,
|
203
|
+
:args => args
|
204
|
+
}
|
205
|
+
end
|
206
|
+
|
207
|
+
c.command "subcommand" do |subcommand|
|
208
|
+
subcommand.flag ['f','flag']
|
209
|
+
subcommand.flag ['foo']
|
210
|
+
subcommand.switch ['s','switch']
|
211
|
+
subcommand.action do |global,options,args|
|
212
|
+
@results = {
|
213
|
+
:command_name => "subcommand",
|
214
|
+
:global_options => global,
|
215
|
+
:command_options => options,
|
216
|
+
:args => args
|
217
|
+
}
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
163
223
|
def app_with_subcommands_storing_results(subcommand_option_handling_strategy = :legacy)
|
164
224
|
@app.subcommand_option_handling subcommand_option_handling_strategy
|
165
225
|
@app.flag ['f','flag']
|
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.18.
|
4
|
+
version: 2.18.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:
|
11
|
+
date: 2019-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- ".gitignore"
|
157
157
|
- ".ruby-gemset"
|
158
158
|
- ".ruby-version"
|
159
|
+
- ".tool-versions"
|
159
160
|
- ".travis.yml"
|
160
161
|
- CONTRIBUTING.md
|
161
162
|
- Gemfile
|
@@ -283,8 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
283
284
|
- !ruby/object:Gem::Version
|
284
285
|
version: '0'
|
285
286
|
requirements: []
|
286
|
-
|
287
|
-
rubygems_version: 2.7.6
|
287
|
+
rubygems_version: 3.0.3
|
288
288
|
signing_key:
|
289
289
|
specification_version: 4
|
290
290
|
summary: Build command-suite CLI apps that are awesome.
|