commander 4.5.1 → 4.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +6 -0
- data/lib/commander/help_formatters/terminal.rb +5 -1
- data/lib/commander/help_formatters/terminal_compact.rb +5 -1
- data/lib/commander/runner.rb +21 -15
- data/lib/commander/version.rb +1 -1
- data/spec/runner_spec.rb +49 -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: c911ee8aef66db7dbe8045f9f996ff0b810afeacb6f8efc7fc288e322937f59a
|
4
|
+
data.tar.gz: b22b126f597fad5adcc4ecc44c60ac57ac70b3ce2ffeb646d8001eabf088da8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '04589993f113b0ed3aab4d90ae8a963f5d68999535f523def84e9d6d2a355c0a5b2bbdc4a5969c0bcf8d44e6d1a40f42e1e6f5bbafe35126b321ef46c05f235f'
|
7
|
+
data.tar.gz: 52c16dd44e1801cb3ee353332dada749c013b452d3976c1a9aed9829d16b545f20b625cadcb37fba4fb09468c2c17a04d1dce14f665b2cdd4ac14e664d2a79fd
|
data/History.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== 4.5.2 / 2020-03-12
|
2
|
+
|
3
|
+
* Fix bug handling global options provided in option=value form (#47). (@orien)
|
4
|
+
* Fix ERB warnings under Ruby 2.7. (@esotericpig)
|
5
|
+
* Fix bug handling global options placed before command name (#32). (@orien)
|
6
|
+
|
1
7
|
=== 4.5.1 / 2020-03-08
|
2
8
|
|
3
9
|
* Fix bug causing global options to be ignored when arguments are present (#86). (@orien)
|
@@ -12,7 +12,11 @@ module Commander
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def template(name)
|
15
|
-
|
15
|
+
if RUBY_VERSION < '2.6'
|
16
|
+
ERB.new(File.read(File.join(File.dirname(__FILE__), 'terminal', "#{name}.erb")), nil, '-')
|
17
|
+
else
|
18
|
+
ERB.new(File.read(File.join(File.dirname(__FILE__), 'terminal', "#{name}.erb")), trim_mode: '-')
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
@@ -4,7 +4,11 @@ module Commander
|
|
4
4
|
module HelpFormatter
|
5
5
|
class TerminalCompact < Terminal
|
6
6
|
def template(name)
|
7
|
-
|
7
|
+
if RUBY_VERSION < '2.6'
|
8
|
+
ERB.new(File.read(File.join(File.dirname(__FILE__), 'terminal_compact', "#{name}.erb")), nil, '-')
|
9
|
+
else
|
10
|
+
ERB.new(File.read(File.join(File.dirname(__FILE__), 'terminal_compact', "#{name}.erb")), trim_mode: '-')
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
data/lib/commander/runner.rb
CHANGED
@@ -246,6 +246,7 @@ module Commander
|
|
246
246
|
# Returns array of valid command names found within _args_.
|
247
247
|
|
248
248
|
def valid_command_names_from(*args)
|
249
|
+
remove_global_options options, args
|
249
250
|
arg_string = args.delete_if { |value| value =~ /^-/ }.join ' '
|
250
251
|
commands.keys.find_all { |name| name if arg_string =~ /^#{name}\b/ }
|
251
252
|
end
|
@@ -329,25 +330,30 @@ module Commander
|
|
329
330
|
|
330
331
|
def remove_global_options(options, args)
|
331
332
|
options.each do |option|
|
332
|
-
switches = option[:switches]
|
333
|
+
switches = option[:switches]
|
333
334
|
next if switches.empty?
|
334
|
-
|
335
|
-
if (switch_has_arg = switches.any? { |s| s =~ /[ =]/ })
|
336
|
-
switches.map! { |s| s[0, s.index('=') || s.index(' ') || s.length] }
|
337
|
-
end
|
338
|
-
|
335
|
+
option_takes_argument = switches.any? { |s| s =~ /[ =]/ }
|
339
336
|
switches = expand_optionally_negative_switches(switches)
|
340
337
|
|
341
|
-
|
342
|
-
args.delete_if do |
|
343
|
-
break if
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
338
|
+
option_argument_needs_removal = false
|
339
|
+
args.delete_if do |token|
|
340
|
+
break if token == '--'
|
341
|
+
|
342
|
+
# Use just the portion of the token before the = when
|
343
|
+
# comparing switches.
|
344
|
+
index_of_equals = token.index('=') if option_takes_argument
|
345
|
+
token = token[0, index_of_equals] if index_of_equals
|
346
|
+
token_contains_option_argument = !index_of_equals.nil?
|
347
|
+
|
348
|
+
if switches.any? { |s| s[0, token.length] == token }
|
349
|
+
option_argument_needs_removal =
|
350
|
+
option_takes_argument && !token_contains_option_argument
|
351
|
+
true
|
352
|
+
elsif option_argument_needs_removal && token !~ /^-/
|
353
|
+
option_argument_needs_removal = false
|
354
|
+
true
|
349
355
|
else
|
350
|
-
|
356
|
+
option_argument_needs_removal = false
|
351
357
|
false
|
352
358
|
end
|
353
359
|
end
|
data/lib/commander/version.rb
CHANGED
data/spec/runner_spec.rb
CHANGED
@@ -100,6 +100,17 @@ describe Commander do
|
|
100
100
|
expect(quiet).to be true
|
101
101
|
end
|
102
102
|
|
103
|
+
it 'should be inherited by commands when provided before the command name' do
|
104
|
+
option = nil
|
105
|
+
new_command_runner '--global-option', 'option-value', 'command_name' do
|
106
|
+
global_option('--global-option=GLOBAL', 'A global option')
|
107
|
+
command :command_name do |c|
|
108
|
+
c.when_called { |_, options| option = options.global_option }
|
109
|
+
end
|
110
|
+
end.run!
|
111
|
+
expect(option).to eq('option-value')
|
112
|
+
end
|
113
|
+
|
103
114
|
it 'should be inherited by commands even when a block is present' do
|
104
115
|
quiet = nil
|
105
116
|
new_command_runner 'foo', '--quiet' do
|
@@ -166,6 +177,23 @@ describe Commander do
|
|
166
177
|
expect(config).to eq('config-value')
|
167
178
|
expect(args).to eq(%w(arg1 arg2))
|
168
179
|
end
|
180
|
+
|
181
|
+
it 'allows global options in the form option=value' do
|
182
|
+
config = nil
|
183
|
+
args = nil
|
184
|
+
new_command_runner 'test', 'arg1', '--config=config-value', 'arg2' do
|
185
|
+
global_option('-c', '--config CONFIG', String)
|
186
|
+
command :test do |c|
|
187
|
+
c.when_called do |arguments, options|
|
188
|
+
options.default(config: 'default')
|
189
|
+
args = arguments
|
190
|
+
config = options.config
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end.run!
|
194
|
+
expect(config).to eq('config-value')
|
195
|
+
expect(args).to eq(%w[arg1 arg2])
|
196
|
+
end
|
169
197
|
end
|
170
198
|
|
171
199
|
describe '#parse_global_options' do
|
@@ -360,6 +388,20 @@ describe Commander do
|
|
360
388
|
command_runner.remove_global_options options, args
|
361
389
|
expect(args).to eq(%w(--versionCode something))
|
362
390
|
end
|
391
|
+
|
392
|
+
it 'should remove specified switches value provided via equals' do
|
393
|
+
options = [{ switches: ['--global GLOBAL'] }]
|
394
|
+
args = ['--command', '--global=option-value', 'arg']
|
395
|
+
command_runner.remove_global_options options, args
|
396
|
+
expect(args).to eq(['--command', 'arg'])
|
397
|
+
end
|
398
|
+
|
399
|
+
it 'should not remove extra values after switches' do
|
400
|
+
options = [{ switches: ['--global GLOBAL'] }]
|
401
|
+
args = ['--global', '--command', 'arg']
|
402
|
+
command_runner.remove_global_options options, args
|
403
|
+
expect(args).to eq(['--command', 'arg'])
|
404
|
+
end
|
363
405
|
end
|
364
406
|
|
365
407
|
describe '--trace' do
|
@@ -529,6 +571,13 @@ describe Commander do
|
|
529
571
|
expect(command_runner.command_name_from_args).to eq('test')
|
530
572
|
end
|
531
573
|
|
574
|
+
it 'should locate command when provided after a global argument with value' do
|
575
|
+
new_command_runner '--global-option', 'option-value', 'test' do
|
576
|
+
global_option('--global-option=GLOBAL', 'A global option')
|
577
|
+
end
|
578
|
+
expect(command_runner.command_name_from_args).to eq('test')
|
579
|
+
end
|
580
|
+
|
532
581
|
it 'should support multi-word commands' do
|
533
582
|
new_command_runner '--help', '--arbitrary', 'some', 'long', 'command', 'foo'
|
534
583
|
command('some long command') {}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.5.
|
4
|
+
version: 4.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TJ Holowaychuk
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-03-
|
12
|
+
date: 2020-03-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: highline
|
@@ -143,9 +143,9 @@ licenses:
|
|
143
143
|
metadata:
|
144
144
|
bug_tracker_uri: https://github.com/commander-rb/commander/issues
|
145
145
|
changelog_uri: https://github.com/commander-rb/commander/blob/master/History.rdoc
|
146
|
-
documentation_uri: https://www.rubydoc.info/gems/commander/4.5.
|
146
|
+
documentation_uri: https://www.rubydoc.info/gems/commander/4.5.2
|
147
147
|
homepage_uri: https://github.com/commander-rb/commander
|
148
|
-
source_code_uri: https://github.com/commander-rb/commander/tree/v4.5.
|
148
|
+
source_code_uri: https://github.com/commander-rb/commander/tree/v4.5.2
|
149
149
|
post_install_message:
|
150
150
|
rdoc_options: []
|
151
151
|
require_paths:
|