commander 4.5.0 → 4.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01bdbd13d121e9ed4efc4a21970fd4465d3f2e516a6440499b67e6bd32868b0d
4
- data.tar.gz: 6bd6e26d357bf26af390ebd4be9a33f7c1f1c91c3efc296b4d21cb138887ac15
3
+ metadata.gz: 81b7ddc3a162a5470bc710c813ae0c774bc120154029d1a4fcbc3dbe5ffc13b9
4
+ data.tar.gz: 1375cade2955ac64e702c982572406a7b4f5e3e6e983bc4d52e5a19521c19e05
5
5
  SHA512:
6
- metadata.gz: c806f1a602eb89351344ff1f7209ec63f547a4659ee62678117cd77795bdc0e9579c8a3e3fecd34a0b167315ab4bdede104485be2e9682d05b2dcea34e170312
7
- data.tar.gz: db8f3b2fc17a1a790533b6d6609bcd5a0904bfb426549a6e6de9707f1ac804ee552efa338c07ef48ec8b2634892858ba4522d0292793064be8cba1f486a78270
6
+ metadata.gz: cf813e48a0d891a9998d96bf92a82d4e771d69a147fd1a45cb9af96f1bf1237050d9a7ba552f35cb27c78e48086fd93f3ea696d4d8207a2b9d025f084c91cf88
7
+ data.tar.gz: ab019b9db4e5dfe26fedea6bc611c8ac7162827fdb402c025b1e68b80b05d19c1ad0563b90b303c64820ed136b9259ce9fcda6b38f35254fe6ce4cee86b23349
@@ -1,3 +1,7 @@
1
+ === 4.5.1 / 2020-03-08
2
+
3
+ * Fix bug causing global options to be ignored when arguments are present (#86). (@orien)
4
+
1
5
  === 4.5.0 / 2020-01-21
2
6
 
3
7
  * Drop support for Ruby < 2.3.
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- [<img src="https://api.travis-ci.org/commander-rb/commander.svg" alt="Build Status" />](http://travis-ci.org/commander-rb/commander)
2
- [![Inline docs](http://inch-ci.org/github/commander-rb/commander.svg)](http://inch-ci.org/github/commander-rb/commander)
1
+ [<img src="https://api.travis-ci.org/commander-rb/commander.svg" alt="Build Status" />](https://travis-ci.org/commander-rb/commander)
2
+ [![Inline docs](https://inch-ci.org/github/commander-rb/commander.svg)](https://inch-ci.org/github/commander-rb/commander)
3
3
 
4
4
  # Commander
5
5
 
@@ -243,8 +243,8 @@ end
243
243
  ## Growl Notifications
244
244
 
245
245
  Commander provides methods for displaying Growl notifications. To use these
246
- methods you need to install http://github.com/tj/growl which utilizes
247
- the [growlnotify](http://growl.info/extras.php#growlnotify) executable. Note that
246
+ methods you need to install https://github.com/tj/growl which utilizes
247
+ the [growlnotify](https://growl.info/extras.php#growlnotify) executable. Note that
248
248
  growl is auto-imported by Commander when available, no need to require.
249
249
 
250
250
  ```ruby
@@ -449,7 +449,7 @@ global_option '--config FILE'
449
449
 
450
450
  ## ASCII Tables
451
451
 
452
- For feature rich ASCII tables for your terminal app check out the terminal-table gem at http://github.com/tj/terminal-table
452
+ For feature rich ASCII tables for your terminal app check out the terminal-table gem at https://github.com/tj/terminal-table
453
453
 
454
454
  +----------+-------+----+--------+-----------------------+
455
455
  | Terminal | Table | Is | Wicked | Awesome |
@@ -468,7 +468,7 @@ OR
468
468
  ## Contrib
469
469
 
470
470
  Feel free to fork and request a pull, or submit a ticket
471
- http://github.com/commander-rb/commander/issues
471
+ https://github.com/commander-rb/commander/issues
472
472
 
473
473
  ## License
474
474
 
@@ -12,6 +12,13 @@ Gem::Specification.new do |s|
12
12
  s.homepage = 'https://github.com/commander-rb/commander'
13
13
  s.summary = 'The complete solution for Ruby command-line executables'
14
14
  s.description = 'The complete solution for Ruby command-line executables. Commander bridges the gap between other terminal related libraries you know and love (OptionParser, HighLine), while providing many new features, and an elegant API.'
15
+ s.metadata = {
16
+ 'bug_tracker_uri' => "#{s.homepage}/issues",
17
+ 'changelog_uri' => "#{s.homepage}/blob/master/History.rdoc",
18
+ 'documentation_uri' => "https://www.rubydoc.info/gems/commander/#{s.version}",
19
+ 'homepage_uri' => s.homepage,
20
+ 'source_code_uri' => "#{s.homepage}/tree/v#{s.version}",
21
+ }
15
22
 
16
23
  s.files = `git ls-files`.split("\n")
17
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -4,6 +4,7 @@ module Commander
4
4
  class Command
5
5
  attr_accessor :name, :examples, :syntax, :description
6
6
  attr_accessor :summary, :proxy_options, :options
7
+ attr_reader :global_options
7
8
 
8
9
  ##
9
10
  # Options struct.
@@ -38,6 +39,7 @@ module Commander
38
39
  def initialize(name)
39
40
  @name, @examples, @when_called = name.to_s, [], []
40
41
  @options, @proxy_options = [], []
42
+ @global_options = []
41
43
  end
42
44
 
43
45
  ##
@@ -190,7 +192,7 @@ module Commander
190
192
  # collected by the #option_proc.
191
193
 
192
194
  def proxy_option_struct
193
- proxy_options.each_with_object(Options.new) do |(option, value), options|
195
+ (global_options + proxy_options).each_with_object(Options.new) do |(option, value), options|
194
196
  # options that are present will evaluate to true
195
197
  value = true if value.nil?
196
198
  options.__send__ :"#{option}=", value
@@ -395,7 +395,7 @@ module Commander
395
395
  def global_option_proc(switches, &block)
396
396
  lambda do |value|
397
397
  unless active_command.nil?
398
- active_command.proxy_options << [Runner.switch_to_sym(switches.last), value]
398
+ active_command.global_options << [Runner.switch_to_sym(switches.last), value]
399
399
  end
400
400
  yield value if block && !value.nil?
401
401
  end
@@ -1,3 +1,3 @@
1
1
  module Commander
2
- VERSION = '4.5.0'.freeze
2
+ VERSION = '4.5.1'.freeze
3
3
  end
@@ -164,6 +164,33 @@ describe Commander::Command do
164
164
  end
165
165
  @command.run '--interval', '15'
166
166
  end
167
+
168
+ describe 'given a global option' do
169
+ before do
170
+ @command.global_options << [:global_option, 'gvalue']
171
+ end
172
+
173
+ describe 'and no command specific arguments' do
174
+ it 'provides the global option to the command action' do
175
+ @command.when_called { |_, options| expect(options.global_option).to eq('gvalue') }
176
+ @command.run
177
+ end
178
+ end
179
+
180
+ describe 'and a command specific option' do
181
+ it 'provides the global option to the command action' do
182
+ @command.when_called { |_, options| expect(options.global_option).to eq('gvalue') }
183
+ @command.run '--verbose'
184
+ end
185
+ end
186
+
187
+ describe 'and a command specific argument' do
188
+ it 'provides the global option to the command action' do
189
+ @command.when_called { |_, options| expect(options.global_option).to eq('gvalue') }
190
+ @command.run 'argument'
191
+ end
192
+ end
193
+ end
167
194
  end
168
195
  end
169
196
  end
@@ -132,6 +132,40 @@ describe Commander do
132
132
  end.run!
133
133
  expect(quiet).to be false
134
134
  end
135
+
136
+ it 'should allow command arguments before the global option' do
137
+ config = nil
138
+ args = nil
139
+ new_command_runner 'foo', '--config', 'config-value', 'arg1', 'arg2' do
140
+ global_option('-c', '--config CONFIG', String)
141
+ command :foo do |c|
142
+ c.when_called do |arguments, options|
143
+ options.default(config: 'default')
144
+ args = arguments
145
+ config = options.config
146
+ end
147
+ end
148
+ end.run!
149
+ expect(config).to eq('config-value')
150
+ expect(args).to eq(%w(arg1 arg2))
151
+ end
152
+
153
+ it 'should allow command arguments after the global option' do
154
+ config = nil
155
+ args = nil
156
+ new_command_runner 'foo', 'arg1', 'arg2', '--config', 'config-value' do
157
+ global_option('-c', '--config CONFIG', String)
158
+ command :foo do |c|
159
+ c.when_called do |arguments, options|
160
+ options.default(config: 'default')
161
+ args = arguments
162
+ config = options.config
163
+ end
164
+ end
165
+ end.run!
166
+ expect(config).to eq('config-value')
167
+ expect(args).to eq(%w(arg1 arg2))
168
+ end
135
169
  end
136
170
 
137
171
  describe '#parse_global_options' do
@@ -334,7 +368,7 @@ describe Commander do
334
368
  new_command_runner 'foo' do
335
369
  command(:foo) { |c| c.when_called { fail 'cookies!' } }
336
370
  end.run!
337
- end.to raise_error(SystemExit, /error: cookies!. Use --trace/)
371
+ end.to raise_error(TestSystemExit, /error: cookies!. Use --trace/)
338
372
  end
339
373
 
340
374
  it 'should display callstack when using this switch' do
@@ -363,7 +397,7 @@ describe Commander do
363
397
  new_command_runner 'help', '--trace' do
364
398
  never_trace!
365
399
  end.run!
366
- end.to raise_error(SystemExit, /invalid option: --trace/)
400
+ end.to raise_error(TestSystemExit, /invalid option: --trace/)
367
401
  end
368
402
 
369
403
  it 'should not prompt to use --trace switch on errors' do
@@ -373,7 +407,7 @@ describe Commander do
373
407
  never_trace!
374
408
  command(:foo) { |c| c.when_called { fail 'cookies!' } }
375
409
  end.run!
376
- rescue SystemExit => e
410
+ rescue TestSystemExit => e
377
411
  msg = e.message
378
412
  end
379
413
  expect(msg).to match(/error: cookies!/)
@@ -430,7 +464,7 @@ describe Commander do
430
464
  it 'should output an invalid option message' do
431
465
  expect do
432
466
  run('test', '--invalid-option')
433
- end.to raise_error(SystemExit, /invalid option: --invalid-option/)
467
+ end.to raise_error(TestSystemExit, /invalid option: --invalid-option/)
434
468
  end
435
469
  end
436
470
 
@@ -438,7 +472,7 @@ describe Commander do
438
472
  it 'should output an invalid command message' do
439
473
  expect do
440
474
  run('foo')
441
- end.to raise_error(SystemExit, /invalid command. Use --help for more information/)
475
+ end.to raise_error(TestSystemExit, /invalid command. Use --help for more information/)
442
476
  end
443
477
  end
444
478
 
@@ -446,7 +480,7 @@ describe Commander do
446
480
  it 'should output an invalid command message' do
447
481
  expect do
448
482
  run('help', 'does_not_exist')
449
- end.to raise_error(SystemExit, /invalid command. Use --help for more information/)
483
+ end.to raise_error(TestSystemExit, /invalid command. Use --help for more information/)
450
484
  end
451
485
  end
452
486
 
@@ -454,7 +488,7 @@ describe Commander do
454
488
  it 'should output an invalid command message' do
455
489
  expect do
456
490
  run('--help', 'does_not_exist')
457
- end.to raise_error(SystemExit, /invalid command. Use --help for more information/)
491
+ end.to raise_error(TestSystemExit, /invalid command. Use --help for more information/)
458
492
  end
459
493
  end
460
494
 
@@ -462,7 +496,7 @@ describe Commander do
462
496
  it 'should output an invalid option message' do
463
497
  expect do
464
498
  run('--help', 'test', '--invalid-option')
465
- end.to raise_error(SystemExit, /invalid option: --invalid-option/)
499
+ end.to raise_error(TestSystemExit, /invalid option: --invalid-option/)
466
500
  end
467
501
  end
468
502
 
@@ -14,13 +14,22 @@ require 'commander'
14
14
  require 'commander/methods'
15
15
 
16
16
  # Mock terminal IO streams so we can spec against them
17
-
18
17
  def mock_terminal
19
18
  @input = StringIO.new
20
19
  @output = StringIO.new
21
20
  HighLine.default_instance = HighLine.new(@input, @output)
22
21
  end
23
22
 
23
+ # Stub Kernel.abort
24
+ TestSystemExit = Class.new(RuntimeError)
25
+ module Commander
26
+ class Runner
27
+ def abort(message)
28
+ fail TestSystemExit, message
29
+ end
30
+ end
31
+ end
32
+
24
33
  # Create test command for usage within several specs
25
34
 
26
35
  def create_test_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.0
4
+ version: 4.5.1
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-01-21 00:00:00.000000000 Z
12
+ date: 2020-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline
@@ -140,7 +140,12 @@ files:
140
140
  homepage: https://github.com/commander-rb/commander
141
141
  licenses:
142
142
  - MIT
143
- metadata: {}
143
+ metadata:
144
+ bug_tracker_uri: https://github.com/commander-rb/commander/issues
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
147
+ homepage_uri: https://github.com/commander-rb/commander
148
+ source_code_uri: https://github.com/commander-rb/commander/tree/v4.5.1
144
149
  post_install_message:
145
150
  rdoc_options: []
146
151
  require_paths:
@@ -156,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
161
  - !ruby/object:Gem::Version
157
162
  version: '0'
158
163
  requirements: []
159
- rubygems_version: 3.0.2
164
+ rubygems_version: 3.0.6
160
165
  signing_key:
161
166
  specification_version: 4
162
167
  summary: The complete solution for Ruby command-line executables