commander-fastlane 4.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/.rubocop.yml +37 -0
- data/.rubocop_todo.yml +77 -0
- data/.travis.yml +12 -0
- data/DEVELOPMENT +15 -0
- data/Gemfile +3 -0
- data/History.rdoc +428 -0
- data/LICENSE +22 -0
- data/Manifest +38 -0
- data/README.md +460 -0
- data/Rakefile +13 -0
- data/bin/commander +104 -0
- data/commander.gemspec +31 -0
- data/lib/commander.rb +35 -0
- data/lib/commander/blank.rb +7 -0
- data/lib/commander/command.rb +210 -0
- data/lib/commander/configure.rb +14 -0
- data/lib/commander/core_ext.rb +2 -0
- data/lib/commander/core_ext/array.rb +24 -0
- data/lib/commander/core_ext/object.rb +8 -0
- data/lib/commander/delegates.rb +25 -0
- data/lib/commander/help_formatters.rb +49 -0
- data/lib/commander/help_formatters/base.rb +24 -0
- data/lib/commander/help_formatters/terminal.rb +19 -0
- data/lib/commander/help_formatters/terminal/command_help.erb +35 -0
- data/lib/commander/help_formatters/terminal/help.erb +44 -0
- data/lib/commander/help_formatters/terminal_compact.rb +11 -0
- data/lib/commander/help_formatters/terminal_compact/command_help.erb +27 -0
- data/lib/commander/help_formatters/terminal_compact/help.erb +35 -0
- data/lib/commander/import.rb +5 -0
- data/lib/commander/methods.rb +11 -0
- data/lib/commander/platform.rb +7 -0
- data/lib/commander/runner.rb +484 -0
- data/lib/commander/user_interaction.rb +528 -0
- data/lib/commander/version.rb +3 -0
- data/spec/command_spec.rb +157 -0
- data/spec/configure_spec.rb +37 -0
- data/spec/core_ext/array_spec.rb +18 -0
- data/spec/core_ext/object_spec.rb +19 -0
- data/spec/help_formatters/terminal_compact_spec.rb +195 -0
- data/spec/help_formatters/terminal_spec.rb +190 -0
- data/spec/methods_spec.rb +20 -0
- data/spec/runner_spec.rb +646 -0
- data/spec/spec_helper.rb +78 -0
- data/spec/ui_spec.rb +30 -0
- metadata +175 -0
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Commander::Command do
|
4
|
+
include Commander::Methods
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
mock_terminal
|
8
|
+
create_test_command
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'Options' do
|
12
|
+
before :each do
|
13
|
+
@options = Commander::Command::Options.new
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should act like an open struct' do
|
17
|
+
@options.send = 'mail'
|
18
|
+
@options.call = true
|
19
|
+
expect(@options.send).to eq('mail')
|
20
|
+
expect(@options.call).to eq(true)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should allow __send__ to function as always' do
|
24
|
+
@options.send = 'foo'
|
25
|
+
expect(@options.__send__(:send)).to eq('foo')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#option' do
|
30
|
+
it 'should add options' do
|
31
|
+
expect { @command.option '--recursive' }.to change(@command.options, :length).from(1).to(2)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should allow procs as option handlers' do
|
35
|
+
@command.option('--recursive') { |recursive| expect(recursive).to be true }
|
36
|
+
@command.run '--recursive'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should allow usage of common method names' do
|
40
|
+
@command.option '--open file'
|
41
|
+
@command.when_called { |_, options| expect(options.open).to eq('foo') }
|
42
|
+
@command.run '--open', 'foo'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#run' do
|
47
|
+
describe 'should invoke #when_called' do
|
48
|
+
it 'with arguments seperated from options' do
|
49
|
+
@command.when_called { |args, _options| expect(args.join(' ')).to eq('just some args') }
|
50
|
+
@command.run '--verbose', 'just', 'some', 'args'
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'calling the #call method by default when an object is called' do
|
54
|
+
object = double 'Object'
|
55
|
+
expect(object).to receive(:call).once
|
56
|
+
@command.when_called object
|
57
|
+
@command.run 'foo'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should allow #action as an alias to #when_called' do
|
61
|
+
object = double 'Object'
|
62
|
+
expect(object).to receive(:call).once
|
63
|
+
@command.action object
|
64
|
+
@command.run 'foo'
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'calling an arbitrary method when an object is called' do
|
68
|
+
object = double 'Object'
|
69
|
+
expect(object).to receive(:foo).once
|
70
|
+
@command.when_called object, :foo
|
71
|
+
@command.run 'foo'
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should raise an error when no handler is present' do
|
75
|
+
expect { @command.when_called }.to raise_error(ArgumentError)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe 'should populate options with' do
|
80
|
+
it 'boolean values' do
|
81
|
+
@command.option '--[no-]toggle'
|
82
|
+
@command.when_called { |_, options| expect(options.toggle).to be true }
|
83
|
+
@command.run '--toggle'
|
84
|
+
@command.when_called { |_, options| expect(options.toggle).to be false }
|
85
|
+
@command.run '--no-toggle'
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'mandatory arguments' do
|
89
|
+
@command.option '--file FILE'
|
90
|
+
@command.when_called { |_, options| expect(options.file).to eq('foo') }
|
91
|
+
@command.run '--file', 'foo'
|
92
|
+
expect { @command.run '--file' }.to raise_error(OptionParser::MissingArgument)
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'optional arguments' do
|
96
|
+
before do
|
97
|
+
@command.option '--use-config [file] '
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should return the argument when provided' do
|
101
|
+
@command.when_called { |_, options| expect(options.use_config).to eq('foo') }
|
102
|
+
@command.run '--use-config', 'foo'
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should return true when present without an argument' do
|
106
|
+
@command.when_called { |_, options| expect(options.use_config).to be true }
|
107
|
+
@command.run '--use-config'
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should return nil when not present' do
|
111
|
+
@command.when_called { |_, options| expect(options.use_config).to be_nil }
|
112
|
+
@command.run
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe 'typed arguments' do
|
117
|
+
before do
|
118
|
+
@command.option '--interval N', Integer
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should parse valid values' do
|
122
|
+
@command.when_called { |_, options| expect(options.interval).to eq(5) }
|
123
|
+
@command.run '--interval', '5'
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should reject invalid values' do
|
127
|
+
expect { @command.run '--interval', 'invalid' }.to raise_error(OptionParser::InvalidArgument)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'lists' do
|
132
|
+
@command.option '--fav COLORS', Array
|
133
|
+
@command.when_called { |_, options| expect(options.fav).to eq(%w(red green blue)) }
|
134
|
+
@command.run '--fav', 'red,green,blue'
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'lists with multi-word items' do
|
138
|
+
@command.option '--fav MOVIES', Array
|
139
|
+
@command.when_called { |_, options| expect(options.fav).to eq(['super\ bad', 'nightmare']) }
|
140
|
+
@command.run '--fav', 'super\ bad,nightmare'
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'defaults' do
|
144
|
+
@command.option '--files LIST', Array
|
145
|
+
@command.option '--interval N', Integer
|
146
|
+
@command.when_called do |_, options|
|
147
|
+
options.default \
|
148
|
+
files: %w(foo bar),
|
149
|
+
interval: 5
|
150
|
+
expect(options.files).to eq(%w(foo bar))
|
151
|
+
expect(options.interval).to eq(15)
|
152
|
+
end
|
153
|
+
@command.run '--interval', '15'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'commander/configure'
|
3
|
+
|
4
|
+
describe Commander do
|
5
|
+
describe '.configure' do
|
6
|
+
it 'calls the given block' do
|
7
|
+
expect { Commander.configure { throw :block_called } }.to throw_symbol(:block_called)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'called block' do
|
11
|
+
before(:each) do
|
12
|
+
allow(Commander::Runner.instance).to receive(:run!)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'provides Commander configuration methods' do
|
16
|
+
Commander.configure do
|
17
|
+
program :name, 'test'
|
18
|
+
end
|
19
|
+
|
20
|
+
expect(Commander::Runner.instance.program(:name)).to eq('test')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'passes all arguments to the block' do
|
24
|
+
Commander.configure('foo') do |first_arg|
|
25
|
+
program :name, first_arg
|
26
|
+
end
|
27
|
+
|
28
|
+
expect(Commander::Runner.instance.program(:name)).to eq('foo')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'calls Runner#run! after calling the configuration block' do
|
33
|
+
expect(Commander::Runner.instance).to receive(:run!)
|
34
|
+
Commander.configure {}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
describe '#parse' do
|
5
|
+
it 'should seperate a list of words into an array' do
|
6
|
+
expect(Array.parse('just a test')).to eq(%w(just a test))
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should preserve escaped whitespace' do
|
10
|
+
expect(Array.parse('just a\ test')).to eq(['just', 'a test'])
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should match %w behavior with multiple backslashes' do
|
14
|
+
str = 'just a\\ test'
|
15
|
+
expect(Array.parse(str)).to eq(eval("%w(#{str})"))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Object do
|
4
|
+
describe '#get_binding' do
|
5
|
+
it 'should return the objects binding' do
|
6
|
+
expect(-> {}.get_binding).to be_instance_of(Binding)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#method_missing' do
|
11
|
+
it 'should preserve its original behavior for missing methods' do
|
12
|
+
expect { send(:i_am_a_missing_method) }.to raise_error(NoMethodError)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should preserve its original behavior for missing variables' do
|
16
|
+
expect { i_am_a_missing_variable }.to raise_error(NameError)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Commander::HelpFormatter::TerminalCompact do
|
4
|
+
include Commander::Methods
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
mock_terminal
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'global help' do
|
11
|
+
before :each do
|
12
|
+
new_command_runner 'help' do
|
13
|
+
program :help_formatter, :compact
|
14
|
+
command :'install gem' do |c|
|
15
|
+
c.syntax = 'foo install gem [options]'
|
16
|
+
c.summary = 'Install some gem'
|
17
|
+
end
|
18
|
+
end.run!
|
19
|
+
@global_help = @output.string
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'should display' do
|
23
|
+
it 'the command name' do
|
24
|
+
expect(@global_help).to include('install gem')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'the summary' do
|
28
|
+
expect(@global_help).to include('Install some gem')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'one space between command name and summary' do
|
32
|
+
expect(@global_help).to include('install gem Install some gem')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'should not display' do
|
37
|
+
it 'the commands label with description for default_command' do
|
38
|
+
expect(@global_help).not_to include('Commands: (* default)')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'global help with default_command' do
|
44
|
+
describe 'with command option' do
|
45
|
+
describe 'default_command is before command' do
|
46
|
+
before :each do
|
47
|
+
new_command_runner 'help' do
|
48
|
+
program :help_formatter, :compact
|
49
|
+
default_command :'install gem'
|
50
|
+
command :'install gem' do |c|
|
51
|
+
c.syntax = 'foo install gem [options]'
|
52
|
+
c.summary = 'Install some gem'
|
53
|
+
c.option('--testing-command', 'Testing command')
|
54
|
+
c.option('--testing-command-second', 'Testing command second')
|
55
|
+
end
|
56
|
+
end.run!
|
57
|
+
@global_help = @output.string
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'should display' do
|
61
|
+
it 'the commands label with description for default_command' do
|
62
|
+
expect(@global_help).to include('Commands: (* default)')
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'the command name' do
|
66
|
+
expect(@global_help).to include('install gem')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'the summary with marked as default_command' do
|
70
|
+
expect(@global_help).to include('* Install some gem')
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'the options label' do
|
74
|
+
expect(@global_help).to include('Options for install gem')
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'the command options' do
|
78
|
+
expect(@global_help).to include('--testing-command')
|
79
|
+
expect(@global_help).to include('--testing-command-second')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'default_command is after command' do
|
85
|
+
before :each do
|
86
|
+
new_command_runner 'help' do
|
87
|
+
program :help_formatter, :compact
|
88
|
+
command :'install gem' do |c|
|
89
|
+
c.syntax = 'foo install gem [options]'
|
90
|
+
c.summary = 'Install some gem'
|
91
|
+
c.option('--testing-command', 'Testing command')
|
92
|
+
c.option('--testing-command-second', 'Testing command second')
|
93
|
+
end
|
94
|
+
default_command :'install gem'
|
95
|
+
end.run!
|
96
|
+
@global_help = @output.string
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'should display' do
|
100
|
+
it 'the commands label with description for default_command' do
|
101
|
+
expect(@global_help).to include('Commands: (* default)')
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'the command name' do
|
105
|
+
expect(@global_help).to include('install gem')
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'the summary with marked as default_command' do
|
109
|
+
expect(@global_help).to include('* Install some gem')
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'the options label' do
|
113
|
+
expect(@global_help).to include('Options for install gem')
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'the command options' do
|
117
|
+
expect(@global_help).to include('--testing-command')
|
118
|
+
expect(@global_help).to include('--testing-command-second')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe 'without command option' do
|
125
|
+
before :each do
|
126
|
+
new_command_runner 'help' do
|
127
|
+
program :help_formatter, :compact
|
128
|
+
command :'install gem' do |c|
|
129
|
+
c.syntax = 'foo install gem [options]'
|
130
|
+
c.summary = 'Install some gem'
|
131
|
+
end
|
132
|
+
default_command :'install gem'
|
133
|
+
end.run!
|
134
|
+
@global_help = @output.string
|
135
|
+
end
|
136
|
+
|
137
|
+
describe 'should display' do
|
138
|
+
it 'the commands label with description for default_command' do
|
139
|
+
expect(@global_help).to include('Commands: (* default)')
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'the command name' do
|
143
|
+
expect(@global_help).to include('install gem')
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'the summary' do
|
147
|
+
expect(@global_help).to include('* Install some gem')
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe 'should not display' do
|
152
|
+
it 'the options label' do
|
153
|
+
expect(@global_help).not_to include('Options for install gem')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe 'command help' do
|
160
|
+
before :each do
|
161
|
+
new_command_runner 'help', 'install', 'gem' do
|
162
|
+
program :help_formatter, :compact
|
163
|
+
command :'install gem' do |c|
|
164
|
+
c.syntax = 'foo install gem [options]'
|
165
|
+
c.summary = 'Install some gem'
|
166
|
+
c.description = 'Install some gem, blah blah blah'
|
167
|
+
c.example 'one', 'two'
|
168
|
+
c.example 'three', 'four'
|
169
|
+
end
|
170
|
+
end.run!
|
171
|
+
@command_help = @output.string
|
172
|
+
end
|
173
|
+
|
174
|
+
describe 'should display' do
|
175
|
+
it 'the command name' do
|
176
|
+
expect(@command_help).to include('install gem')
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'the description' do
|
180
|
+
expect(@command_help).to include('Install some gem, blah blah blah')
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'all examples' do
|
184
|
+
expect(@command_help).to include('# one')
|
185
|
+
expect(@command_help).to include('two')
|
186
|
+
expect(@command_help).to include('# three')
|
187
|
+
expect(@command_help).to include('four')
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'the syntax' do
|
191
|
+
expect(@command_help).to include('foo install gem [options]')
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Commander::HelpFormatter::Terminal do
|
4
|
+
include Commander::Methods
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
mock_terminal
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'global help' do
|
11
|
+
before :each do
|
12
|
+
new_command_runner 'help' do
|
13
|
+
command :'install gem' do |c|
|
14
|
+
c.syntax = 'foo install gem [options]'
|
15
|
+
c.summary = 'Install some gem'
|
16
|
+
end
|
17
|
+
end.run!
|
18
|
+
@global_help = @output.string
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'should display' do
|
22
|
+
it 'the command name' do
|
23
|
+
expect(@global_help).to include('install gem')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'the summary' do
|
27
|
+
expect(@global_help).to include('Install some gem')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'one space between command name and summary' do
|
31
|
+
expect(@global_help).to include('install gem Install some gem')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'should not display' do
|
36
|
+
it 'the commands label with description for default_command' do
|
37
|
+
expect(@global_help).not_to include("COMMANDS\e[0m: (* default)")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'global help with default_command' do
|
43
|
+
describe 'with command option' do
|
44
|
+
describe 'default_command is before command' do
|
45
|
+
before :each do
|
46
|
+
new_command_runner 'help' do
|
47
|
+
default_command :'install gem'
|
48
|
+
command :'install gem' do |c|
|
49
|
+
c.syntax = 'foo install gem [options]'
|
50
|
+
c.summary = 'Install some gem'
|
51
|
+
c.option('--testing-command', 'Testing command')
|
52
|
+
c.option('--testing-command-second', 'Testing command second')
|
53
|
+
end
|
54
|
+
end.run!
|
55
|
+
@global_help = @output.string
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'should display' do
|
59
|
+
it 'the commands label with description for default_command' do
|
60
|
+
expect(@global_help).to include("COMMANDS\e[0m: (* default)")
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'the command name' do
|
64
|
+
expect(@global_help).to include('install gem')
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'the summary with marked as default_command' do
|
68
|
+
expect(@global_help).to include('* Install some gem')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'the options label' do
|
72
|
+
expect(@global_help).to include('OPTIONS for install gem')
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'the command options' do
|
76
|
+
expect(@global_help).to include('--testing-command')
|
77
|
+
expect(@global_help).to include('--testing-command-second')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'default_command is after command' do
|
83
|
+
before :each do
|
84
|
+
new_command_runner 'help' do
|
85
|
+
command :'install gem' do |c|
|
86
|
+
c.syntax = 'foo install gem [options]'
|
87
|
+
c.summary = 'Install some gem'
|
88
|
+
c.option('--testing-command', 'Testing command')
|
89
|
+
c.option('--testing-command-second', 'Testing command second')
|
90
|
+
end
|
91
|
+
default_command :'install gem'
|
92
|
+
end.run!
|
93
|
+
@global_help = @output.string
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'should display' do
|
97
|
+
it 'the commands label with description for default_command' do
|
98
|
+
expect(@global_help).to include("COMMANDS\e[0m: (* default)")
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'the command name' do
|
102
|
+
expect(@global_help).to include('install gem')
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'the summary with marked as default_command' do
|
106
|
+
expect(@global_help).to include('* Install some gem')
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'the options label' do
|
110
|
+
expect(@global_help).to include('OPTIONS for install gem')
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'the command options' do
|
114
|
+
expect(@global_help).to include('--testing-command')
|
115
|
+
expect(@global_help).to include('--testing-command-second')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe 'without command option' do
|
122
|
+
before :each do
|
123
|
+
new_command_runner 'help' do
|
124
|
+
command :'install gem' do |c|
|
125
|
+
c.syntax = 'foo install gem [options]'
|
126
|
+
c.summary = 'Install some gem'
|
127
|
+
end
|
128
|
+
default_command :'install gem'
|
129
|
+
end.run!
|
130
|
+
@global_help = @output.string
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'should display' do
|
134
|
+
it 'the commands label with description for default_command' do
|
135
|
+
expect(@global_help).to include("COMMANDS\e[0m: (* default)")
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'the command name' do
|
139
|
+
expect(@global_help).to include('install gem')
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'the summary' do
|
143
|
+
expect(@global_help).to include('* Install some gem')
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe 'should not display' do
|
148
|
+
it 'the options label' do
|
149
|
+
expect(@global_help).not_to include('OPTIONS for install gem')
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe 'command help' do
|
156
|
+
before :each do
|
157
|
+
new_command_runner 'help', 'install', 'gem' do
|
158
|
+
command :'install gem' do |c|
|
159
|
+
c.syntax = 'foo install gem [options]'
|
160
|
+
c.summary = 'Install some gem'
|
161
|
+
c.description = 'Install some gem, blah blah blah'
|
162
|
+
c.example 'one', 'two'
|
163
|
+
c.example 'three', 'four'
|
164
|
+
end
|
165
|
+
end.run!
|
166
|
+
@command_help = @output.string
|
167
|
+
end
|
168
|
+
|
169
|
+
describe 'should display' do
|
170
|
+
it 'the command name' do
|
171
|
+
expect(@command_help).to include('install gem')
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'the description' do
|
175
|
+
expect(@command_help).to include('Install some gem, blah blah blah')
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'all examples' do
|
179
|
+
expect(@command_help).to include('# one')
|
180
|
+
expect(@command_help).to include('two')
|
181
|
+
expect(@command_help).to include('# three')
|
182
|
+
expect(@command_help).to include('four')
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'the syntax' do
|
186
|
+
expect(@command_help).to include('foo install gem [options]')
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|