commander 4.4.6 → 4.6.0
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/.rubocop.yml +26 -6
- data/.rubocop_todo.yml +4 -4
- data/.travis.yml +7 -8
- data/Gemfile +2 -0
- data/History.rdoc +25 -0
- data/README.md +6 -6
- data/Rakefile +3 -1
- data/bin/commander +2 -1
- data/commander.gemspec +13 -10
- data/lib/commander.rb +2 -0
- data/lib/commander/blank.rb +2 -0
- data/lib/commander/command.rb +10 -5
- data/lib/commander/configure.rb +2 -0
- data/lib/commander/core_ext.rb +2 -0
- data/lib/commander/core_ext/array.rb +3 -1
- data/lib/commander/core_ext/object.rb +2 -0
- data/lib/commander/delegates.rb +3 -1
- data/lib/commander/help_formatters.rb +3 -1
- data/lib/commander/help_formatters/base.rb +2 -0
- data/lib/commander/help_formatters/terminal.rb +7 -1
- data/lib/commander/help_formatters/terminal/command_help.erb +6 -6
- data/lib/commander/help_formatters/terminal/help.erb +7 -7
- data/lib/commander/help_formatters/terminal_compact.rb +7 -1
- data/lib/commander/import.rb +2 -0
- data/lib/commander/methods.rb +4 -2
- data/lib/commander/platform.rb +2 -0
- data/lib/commander/runner.rb +44 -36
- data/lib/commander/user_interaction.rb +27 -21
- data/lib/commander/version.rb +3 -1
- data/spec/command_spec.rb +29 -0
- data/spec/configure_spec.rb +2 -0
- data/spec/core_ext/array_spec.rb +3 -1
- data/spec/core_ext/object_spec.rb +2 -0
- data/spec/help_formatters/terminal_compact_spec.rb +2 -0
- data/spec/help_formatters/terminal_spec.rb +2 -0
- data/spec/methods_spec.rb +5 -3
- data/spec/runner_spec.rb +123 -8
- data/spec/spec_helper.rb +15 -4
- data/spec/ui_spec.rb +4 -2
- metadata +34 -30
data/spec/configure_spec.rb
CHANGED
data/spec/core_ext/array_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Array do
|
@@ -12,7 +14,7 @@ describe Array do
|
|
12
14
|
|
13
15
|
it 'should match %w behavior with multiple backslashes' do
|
14
16
|
str = 'just a\\ test'
|
15
|
-
expect(Array.parse(str)).to eq(
|
17
|
+
expect(Array.parse(str)).to eq(['just', 'a test'])
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
data/spec/methods_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'commander/methods'
|
3
5
|
|
@@ -16,12 +18,12 @@ describe Commander::Methods do
|
|
16
18
|
|
17
19
|
before do
|
18
20
|
allow(terminal).to receive(:ask)
|
19
|
-
|
20
|
-
|
21
|
+
@old_highline = HighLine.default_instance
|
22
|
+
HighLine.default_instance = terminal
|
21
23
|
end
|
22
24
|
|
23
25
|
after do
|
24
|
-
|
26
|
+
HighLine.default_instance = @old_highline
|
25
27
|
end
|
26
28
|
|
27
29
|
subject do
|
data/spec/runner_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Commander do
|
@@ -100,6 +102,17 @@ describe Commander do
|
|
100
102
|
expect(quiet).to be true
|
101
103
|
end
|
102
104
|
|
105
|
+
it 'should be inherited by commands when provided before the command name' do
|
106
|
+
option = nil
|
107
|
+
new_command_runner '--global-option', 'option-value', 'command_name' do
|
108
|
+
global_option('--global-option=GLOBAL', 'A global option')
|
109
|
+
command :command_name do |c|
|
110
|
+
c.when_called { |_, options| option = options.global_option }
|
111
|
+
end
|
112
|
+
end.run!
|
113
|
+
expect(option).to eq('option-value')
|
114
|
+
end
|
115
|
+
|
103
116
|
it 'should be inherited by commands even when a block is present' do
|
104
117
|
quiet = nil
|
105
118
|
new_command_runner 'foo', '--quiet' do
|
@@ -132,6 +145,57 @@ describe Commander do
|
|
132
145
|
end.run!
|
133
146
|
expect(quiet).to be false
|
134
147
|
end
|
148
|
+
|
149
|
+
it 'should allow command arguments before the global option' do
|
150
|
+
config = nil
|
151
|
+
args = nil
|
152
|
+
new_command_runner 'foo', '--config', 'config-value', 'arg1', 'arg2' do
|
153
|
+
global_option('-c', '--config CONFIG', String)
|
154
|
+
command :foo do |c|
|
155
|
+
c.when_called do |arguments, options|
|
156
|
+
options.default(config: 'default')
|
157
|
+
args = arguments
|
158
|
+
config = options.config
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end.run!
|
162
|
+
expect(config).to eq('config-value')
|
163
|
+
expect(args).to eq(%w(arg1 arg2))
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should allow command arguments after the global option' do
|
167
|
+
config = nil
|
168
|
+
args = nil
|
169
|
+
new_command_runner 'foo', 'arg1', 'arg2', '--config', 'config-value' do
|
170
|
+
global_option('-c', '--config CONFIG', String)
|
171
|
+
command :foo do |c|
|
172
|
+
c.when_called do |arguments, options|
|
173
|
+
options.default(config: 'default')
|
174
|
+
args = arguments
|
175
|
+
config = options.config
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end.run!
|
179
|
+
expect(config).to eq('config-value')
|
180
|
+
expect(args).to eq(%w(arg1 arg2))
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'allows global options in the form option=value' do
|
184
|
+
config = nil
|
185
|
+
args = nil
|
186
|
+
new_command_runner 'test', 'arg1', '--config=config-value', 'arg2' do
|
187
|
+
global_option('-c', '--config CONFIG', String)
|
188
|
+
command :test do |c|
|
189
|
+
c.when_called do |arguments, options|
|
190
|
+
options.default(config: 'default')
|
191
|
+
args = arguments
|
192
|
+
config = options.config
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end.run!
|
196
|
+
expect(config).to eq('config-value')
|
197
|
+
expect(args).to eq(%w[arg1 arg2])
|
198
|
+
end
|
135
199
|
end
|
136
200
|
|
137
201
|
describe '#parse_global_options' do
|
@@ -326,6 +390,20 @@ describe Commander do
|
|
326
390
|
command_runner.remove_global_options options, args
|
327
391
|
expect(args).to eq(%w(--versionCode something))
|
328
392
|
end
|
393
|
+
|
394
|
+
it 'should remove specified switches value provided via equals' do
|
395
|
+
options = [{ switches: ['--global GLOBAL'] }]
|
396
|
+
args = ['--command', '--global=option-value', 'arg']
|
397
|
+
command_runner.remove_global_options options, args
|
398
|
+
expect(args).to eq(['--command', 'arg'])
|
399
|
+
end
|
400
|
+
|
401
|
+
it 'should not remove extra values after switches' do
|
402
|
+
options = [{ switches: ['--global GLOBAL'] }]
|
403
|
+
args = ['--global', '--command', 'arg']
|
404
|
+
command_runner.remove_global_options options, args
|
405
|
+
expect(args).to eq(['--command', 'arg'])
|
406
|
+
end
|
329
407
|
end
|
330
408
|
|
331
409
|
describe '--trace' do
|
@@ -334,7 +412,7 @@ describe Commander do
|
|
334
412
|
new_command_runner 'foo' do
|
335
413
|
command(:foo) { |c| c.when_called { fail 'cookies!' } }
|
336
414
|
end.run!
|
337
|
-
end.to raise_error(
|
415
|
+
end.to raise_error(TestSystemExit, /error: cookies!. Use --trace/)
|
338
416
|
end
|
339
417
|
|
340
418
|
it 'should display callstack when using this switch' do
|
@@ -363,7 +441,7 @@ describe Commander do
|
|
363
441
|
new_command_runner 'help', '--trace' do
|
364
442
|
never_trace!
|
365
443
|
end.run!
|
366
|
-
end.to raise_error(
|
444
|
+
end.to raise_error(TestSystemExit, /invalid option: --trace/)
|
367
445
|
end
|
368
446
|
|
369
447
|
it 'should not prompt to use --trace switch on errors' do
|
@@ -373,7 +451,7 @@ describe Commander do
|
|
373
451
|
never_trace!
|
374
452
|
command(:foo) { |c| c.when_called { fail 'cookies!' } }
|
375
453
|
end.run!
|
376
|
-
rescue
|
454
|
+
rescue TestSystemExit => e
|
377
455
|
msg = e.message
|
378
456
|
end
|
379
457
|
expect(msg).to match(/error: cookies!/)
|
@@ -408,6 +486,22 @@ describe Commander do
|
|
408
486
|
expect(run('test', '--help')).to eq("Implement help for test here\n")
|
409
487
|
end
|
410
488
|
|
489
|
+
it 'can be used after the command and command arguments' do
|
490
|
+
expect(run('test', 'command-arg', '--help')).to eq("Implement help for test here\n")
|
491
|
+
end
|
492
|
+
|
493
|
+
it 'can be used before a single-word command with command arguments' do
|
494
|
+
expect(run('help', 'test', 'command-arg')).to eq("Implement help for test here\n")
|
495
|
+
end
|
496
|
+
|
497
|
+
it 'can be used before a multi-word command with command arguments' do
|
498
|
+
expect(
|
499
|
+
run('help', 'module', 'install', 'command-arg') do
|
500
|
+
command('module install') { |c| c.when_called { say 'whee!' } }
|
501
|
+
end
|
502
|
+
).to eq("Implement help for module install here\n")
|
503
|
+
end
|
504
|
+
|
411
505
|
describe 'help_paging program information' do
|
412
506
|
it 'enables paging when enabled' do
|
413
507
|
run('--help') { program :help_paging, true }
|
@@ -430,7 +524,7 @@ describe Commander do
|
|
430
524
|
it 'should output an invalid option message' do
|
431
525
|
expect do
|
432
526
|
run('test', '--invalid-option')
|
433
|
-
end.to raise_error(
|
527
|
+
end.to raise_error(TestSystemExit, /invalid option: --invalid-option/)
|
434
528
|
end
|
435
529
|
end
|
436
530
|
|
@@ -438,7 +532,7 @@ describe Commander do
|
|
438
532
|
it 'should output an invalid command message' do
|
439
533
|
expect do
|
440
534
|
run('foo')
|
441
|
-
end.to raise_error(
|
535
|
+
end.to raise_error(TestSystemExit, /invalid command. Use --help for more information/)
|
442
536
|
end
|
443
537
|
end
|
444
538
|
|
@@ -446,7 +540,7 @@ describe Commander do
|
|
446
540
|
it 'should output an invalid command message' do
|
447
541
|
expect do
|
448
542
|
run('help', 'does_not_exist')
|
449
|
-
end.to raise_error(
|
543
|
+
end.to raise_error(TestSystemExit, /invalid command. Use --help for more information/)
|
450
544
|
end
|
451
545
|
end
|
452
546
|
|
@@ -454,7 +548,7 @@ describe Commander do
|
|
454
548
|
it 'should output an invalid command message' do
|
455
549
|
expect do
|
456
550
|
run('--help', 'does_not_exist')
|
457
|
-
end.to raise_error(
|
551
|
+
end.to raise_error(TestSystemExit, /invalid command. Use --help for more information/)
|
458
552
|
end
|
459
553
|
end
|
460
554
|
|
@@ -462,7 +556,7 @@ describe Commander do
|
|
462
556
|
it 'should output an invalid option message' do
|
463
557
|
expect do
|
464
558
|
run('--help', 'test', '--invalid-option')
|
465
|
-
end.to raise_error(
|
559
|
+
end.to raise_error(TestSystemExit, /invalid option: --invalid-option/)
|
466
560
|
end
|
467
561
|
end
|
468
562
|
|
@@ -495,6 +589,13 @@ describe Commander do
|
|
495
589
|
expect(command_runner.command_name_from_args).to eq('test')
|
496
590
|
end
|
497
591
|
|
592
|
+
it 'should locate command when provided after a global argument with value' do
|
593
|
+
new_command_runner '--global-option', 'option-value', 'test' do
|
594
|
+
global_option('--global-option=GLOBAL', 'A global option')
|
595
|
+
end
|
596
|
+
expect(command_runner.command_name_from_args).to eq('test')
|
597
|
+
end
|
598
|
+
|
498
599
|
it 'should support multi-word commands' do
|
499
600
|
new_command_runner '--help', '--arbitrary', 'some', 'long', 'command', 'foo'
|
500
601
|
command('some long command') {}
|
@@ -643,4 +744,18 @@ describe Commander do
|
|
643
744
|
end.run!
|
644
745
|
end
|
645
746
|
end
|
747
|
+
|
748
|
+
describe 'with double dash' do
|
749
|
+
it 'should interpret the remainder as arguments' do
|
750
|
+
new_command_runner 'foo', '--', '-x' do
|
751
|
+
command('foo') do |c|
|
752
|
+
c.option '-x', 'Switch'
|
753
|
+
c.when_called do |args, options|
|
754
|
+
expect(args).to eq(%w(-x))
|
755
|
+
expect(options.x).to be_nil
|
756
|
+
end
|
757
|
+
end
|
758
|
+
end.run!
|
759
|
+
end
|
760
|
+
end
|
646
761
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require 'stringio'
|
3
5
|
require 'simplecov'
|
@@ -6,7 +8,7 @@ SimpleCov.start do
|
|
6
8
|
end
|
7
9
|
|
8
10
|
# Unshift so that local files load instead of something in gems
|
9
|
-
$LOAD_PATH.unshift File.dirname(__FILE__)
|
11
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
10
12
|
|
11
13
|
# This basically replicates the behavior of `require 'commander/import'`
|
12
14
|
# but without adding an `at_exit` hook, which interferes with exit code
|
@@ -14,11 +16,20 @@ require 'commander'
|
|
14
16
|
require 'commander/methods'
|
15
17
|
|
16
18
|
# Mock terminal IO streams so we can spec against them
|
17
|
-
|
18
19
|
def mock_terminal
|
19
20
|
@input = StringIO.new
|
20
21
|
@output = StringIO.new
|
21
|
-
|
22
|
+
HighLine.default_instance = HighLine.new(@input, @output)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Stub Kernel.abort
|
26
|
+
TestSystemExit = Class.new(RuntimeError)
|
27
|
+
module Commander
|
28
|
+
class Runner
|
29
|
+
def abort(message)
|
30
|
+
fail TestSystemExit, message
|
31
|
+
end
|
32
|
+
end
|
22
33
|
end
|
23
34
|
|
24
35
|
# Create test command for usage within several specs
|
@@ -40,7 +51,7 @@ end
|
|
40
51
|
# Create a new command runner
|
41
52
|
|
42
53
|
def new_command_runner(*args, &block)
|
43
|
-
Commander::Runner.instance_variable_set
|
54
|
+
Commander::Runner.instance_variable_set :@instance, Commander::Runner.new(args)
|
44
55
|
program :name, 'test'
|
45
56
|
program :version, '1.2.3'
|
46
57
|
program :description, 'something'
|
data/spec/ui_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Commander::UI do
|
@@ -5,7 +7,7 @@ describe Commander::UI do
|
|
5
7
|
|
6
8
|
describe '.replace_tokens' do
|
7
9
|
it 'should replace tokens within a string, with hash values' do
|
8
|
-
result = Commander::UI.replace_tokens 'Welcome :name, enjoy your :object'
|
10
|
+
result = Commander::UI.replace_tokens 'Welcome :name, enjoy your :object', name: 'TJ', object: 'cookie'
|
9
11
|
expect(result).to eq('Welcome TJ, enjoy your cookie')
|
10
12
|
end
|
11
13
|
end
|
@@ -15,7 +17,7 @@ describe Commander::UI do
|
|
15
17
|
exception = false
|
16
18
|
begin
|
17
19
|
progress([]) {}
|
18
|
-
rescue
|
20
|
+
rescue StandardError
|
19
21
|
exception = true
|
20
22
|
end
|
21
23
|
expect(exception).not_to be true
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TJ Holowaychuk
|
8
8
|
- Gabriel Gilder
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-04-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: highline
|
@@ -17,14 +17,28 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 2.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 2.0.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: rspec
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,19 +54,19 @@ dependencies:
|
|
40
54
|
- !ruby/object:Gem::Version
|
41
55
|
version: '3.2'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
57
|
+
name: rubocop
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
45
59
|
requirements:
|
46
|
-
- - "
|
60
|
+
- - "~>"
|
47
61
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
62
|
+
version: 1.12.1
|
49
63
|
type: :development
|
50
64
|
prerelease: false
|
51
65
|
version_requirements: !ruby/object:Gem::Requirement
|
52
66
|
requirements:
|
53
|
-
- - "
|
67
|
+
- - "~>"
|
54
68
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
69
|
+
version: 1.12.1
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: simplecov
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,20 +81,6 @@ dependencies:
|
|
67
81
|
- - ">="
|
68
82
|
- !ruby/object:Gem::Version
|
69
83
|
version: '0'
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: rubocop
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - "~>"
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 0.49.1
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - "~>"
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: 0.49.1
|
84
84
|
description: The complete solution for Ruby command-line executables. Commander bridges
|
85
85
|
the gap between other terminal related libraries you know and love (OptionParser,
|
86
86
|
HighLine), while providing many new features, and an elegant API.
|
@@ -140,8 +140,13 @@ files:
|
|
140
140
|
homepage: https://github.com/commander-rb/commander
|
141
141
|
licenses:
|
142
142
|
- MIT
|
143
|
-
metadata:
|
144
|
-
|
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.6.0
|
147
|
+
homepage_uri: https://github.com/commander-rb/commander
|
148
|
+
source_code_uri: https://github.com/commander-rb/commander/tree/v4.6.0
|
149
|
+
post_install_message:
|
145
150
|
rdoc_options: []
|
146
151
|
require_paths:
|
147
152
|
- lib
|
@@ -149,16 +154,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
154
|
requirements:
|
150
155
|
- - ">="
|
151
156
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
157
|
+
version: '2.4'
|
153
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
159
|
requirements:
|
155
160
|
- - ">="
|
156
161
|
- !ruby/object:Gem::Version
|
157
162
|
version: '0'
|
158
163
|
requirements: []
|
159
|
-
|
160
|
-
|
161
|
-
signing_key:
|
164
|
+
rubygems_version: 3.2.15
|
165
|
+
signing_key:
|
162
166
|
specification_version: 4
|
163
167
|
summary: The complete solution for Ruby command-line executables
|
164
168
|
test_files:
|