commander 4.5.1 → 4.5.2

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
  SHA256:
3
- metadata.gz: 81b7ddc3a162a5470bc710c813ae0c774bc120154029d1a4fcbc3dbe5ffc13b9
4
- data.tar.gz: 1375cade2955ac64e702c982572406a7b4f5e3e6e983bc4d52e5a19521c19e05
3
+ metadata.gz: c911ee8aef66db7dbe8045f9f996ff0b810afeacb6f8efc7fc288e322937f59a
4
+ data.tar.gz: b22b126f597fad5adcc4ecc44c60ac57ac70b3ce2ffeb646d8001eabf088da8d
5
5
  SHA512:
6
- metadata.gz: cf813e48a0d891a9998d96bf92a82d4e771d69a147fd1a45cb9af96f1bf1237050d9a7ba552f35cb27c78e48086fd93f3ea696d4d8207a2b9d025f084c91cf88
7
- data.tar.gz: ab019b9db4e5dfe26fedea6bc611c8ac7162827fdb402c025b1e68b80b05d19c1ad0563b90b303c64820ed136b9259ce9fcda6b38f35254fe6ce4cee86b23349
6
+ metadata.gz: '04589993f113b0ed3aab4d90ae8a963f5d68999535f523def84e9d6d2a355c0a5b2bbdc4a5969c0bcf8d44e6d1a40f42e1e6f5bbafe35126b321ef46c05f235f'
7
+ data.tar.gz: 52c16dd44e1801cb3ee353332dada749c013b452d3976c1a9aed9829d16b545f20b625cadcb37fba4fb09468c2c17a04d1dce14f665b2cdd4ac14e664d2a79fd
@@ -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
- ERB.new(File.read(File.join(File.dirname(__FILE__), 'terminal', "#{name}.erb")), nil, '-')
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
- ERB.new(File.read(File.join(File.dirname(__FILE__), 'terminal_compact', "#{name}.erb")), nil, '-')
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
@@ -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].dup
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
- past_switch, arg_removed = false, false
342
- args.delete_if do |arg|
343
- break if arg == '--'
344
- if switches.any? { |s| s[0, arg.length] == arg }
345
- arg_removed = !switch_has_arg
346
- past_switch = true
347
- elsif past_switch && !arg_removed && arg !~ /^-/
348
- arg_removed = true
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
- arg_removed = true
356
+ option_argument_needs_removal = false
351
357
  false
352
358
  end
353
359
  end
@@ -1,3 +1,3 @@
1
1
  module Commander
2
- VERSION = '4.5.1'.freeze
2
+ VERSION = '4.5.2'.freeze
3
3
  end
@@ -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.1
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-08 00:00:00.000000000 Z
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.1
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.1
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: