commander 4.1.6 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +4 -0
- data/README.md +37 -0
- data/commander.gemspec +1 -1
- data/lib/commander.rb +2 -0
- data/lib/commander/configure.rb +18 -0
- data/lib/commander/methods.rb +11 -0
- data/lib/commander/runner.rb +2 -3
- data/lib/commander/version.rb +1 -1
- data/spec/command_spec.rb +25 -24
- data/spec/configure_spec.rb +37 -0
- data/spec/core_ext/array_spec.rb +3 -3
- data/spec/core_ext/object_spec.rb +3 -3
- data/spec/help_formatters/terminal_spec.rb +10 -9
- data/spec/methods_spec.rb +20 -0
- data/spec/runner_spec.rb +90 -88
- data/spec/spec_helper.rb +19 -17
- data/spec/ui_spec.rb +4 -3
- metadata +23 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21b09d008c6a8a753877a504afd266191e9d56f1
|
4
|
+
data.tar.gz: eb66a9f050995361aef5eb5abe80b957386547b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f193eb63b1ac9b359c5087ee82db39058b11dfb479ecf562d419bdf7e0dc339ba4ffd47528054a7e6ba67891b43c3210b17d59a8b0eabb201ba4a5c7c81ac87b
|
7
|
+
data.tar.gz: 166c934efdbd6469f8f67d312b1d88758b6158e2116a3179e571f31531efbbf89f9f733eaadde33a972909bc641e1a1d6182c5553b735932678ce1d322330f1c
|
data/History.rdoc
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
[<img src="https://secure.travis-ci.org/ggilder/commander.png?branch=master" alt="Build Status" />](http://travis-ci.org/ggilder/commander)
|
2
|
+
[![Inline docs](http://inch-pages.github.io/github/visionmedia/commander.png)](http://inch-pages.github.io/github/visionmedia/commander)
|
2
3
|
|
3
4
|
# Commander
|
4
5
|
|
@@ -42,6 +43,8 @@ For more option examples view the `Commander::Command#option` method. Also
|
|
42
43
|
an important feature to note is that action may be a class to instantiate,
|
43
44
|
as well as an object, specifying a method to call, so view the RDoc for more information.
|
44
45
|
|
46
|
+
### Classic style
|
47
|
+
|
45
48
|
```ruby
|
46
49
|
require 'rubygems'
|
47
50
|
require 'commander/import'
|
@@ -80,6 +83,40 @@ $ foobar bar --suffix '}' --prefix '{'
|
|
80
83
|
# => {bar}
|
81
84
|
```
|
82
85
|
|
86
|
+
### Modular style
|
87
|
+
```ruby
|
88
|
+
require 'rubygems'
|
89
|
+
require 'commander'
|
90
|
+
|
91
|
+
class MyApplication
|
92
|
+
include Commander::Methods
|
93
|
+
|
94
|
+
def run
|
95
|
+
program :name, 'Foo Bar'
|
96
|
+
program :version, '1.0.0'
|
97
|
+
program :description, 'Stupid command that prints foo or bar.'
|
98
|
+
|
99
|
+
# see classic style example for options
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
MyApplication.new.run if $0 == __FILE__
|
104
|
+
```
|
105
|
+
|
106
|
+
### Block style
|
107
|
+
```ruby
|
108
|
+
require 'rubygems'
|
109
|
+
require 'commander'
|
110
|
+
|
111
|
+
Commander.configure do
|
112
|
+
program :name, 'Foo Bar'
|
113
|
+
program :version, '1.0.0'
|
114
|
+
program :description, 'Stupid command that prints foo or bar.'
|
115
|
+
|
116
|
+
# see classic style example for options
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
83
120
|
## HighLine
|
84
121
|
|
85
122
|
As mentioned above, the highline gem is imported into the global scope. Here
|
data/commander.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.add_runtime_dependency("highline", "~> 1.6.11")
|
23
23
|
|
24
|
-
s.add_development_dependency("rspec", "~> 2")
|
24
|
+
s.add_development_dependency("rspec", "~> 2.14")
|
25
25
|
s.add_development_dependency("rake")
|
26
26
|
s.add_development_dependency("simplecov")
|
27
27
|
end
|
data/lib/commander.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'commander'
|
2
|
+
require 'commander/methods'
|
3
|
+
|
4
|
+
module Commander
|
5
|
+
def configure(*configuration_opts, &configuration_block)
|
6
|
+
configuration_module = Module.new
|
7
|
+
configuration_module.extend Commander::Methods
|
8
|
+
|
9
|
+
configuration_module.class_exec(*configuration_opts, &configuration_block)
|
10
|
+
|
11
|
+
configuration_module.class_exec do
|
12
|
+
run!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module_function :configure
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'commander'
|
2
|
+
require 'commander/delegates'
|
3
|
+
|
4
|
+
module Commander::Methods
|
5
|
+
include Commander::UI
|
6
|
+
include Commander::UI::AskForClass
|
7
|
+
include Commander::Delegates
|
8
|
+
|
9
|
+
$terminal.wrap_at = HighLine::SystemExtensions.terminal_size.first - 5 rescue 80 if $stdin.tty?
|
10
|
+
end
|
11
|
+
|
data/lib/commander/runner.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require 'optparse'
|
3
2
|
|
4
3
|
module Commander
|
@@ -286,11 +285,11 @@ module Commander
|
|
286
285
|
def create_default_commands
|
287
286
|
command :help do |c|
|
288
287
|
c.syntax = 'commander help [command]'
|
289
|
-
c.description = 'Display global or [command] help documentation
|
288
|
+
c.description = 'Display global or [command] help documentation'
|
290
289
|
c.example 'Display global help', 'command help'
|
291
290
|
c.example "Display help for 'foo'", 'command help foo'
|
292
291
|
c.when_called do |args, options|
|
293
|
-
enable_paging
|
292
|
+
UI.enable_paging
|
294
293
|
if args.empty?
|
295
294
|
say help_formatter.render
|
296
295
|
else
|
data/lib/commander/version.rb
CHANGED
data/spec/command_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Commander::Command do
|
4
|
+
include Commander::Methods
|
4
5
|
|
5
6
|
before :each do
|
6
7
|
mock_terminal
|
@@ -15,29 +16,29 @@ describe Commander::Command do
|
|
15
16
|
it "should act like an open struct" do
|
16
17
|
@options.send = 'mail'
|
17
18
|
@options.call = true
|
18
|
-
@options.send.
|
19
|
-
@options.call.
|
19
|
+
expect(@options.send).to eq('mail')
|
20
|
+
expect(@options.call).to eq(true)
|
20
21
|
end
|
21
22
|
|
22
23
|
it "should allow __send__ to function as always" do
|
23
24
|
@options.send = 'foo'
|
24
|
-
@options.__send__(:send).
|
25
|
+
expect(@options.__send__(:send)).to eq('foo')
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
29
|
describe "#option" do
|
29
30
|
it "should add options" do
|
30
|
-
|
31
|
+
expect { @command.option '--recursive' }.to change(@command.options, :length).from(1).to(2)
|
31
32
|
end
|
32
33
|
|
33
34
|
it "should allow procs as option handlers" do
|
34
|
-
@command.option('--recursive') { |recursive| recursive.
|
35
|
+
@command.option('--recursive') { |recursive| expect(recursive).to be_true }
|
35
36
|
@command.run '--recursive'
|
36
37
|
end
|
37
38
|
|
38
39
|
it "should allow usage of common method names" do
|
39
40
|
@command.option '--open file'
|
40
|
-
@command.when_called { |_, options| options.open.
|
41
|
+
@command.when_called { |_, options| expect(options.open).to eq('foo') }
|
41
42
|
@command.run '--open', 'foo'
|
42
43
|
end
|
43
44
|
end
|
@@ -45,50 +46,50 @@ describe Commander::Command do
|
|
45
46
|
describe "#run" do
|
46
47
|
describe "should invoke #when_called" do
|
47
48
|
it "with arguments seperated from options" do
|
48
|
-
@command.when_called { |args, options| args.join(' ').
|
49
|
+
@command.when_called { |args, options| expect(args.join(' ')).to eq('just some args') }
|
49
50
|
@command.run '--verbose', 'just', 'some', 'args'
|
50
51
|
end
|
51
52
|
|
52
53
|
it "calling the #call method by default when an object is called" do
|
53
54
|
object = double 'Object'
|
54
|
-
object.
|
55
|
+
expect(object).to receive(:call).once
|
55
56
|
@command.when_called object
|
56
57
|
@command.run 'foo'
|
57
58
|
end
|
58
59
|
|
59
60
|
it "should allow #action as an alias to #when_called" do
|
60
61
|
object = double 'Object'
|
61
|
-
object.
|
62
|
+
expect(object).to receive(:call).once
|
62
63
|
@command.action object
|
63
64
|
@command.run 'foo'
|
64
65
|
end
|
65
66
|
|
66
67
|
it "calling an arbitrary method when an object is called" do
|
67
68
|
object = double 'Object'
|
68
|
-
object.
|
69
|
+
expect(object).to receive(:foo).once
|
69
70
|
@command.when_called object, :foo
|
70
71
|
@command.run 'foo'
|
71
72
|
end
|
72
73
|
|
73
74
|
it "should raise an error when no handler is present" do
|
74
|
-
|
75
|
+
expect { @command.when_called }.to raise_error(ArgumentError)
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
78
79
|
describe "should populate options with" do
|
79
80
|
it "boolean values" do
|
80
81
|
@command.option '--[no-]toggle'
|
81
|
-
@command.when_called { |_, options| options.toggle.
|
82
|
+
@command.when_called { |_, options| expect(options.toggle).to be_true }
|
82
83
|
@command.run '--toggle'
|
83
|
-
@command.when_called { |_, options| options.toggle.
|
84
|
+
@command.when_called { |_, options| expect(options.toggle).to be_false }
|
84
85
|
@command.run '--no-toggle'
|
85
86
|
end
|
86
87
|
|
87
88
|
it "mandatory arguments" do
|
88
89
|
@command.option '--file FILE'
|
89
|
-
@command.when_called { |_, options| options.file.
|
90
|
+
@command.when_called { |_, options| expect(options.file).to eq('foo') }
|
90
91
|
@command.run '--file', 'foo'
|
91
|
-
|
92
|
+
expect { @command.run '--file' }.to raise_error(OptionParser::MissingArgument)
|
92
93
|
end
|
93
94
|
|
94
95
|
describe "optional arguments" do
|
@@ -97,17 +98,17 @@ describe Commander::Command do
|
|
97
98
|
end
|
98
99
|
|
99
100
|
it "should return the argument when provided" do
|
100
|
-
@command.when_called { |_, options| options.use_config.
|
101
|
+
@command.when_called { |_, options| expect(options.use_config).to eq('foo') }
|
101
102
|
@command.run '--use-config', 'foo'
|
102
103
|
end
|
103
104
|
|
104
105
|
it "should return true when present without an argument" do
|
105
|
-
@command.when_called { |_, options| options.use_config.
|
106
|
+
@command.when_called { |_, options| expect(options.use_config).to be_true }
|
106
107
|
@command.run '--use-config'
|
107
108
|
end
|
108
109
|
|
109
110
|
it "should return nil when not present" do
|
110
|
-
@command.when_called { |_, options| options.use_config.
|
111
|
+
@command.when_called { |_, options| expect(options.use_config).to be_nil }
|
111
112
|
@command.run
|
112
113
|
end
|
113
114
|
end
|
@@ -118,24 +119,24 @@ describe Commander::Command do
|
|
118
119
|
end
|
119
120
|
|
120
121
|
it "should parse valid values" do
|
121
|
-
@command.when_called { |_, options| options.interval.
|
122
|
+
@command.when_called { |_, options| expect(options.interval).to eq(5) }
|
122
123
|
@command.run '--interval', '5'
|
123
124
|
end
|
124
125
|
|
125
126
|
it "should reject invalid values" do
|
126
|
-
|
127
|
+
expect { @command.run '--interval', 'invalid' }.to raise_error(OptionParser::InvalidArgument)
|
127
128
|
end
|
128
129
|
end
|
129
130
|
|
130
131
|
it "lists" do
|
131
132
|
@command.option '--fav COLORS', Array
|
132
|
-
@command.when_called { |_, options| options.fav.
|
133
|
+
@command.when_called { |_, options| expect(options.fav).to eq(['red', 'green', 'blue']) }
|
133
134
|
@command.run '--fav', 'red,green,blue'
|
134
135
|
end
|
135
136
|
|
136
137
|
it "lists with multi-word items" do
|
137
138
|
@command.option '--fav MOVIES', Array
|
138
|
-
@command.when_called { |_, options| options.fav.
|
139
|
+
@command.when_called { |_, options| expect(options.fav).to eq(['super\ bad', 'nightmare']) }
|
139
140
|
@command.run '--fav', 'super\ bad,nightmare'
|
140
141
|
end
|
141
142
|
|
@@ -146,8 +147,8 @@ describe Commander::Command do
|
|
146
147
|
options.default \
|
147
148
|
:files => ['foo', 'bar'],
|
148
149
|
:interval => 5
|
149
|
-
options.files.
|
150
|
-
options.interval.
|
150
|
+
expect(options.files).to eq(['foo', 'bar'])
|
151
|
+
expect(options.interval).to eq(15)
|
151
152
|
end
|
152
153
|
@command.run '--interval', '15'
|
153
154
|
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 {
|
17
|
+
program :name, 'test'
|
18
|
+
}
|
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') { |first_arg|
|
25
|
+
program :name, first_arg
|
26
|
+
}
|
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
|
data/spec/core_ext/array_spec.rb
CHANGED
@@ -4,16 +4,16 @@ describe Array do
|
|
4
4
|
|
5
5
|
describe "#parse" do
|
6
6
|
it "should seperate a list of words into an array" do
|
7
|
-
Array.parse('just a test').
|
7
|
+
expect(Array.parse('just a test')).to eq(['just', 'a', 'test'])
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should preserve escaped whitespace" do
|
11
|
-
Array.parse('just a\ test').
|
11
|
+
expect(Array.parse('just a\ test')).to eq(['just', 'a test'])
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should match %w behavior with multiple backslashes" do
|
15
15
|
str = 'just a\\ test'
|
16
|
-
Array.parse(str).
|
16
|
+
expect(Array.parse(str)).to eq(eval("%w(#{str})"))
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -4,17 +4,17 @@ describe Object do
|
|
4
4
|
|
5
5
|
describe "#get_binding" do
|
6
6
|
it "should return the objects binding" do
|
7
|
-
lambda {}.get_binding.
|
7
|
+
expect(lambda {}.get_binding).to be_instance_of(Binding)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#method_missing" do
|
12
12
|
it "should preserve its original behavior for missing methods" do
|
13
|
-
|
13
|
+
expect { i_am_a_missing_method() }.to raise_error(NoMethodError)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should preserve its original behavior for missing variables" do
|
17
|
-
|
17
|
+
expect { i_am_a_missing_variable }.to raise_error(NameError)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Commander::HelpFormatter::Terminal do
|
4
|
+
include Commander::Methods
|
4
5
|
|
5
6
|
before :each do
|
6
7
|
mock_terminal
|
@@ -19,11 +20,11 @@ describe Commander::HelpFormatter::Terminal do
|
|
19
20
|
|
20
21
|
describe "should display" do
|
21
22
|
it "the command name" do
|
22
|
-
@global_help.
|
23
|
+
expect(@global_help).to include('install gem')
|
23
24
|
end
|
24
25
|
|
25
26
|
it "the summary" do
|
26
|
-
@global_help.
|
27
|
+
expect(@global_help).to include('Install some gem')
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
@@ -44,22 +45,22 @@ describe Commander::HelpFormatter::Terminal do
|
|
44
45
|
|
45
46
|
describe "should display" do
|
46
47
|
it "the command name" do
|
47
|
-
@command_help.
|
48
|
+
expect(@command_help).to include('install gem')
|
48
49
|
end
|
49
50
|
|
50
51
|
it "the description" do
|
51
|
-
@command_help.
|
52
|
+
expect(@command_help).to include('Install some gem, blah blah blah')
|
52
53
|
end
|
53
54
|
|
54
55
|
it "all examples" do
|
55
|
-
@command_help.
|
56
|
-
@command_help.
|
57
|
-
@command_help.
|
58
|
-
@command_help.
|
56
|
+
expect(@command_help).to include('# one')
|
57
|
+
expect(@command_help).to include('two')
|
58
|
+
expect(@command_help).to include('# three')
|
59
|
+
expect(@command_help).to include('four')
|
59
60
|
end
|
60
61
|
|
61
62
|
it "the syntax" do
|
62
|
-
@command_help.
|
63
|
+
expect(@command_help).to include('foo install gem [options]')
|
63
64
|
end
|
64
65
|
end
|
65
66
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'commander/methods'
|
3
|
+
|
4
|
+
describe Commander::Methods do
|
5
|
+
it 'includes Commander::UI' do
|
6
|
+
expect(subject.ancestors).to include(Commander::UI)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'includes Commander::UI::AskForClass' do
|
10
|
+
expect(subject.ancestors).to include(Commander::UI::AskForClass)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'includes Commander::Delegates' do
|
14
|
+
expect(subject.ancestors).to include(Commander::Delegates)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'does not change the Object ancestors' do
|
18
|
+
expect(Object.ancestors).not_to include(Commander::UI)
|
19
|
+
end
|
20
|
+
end
|
data/spec/runner_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Commander do
|
4
|
+
include Commander::Methods
|
5
|
+
|
4
6
|
before :each do
|
5
7
|
$stderr = StringIO.new
|
6
8
|
mock_terminal
|
@@ -10,59 +12,59 @@ describe Commander do
|
|
10
12
|
describe "#program" do
|
11
13
|
it "should set / get program information" do
|
12
14
|
program :name, 'test'
|
13
|
-
program(:name).
|
15
|
+
expect(program(:name)).to eq('test')
|
14
16
|
end
|
15
17
|
|
16
18
|
it "should allow arbitrary blocks of global help documentation" do
|
17
19
|
program :help, 'Copyright', 'TJ Holowaychuk'
|
18
|
-
program(:help)['Copyright'].
|
20
|
+
expect(program(:help)['Copyright']).to eq('TJ Holowaychuk')
|
19
21
|
end
|
20
22
|
|
21
23
|
it "should raise an error when required info has not been set" do
|
22
24
|
new_command_runner '--help'
|
23
25
|
program :version, ''
|
24
|
-
|
26
|
+
expect { run! }.to raise_error(Commander::Runner::CommandError)
|
25
27
|
end
|
26
28
|
|
27
29
|
it "should allow aliases of help formatters" do
|
28
30
|
program :help_formatter, :compact
|
29
|
-
program(:help_formatter).
|
31
|
+
expect(program(:help_formatter)).to eq(Commander::HelpFormatter::TerminalCompact)
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
35
|
describe "#command" do
|
34
36
|
it "should return a command instance when only the name is passed" do
|
35
|
-
command(:test).
|
37
|
+
expect(command(:test)).to be_instance_of(Commander::Command)
|
36
38
|
end
|
37
39
|
|
38
40
|
it "should return nil when the command does not exist" do
|
39
|
-
command(:im_not_real).
|
41
|
+
expect(command(:im_not_real)).to be_nil
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
45
|
describe "#separate_switches_from_description" do
|
44
46
|
it "should seperate switches and description returning both" do
|
45
47
|
switches, description = *Commander::Runner.separate_switches_from_description('-h', '--help', 'display help')
|
46
|
-
switches.
|
47
|
-
description.
|
48
|
+
expect(switches).to eq(['-h', '--help'])
|
49
|
+
expect(description).to eq('display help')
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
53
|
describe "#switch_to_sym" do
|
52
54
|
it "should return a symbol based on the switch name" do
|
53
|
-
Commander::Runner.switch_to_sym('--trace').
|
54
|
-
Commander::Runner.switch_to_sym('--foo-bar').
|
55
|
-
Commander::Runner.switch_to_sym('--[no-]feature"').
|
56
|
-
Commander::Runner.switch_to_sym('--[no-]feature ARG').
|
57
|
-
Commander::Runner.switch_to_sym('--file [ARG]').
|
58
|
-
Commander::Runner.switch_to_sym('--colors colors').
|
55
|
+
expect(Commander::Runner.switch_to_sym('--trace')).to eq(:trace)
|
56
|
+
expect(Commander::Runner.switch_to_sym('--foo-bar')).to eq(:foo_bar)
|
57
|
+
expect(Commander::Runner.switch_to_sym('--[no-]feature"')).to eq(:feature)
|
58
|
+
expect(Commander::Runner.switch_to_sym('--[no-]feature ARG')).to eq(:feature)
|
59
|
+
expect(Commander::Runner.switch_to_sym('--file [ARG]')).to eq(:file)
|
60
|
+
expect(Commander::Runner.switch_to_sym('--colors colors')).to eq(:colors)
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
62
64
|
describe "#alias_command" do
|
63
65
|
it "should alias a command" do
|
64
66
|
alias_command :foo, :test
|
65
|
-
command(:foo).
|
67
|
+
expect(command(:foo)).to eq(command(:test))
|
66
68
|
end
|
67
69
|
|
68
70
|
it "should pass arguments passed to the alias when called" do
|
@@ -74,7 +76,7 @@ describe Commander do
|
|
74
76
|
end
|
75
77
|
alias_command :'install gem', :install, '--gem-name'
|
76
78
|
end.run!
|
77
|
-
gem_name.
|
79
|
+
expect(gem_name).to eq('commander')
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
@@ -84,7 +86,7 @@ describe Commander do
|
|
84
86
|
new_command_runner 'test', '--config', 'foo' do
|
85
87
|
global_option('--config FILE') { |f| file = f }
|
86
88
|
end.run!
|
87
|
-
file.
|
89
|
+
expect(file).to eq('foo')
|
88
90
|
end
|
89
91
|
|
90
92
|
it "should be inherited by commands" do
|
@@ -95,7 +97,7 @@ describe Commander do
|
|
95
97
|
c.when_called { |_, options| quiet = options.quiet }
|
96
98
|
end
|
97
99
|
end.run!
|
98
|
-
quiet.
|
100
|
+
expect(quiet).to be_true
|
99
101
|
end
|
100
102
|
|
101
103
|
it "should be inherited by commands even when a block is present" do
|
@@ -106,7 +108,7 @@ describe Commander do
|
|
106
108
|
c.when_called { |_, options| quiet = options.quiet }
|
107
109
|
end
|
108
110
|
end.run!
|
109
|
-
quiet.
|
111
|
+
expect(quiet).to be_true
|
110
112
|
end
|
111
113
|
end
|
112
114
|
|
@@ -120,7 +122,7 @@ describe Commander do
|
|
120
122
|
c.when_called {}
|
121
123
|
end
|
122
124
|
end.run!
|
123
|
-
global_option.
|
125
|
+
expect(global_option).to eq('MAGIC')
|
124
126
|
end
|
125
127
|
|
126
128
|
it 'should parse global options after command' do
|
@@ -132,7 +134,7 @@ describe Commander do
|
|
132
134
|
c.when_called {}
|
133
135
|
end
|
134
136
|
end.run!
|
135
|
-
global_option.
|
137
|
+
expect(global_option).to eq('MAGIC')
|
136
138
|
end
|
137
139
|
|
138
140
|
it 'should parse global options placed before command options' do
|
@@ -146,7 +148,7 @@ describe Commander do
|
|
146
148
|
end
|
147
149
|
end.run!
|
148
150
|
|
149
|
-
global_option.
|
151
|
+
expect(global_option).to eq('MAGIC')
|
150
152
|
end
|
151
153
|
|
152
154
|
it 'should parse global options placed after command options' do
|
@@ -160,7 +162,7 @@ describe Commander do
|
|
160
162
|
end
|
161
163
|
end.run!
|
162
164
|
|
163
|
-
global_option.
|
165
|
+
expect(global_option).to eq('MAGIC')
|
164
166
|
end
|
165
167
|
|
166
168
|
it 'should parse global options surrounded by command options' do
|
@@ -175,7 +177,7 @@ describe Commander do
|
|
175
177
|
end
|
176
178
|
end.run!
|
177
179
|
|
178
|
-
global_option.
|
180
|
+
expect(global_option).to eq('MAGIC')
|
179
181
|
end
|
180
182
|
|
181
183
|
it 'should not parse command options' do
|
@@ -190,8 +192,8 @@ describe Commander do
|
|
190
192
|
end
|
191
193
|
end.parse_global_options
|
192
194
|
|
193
|
-
command_option.
|
194
|
-
global_option.
|
195
|
+
expect(command_option).to be_nil
|
196
|
+
expect(global_option).to eq('MAGIC')
|
195
197
|
end
|
196
198
|
|
197
199
|
it 'should not affect command arguments with values' do
|
@@ -206,8 +208,8 @@ describe Commander do
|
|
206
208
|
end
|
207
209
|
end.run!
|
208
210
|
|
209
|
-
command_option.
|
210
|
-
global_option.
|
211
|
+
expect(command_option).to eq('bar')
|
212
|
+
expect(global_option).to eq('MAGIC')
|
211
213
|
end
|
212
214
|
|
213
215
|
it 'should not affect global arguments with values' do
|
@@ -221,7 +223,7 @@ describe Commander do
|
|
221
223
|
end
|
222
224
|
end.run!
|
223
225
|
|
224
|
-
global_option.
|
226
|
+
expect(global_option).to eq('bar')
|
225
227
|
end
|
226
228
|
|
227
229
|
it 'should allow global arguments with values before command arguments (github issue #8)' do
|
@@ -236,8 +238,8 @@ describe Commander do
|
|
236
238
|
end
|
237
239
|
end.run!
|
238
240
|
|
239
|
-
global_option.
|
240
|
-
command_option.
|
241
|
+
expect(global_option).to eq('path')
|
242
|
+
expect(command_option).to eq('bar')
|
241
243
|
end
|
242
244
|
end
|
243
245
|
|
@@ -254,7 +256,7 @@ describe Commander do
|
|
254
256
|
args << '--command-with-arg' << 'rawr'
|
255
257
|
args << '--paths' << '"lib/**/*.js","spec/**/*.js"'
|
256
258
|
command_runner.remove_global_options options, args
|
257
|
-
args.
|
259
|
+
expect(args).to eq(['--command', '--command-with-arg', 'rawr'])
|
258
260
|
end
|
259
261
|
|
260
262
|
it "should not swallow an argument unless it expects an argument" do
|
@@ -267,47 +269,47 @@ describe Commander do
|
|
267
269
|
args << '-a' << 'deleted'
|
268
270
|
args << 'beta'
|
269
271
|
command_runner.remove_global_options options, args
|
270
|
-
args.
|
272
|
+
expect(args).to eq(['alpha', 'beta'])
|
271
273
|
end
|
272
274
|
end
|
273
275
|
|
274
276
|
describe "--trace" do
|
275
277
|
it "should display pretty errors by default" do
|
276
278
|
pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
|
277
|
-
|
279
|
+
expect {
|
278
280
|
new_command_runner 'foo' do
|
279
281
|
command(:foo) { |c| c.when_called { raise 'cookies!' } }
|
280
282
|
end.run!
|
281
|
-
}.
|
283
|
+
}.to raise_error(SystemExit, /error: cookies!. Use --trace/)
|
282
284
|
end
|
283
285
|
|
284
286
|
it "should display callstack when using this switch" do
|
285
|
-
|
287
|
+
expect {
|
286
288
|
new_command_runner 'foo', '--trace' do
|
287
289
|
command(:foo) { |c| c.when_called { raise 'cookies!' } }
|
288
290
|
end.run!
|
289
|
-
}.
|
291
|
+
}.to raise_error(RuntimeError)
|
290
292
|
end
|
291
293
|
end
|
292
294
|
|
293
295
|
describe "#always_trace!" do
|
294
296
|
it "should enable tracing globally, regardless of whether --trace was passed or not" do
|
295
|
-
|
297
|
+
expect {
|
296
298
|
new_command_runner 'foo' do
|
297
299
|
always_trace!
|
298
300
|
command(:foo) { |c| c.when_called { raise 'cookies!' } }
|
299
301
|
end.run!
|
300
|
-
}.
|
302
|
+
}.to raise_error(RuntimeError)
|
301
303
|
end
|
302
304
|
end
|
303
305
|
|
304
306
|
describe "#never_trace!" do
|
305
307
|
it "should disable tracing globally, regardless of whether --trace was passed or not" do
|
306
|
-
|
308
|
+
expect {
|
307
309
|
new_command_runner 'help', '--trace' do
|
308
310
|
never_trace!
|
309
311
|
end.run!
|
310
|
-
}.
|
312
|
+
}.to raise_error(SystemExit, /invalid option: --trace/)
|
311
313
|
end
|
312
314
|
|
313
315
|
it "should not prompt to use --trace switch on errors" do
|
@@ -320,81 +322,81 @@ describe Commander do
|
|
320
322
|
rescue SystemExit => e
|
321
323
|
msg = e.message
|
322
324
|
end
|
323
|
-
msg.
|
324
|
-
msg.
|
325
|
+
expect(msg).to match(/error: cookies!/)
|
326
|
+
expect(msg).not_to match(/--trace/)
|
325
327
|
end
|
326
328
|
end
|
327
329
|
|
328
330
|
context "conflict between #always_trace! and #never_trace!" do
|
329
331
|
it "respects the last used command" do
|
330
|
-
|
332
|
+
expect {
|
331
333
|
new_command_runner 'foo' do
|
332
334
|
never_trace!
|
333
335
|
always_trace!
|
334
336
|
command(:foo) { |c| c.when_called { raise 'cookies!' } }
|
335
337
|
end.run!
|
336
|
-
}.
|
338
|
+
}.to raise_error(RuntimeError)
|
337
339
|
end
|
338
340
|
end
|
339
341
|
|
340
342
|
describe "--version" do
|
341
343
|
it "should output program version" do
|
342
|
-
run('--version').
|
344
|
+
expect(run('--version')).to eq("test 1.2.3\n")
|
343
345
|
end
|
344
346
|
end
|
345
347
|
|
346
348
|
describe "--help" do
|
347
349
|
it "should not output an invalid command message" do
|
348
|
-
run('--help').
|
350
|
+
expect(run('--help')).not_to eq("invalid command. Use --help for more information\n")
|
349
351
|
end
|
350
352
|
|
351
353
|
it "can be used before or after the command and options" do
|
352
|
-
run('test', '--help').
|
354
|
+
expect(run('test', '--help')).to eq("Implement help for test here\n")
|
353
355
|
end
|
354
356
|
end
|
355
357
|
|
356
358
|
describe "with invalid options" do
|
357
359
|
it "should output an invalid option message" do
|
358
360
|
pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
|
359
|
-
|
361
|
+
expect {
|
360
362
|
run('test', '--invalid-option')
|
361
|
-
}.
|
363
|
+
}.to raise_error(SystemExit, /invalid option: --invalid-option/)
|
362
364
|
end
|
363
365
|
end
|
364
366
|
|
365
367
|
describe "with invalid command passed" do
|
366
368
|
it "should output an invalid command message" do
|
367
369
|
pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
|
368
|
-
|
370
|
+
expect {
|
369
371
|
run('foo')
|
370
|
-
}.
|
372
|
+
}.to raise_error(SystemExit, /invalid command. Use --help for more information/)
|
371
373
|
end
|
372
374
|
end
|
373
375
|
|
374
376
|
describe "with invalid command passed to help" do
|
375
377
|
it "should output an invalid command message" do
|
376
378
|
pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
|
377
|
-
|
379
|
+
expect {
|
378
380
|
run('help', 'does_not_exist')
|
379
|
-
}.
|
381
|
+
}.to raise_error(SystemExit, /invalid command. Use --help for more information/)
|
380
382
|
end
|
381
383
|
end
|
382
384
|
|
383
385
|
describe "with invalid command passed to --help" do
|
384
386
|
it "should output an invalid command message" do
|
385
387
|
pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
|
386
|
-
|
388
|
+
expect {
|
387
389
|
run('--help', 'does_not_exist')
|
388
|
-
}.
|
390
|
+
}.to raise_error(SystemExit, /invalid command. Use --help for more information/)
|
389
391
|
end
|
390
392
|
end
|
391
393
|
|
392
394
|
describe "with invalid option passed to --help" do
|
393
395
|
it "should output an invalid option message" do
|
394
396
|
pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
|
395
|
-
|
397
|
+
expect {
|
396
398
|
run('--help', 'test', '--invalid-option')
|
397
|
-
}.
|
399
|
+
}.to raise_error(SystemExit, /invalid option: --invalid-option/)
|
398
400
|
end
|
399
401
|
end
|
400
402
|
|
@@ -403,20 +405,20 @@ describe Commander do
|
|
403
405
|
new_command_runner do
|
404
406
|
command('foo bar') {}
|
405
407
|
command('foo bar foo') {}
|
406
|
-
command_runner.valid_command_names_from('foo', 'bar', 'foo').sort.
|
408
|
+
expect(command_runner.valid_command_names_from('foo', 'bar', 'foo').sort).to eq(['foo bar', 'foo bar foo'])
|
407
409
|
end
|
408
410
|
end
|
409
411
|
|
410
412
|
it "should return empty array when no possible command names exist" do
|
411
413
|
new_command_runner do
|
412
|
-
command_runner.valid_command_names_from('fake', 'command', 'name').
|
414
|
+
expect(command_runner.valid_command_names_from('fake', 'command', 'name')).to eq([])
|
413
415
|
end
|
414
416
|
end
|
415
417
|
|
416
418
|
it "should match exact commands only" do
|
417
419
|
new_command_runner do
|
418
420
|
command('foo') {}
|
419
|
-
command_runner.valid_command_names_from('foobar').
|
421
|
+
expect(command_runner.valid_command_names_from('foobar')).to eq([])
|
420
422
|
end
|
421
423
|
end
|
422
424
|
end
|
@@ -424,42 +426,42 @@ describe Commander do
|
|
424
426
|
describe "#command_name_from_args" do
|
425
427
|
it "should locate command within arbitrary arguments passed" do
|
426
428
|
new_command_runner '--help', '--arbitrary', 'test'
|
427
|
-
command_runner.command_name_from_args.
|
429
|
+
expect(command_runner.command_name_from_args).to eq('test')
|
428
430
|
end
|
429
431
|
|
430
432
|
it "should support multi-word commands" do
|
431
433
|
new_command_runner '--help', '--arbitrary', 'some', 'long', 'command', 'foo'
|
432
434
|
command('some long command') {}
|
433
|
-
command_runner.command_name_from_args.
|
435
|
+
expect(command_runner.command_name_from_args).to eq('some long command')
|
434
436
|
end
|
435
437
|
|
436
438
|
it "should match the longest possible command" do
|
437
439
|
new_command_runner '--help', '--arbitrary', 'foo', 'bar', 'foo'
|
438
440
|
command('foo bar') {}
|
439
441
|
command('foo bar foo') {}
|
440
|
-
command_runner.command_name_from_args.
|
442
|
+
expect(command_runner.command_name_from_args).to eq('foo bar foo' )
|
441
443
|
end
|
442
444
|
|
443
445
|
it "should use the left-most command name when multiple are present" do
|
444
446
|
new_command_runner 'help', 'test'
|
445
|
-
command_runner.command_name_from_args.
|
447
|
+
expect(command_runner.command_name_from_args).to eq('help' )
|
446
448
|
end
|
447
449
|
end
|
448
450
|
|
449
451
|
describe "#active_command" do
|
450
452
|
it "should resolve the active command" do
|
451
453
|
new_command_runner '--help', 'test'
|
452
|
-
command_runner.active_command.
|
454
|
+
expect(command_runner.active_command).to be_instance_of(Commander::Command)
|
453
455
|
end
|
454
456
|
|
455
457
|
it "should resolve active command when invalid options are passed" do
|
456
458
|
new_command_runner '--help', 'test', '--arbitrary'
|
457
|
-
command_runner.active_command.
|
459
|
+
expect(command_runner.active_command).to be_instance_of(Commander::Command)
|
458
460
|
end
|
459
461
|
|
460
462
|
it "should return nil when the command is not found" do
|
461
463
|
new_command_runner 'foo'
|
462
|
-
command_runner.active_command.
|
464
|
+
expect(command_runner.active_command).to be_nil
|
463
465
|
end
|
464
466
|
end
|
465
467
|
|
@@ -467,8 +469,8 @@ describe Commander do
|
|
467
469
|
it "should allow you to default any command when one is not explicitly passed" do
|
468
470
|
new_command_runner '--trace' do
|
469
471
|
default_command :test
|
470
|
-
command(:test).
|
471
|
-
command_runner.active_command.
|
472
|
+
expect(command(:test)).to receive(:run).once
|
473
|
+
expect(command_runner.active_command).to eq(command(:test))
|
472
474
|
end.run!
|
473
475
|
end
|
474
476
|
|
@@ -476,8 +478,8 @@ describe Commander do
|
|
476
478
|
new_command_runner 'foo', 'bar', '--trace' do
|
477
479
|
default_command :test
|
478
480
|
command(:'foo bar'){}
|
479
|
-
command(:'foo bar').
|
480
|
-
command_runner.active_command.
|
481
|
+
expect(command(:'foo bar')).to receive(:run).once
|
482
|
+
expect(command_runner.active_command).to eq(command(:'foo bar'))
|
481
483
|
end.run!
|
482
484
|
end
|
483
485
|
|
@@ -486,14 +488,14 @@ describe Commander do
|
|
486
488
|
default_command :'foo bar'
|
487
489
|
command(:'foo bar'){}
|
488
490
|
command(:'foo bar something'){}
|
489
|
-
command_runner.active_command.
|
491
|
+
expect(command_runner.active_command).to eq(command(:'foo bar something'))
|
490
492
|
end
|
491
493
|
|
492
494
|
it "should allow defaulting of command aliases" do
|
493
495
|
new_command_runner '--trace' do
|
494
496
|
default_command :foobar
|
495
497
|
alias_command :foobar, :test
|
496
|
-
command(:test).
|
498
|
+
expect(command(:test)).to receive(:run).once
|
497
499
|
end.run!
|
498
500
|
end
|
499
501
|
end
|
@@ -502,8 +504,8 @@ describe Commander do
|
|
502
504
|
it "when options are passed before the command name" do
|
503
505
|
new_command_runner '--verbose', 'test', 'foo', 'bar' do
|
504
506
|
@command.when_called do |args, options|
|
505
|
-
args.
|
506
|
-
options.verbose.
|
507
|
+
expect(args).to eq(['foo', 'bar'])
|
508
|
+
expect(options.verbose).to be_true
|
507
509
|
end
|
508
510
|
end.run!
|
509
511
|
end
|
@@ -511,8 +513,8 @@ describe Commander do
|
|
511
513
|
it "when options are passed after the command name" do
|
512
514
|
new_command_runner 'test', '--verbose', 'foo', 'bar' do
|
513
515
|
@command.when_called do |args, options|
|
514
|
-
args.
|
515
|
-
options.verbose.
|
516
|
+
expect(args).to eq(['foo', 'bar'])
|
517
|
+
expect(options.verbose).to be_true
|
516
518
|
end
|
517
519
|
end.run!
|
518
520
|
end
|
@@ -520,8 +522,8 @@ describe Commander do
|
|
520
522
|
it "when an argument passed is the same name as the command" do
|
521
523
|
new_command_runner 'test', '--verbose', 'foo', 'test', 'bar' do
|
522
524
|
@command.when_called do |args, options|
|
523
|
-
args.
|
524
|
-
options.verbose.
|
525
|
+
expect(args).to eq(['foo', 'test', 'bar'])
|
526
|
+
expect(options.verbose).to be_true
|
525
527
|
end
|
526
528
|
end.run!
|
527
529
|
end
|
@@ -529,16 +531,16 @@ describe Commander do
|
|
529
531
|
it "when using multi-word commands" do
|
530
532
|
new_command_runner '--verbose', 'my', 'command', 'something', 'foo', 'bar' do
|
531
533
|
command('my command') { |c| c.option('--verbose') }
|
532
|
-
command_runner.command_name_from_args.
|
533
|
-
command_runner.args_without_command_name.
|
534
|
+
expect(command_runner.command_name_from_args).to eq('my command')
|
535
|
+
expect(command_runner.args_without_command_name).to eq(['--verbose', 'something', 'foo', 'bar'])
|
534
536
|
end.run!
|
535
537
|
end
|
536
538
|
|
537
539
|
it "when using multi-word commands with parts of the command name as arguments" do
|
538
540
|
new_command_runner '--verbose', 'my', 'command', 'something', 'my', 'command' do
|
539
541
|
command('my command') { |c| c.option('--verbose') }
|
540
|
-
command_runner.command_name_from_args.
|
541
|
-
command_runner.args_without_command_name.
|
542
|
+
expect(command_runner.command_name_from_args).to eq('my command')
|
543
|
+
expect(command_runner.args_without_command_name).to eq(['--verbose', 'something', 'my', 'command'])
|
542
544
|
end.run!
|
543
545
|
end
|
544
546
|
|
@@ -546,8 +548,8 @@ describe Commander do
|
|
546
548
|
new_command_runner '--verbose', 'my', 'command', 'something', 'my', 'command' do
|
547
549
|
command('my command') {}
|
548
550
|
command('my command something') { |c| c.option('--verbose') }
|
549
|
-
command_runner.command_name_from_args.
|
550
|
-
command_runner.args_without_command_name.
|
551
|
+
expect(command_runner.command_name_from_args).to eq('my command something')
|
552
|
+
expect(command_runner.args_without_command_name).to eq(['--verbose', 'my', 'command'])
|
551
553
|
end.run!
|
552
554
|
end
|
553
555
|
end
|
@@ -558,7 +560,7 @@ describe Commander do
|
|
558
560
|
command('foo') do |c|
|
559
561
|
c.option('--optional [argument]')
|
560
562
|
c.when_called do |_, options|
|
561
|
-
options.optional.
|
563
|
+
expect(options.optional).to eq('arg1')
|
562
564
|
end
|
563
565
|
end
|
564
566
|
end.run!
|
@@ -569,7 +571,7 @@ describe Commander do
|
|
569
571
|
command('foo') do |c|
|
570
572
|
c.option('--optional [argument]')
|
571
573
|
c.when_called do |_, options|
|
572
|
-
options.optional.
|
574
|
+
expect(options.optional).to be_true
|
573
575
|
end
|
574
576
|
end
|
575
577
|
end.run!
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'stringio'
|
3
3
|
require 'simplecov'
|
4
|
-
SimpleCov.start
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter "/spec/"
|
6
|
+
end
|
5
7
|
|
6
8
|
# Unshift so that local files load instead of something in gems
|
7
9
|
$:.unshift File.dirname(__FILE__) + '/../lib'
|
@@ -9,21 +11,7 @@ $:.unshift File.dirname(__FILE__) + '/../lib'
|
|
9
11
|
# This basically replicates the behavior of `require 'commander/import'`
|
10
12
|
# but without adding an `at_exit` hook, which interferes with exit code
|
11
13
|
require 'commander'
|
12
|
-
require 'commander/
|
13
|
-
|
14
|
-
include Commander::UI
|
15
|
-
include Commander::UI::AskForClass
|
16
|
-
include Commander::Delegates
|
17
|
-
|
18
|
-
# prevent paging from actually occurring in test environment
|
19
|
-
|
20
|
-
module Commander
|
21
|
-
module UI
|
22
|
-
def enable_paging
|
23
|
-
return
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
14
|
+
require 'commander/methods'
|
27
15
|
|
28
16
|
# Mock terminal IO streams so we can spec against them
|
29
17
|
|
@@ -72,4 +60,18 @@ def run *args
|
|
72
60
|
program :help_formatter, Commander::HelpFormatter::Base
|
73
61
|
end.run!
|
74
62
|
@output.string
|
75
|
-
end
|
63
|
+
end
|
64
|
+
|
65
|
+
RSpec.configure do |c|
|
66
|
+
c.expect_with(:rspec) do |e|
|
67
|
+
e.syntax = :expect
|
68
|
+
end
|
69
|
+
|
70
|
+
c.mock_with(:rspec) do |m|
|
71
|
+
m.syntax = :expect
|
72
|
+
end
|
73
|
+
|
74
|
+
c.before(:each) do
|
75
|
+
allow(Commander::UI).to receive(:enable_paging)
|
76
|
+
end
|
77
|
+
end
|
data/spec/ui_spec.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Commander::UI do
|
4
|
+
include Commander::Methods
|
4
5
|
|
5
6
|
describe ".replace_tokens" do
|
6
7
|
it "should replace tokens within a string, with hash values" do
|
7
8
|
result = Commander::UI.replace_tokens 'Welcome :name, enjoy your :object'.freeze, :name => 'TJ', :object => 'cookie'
|
8
|
-
result.
|
9
|
+
expect(result).to eq('Welcome TJ, enjoy your cookie')
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
@@ -17,13 +18,13 @@ describe Commander::UI do
|
|
17
18
|
rescue
|
18
19
|
exception = true
|
19
20
|
end
|
20
|
-
exception.
|
21
|
+
expect(exception).not_to be_true
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
describe ".available_editor" do
|
25
26
|
it "should not fail on available editors with shell arguments" do
|
26
|
-
Commander::UI.available_editor('sh -c').
|
27
|
+
expect(Commander::UI.available_editor('sh -c')).to eq('sh -c')
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
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.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TJ Holowaychuk
|
@@ -9,62 +9,62 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: highline
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 1.6.11
|
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
27
|
version: 1.6.11
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rspec
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - ~>
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '2'
|
34
|
+
version: '2.14'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - ~>
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '2'
|
41
|
+
version: '2.14'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: simplecov
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
description: The complete solution for Ruby command-line executables. Commander bridges
|
@@ -77,8 +77,8 @@ executables:
|
|
77
77
|
extensions: []
|
78
78
|
extra_rdoc_files: []
|
79
79
|
files:
|
80
|
-
- .gitignore
|
81
|
-
- .travis.yml
|
80
|
+
- ".gitignore"
|
81
|
+
- ".travis.yml"
|
82
82
|
- DEVELOPMENT
|
83
83
|
- Gemfile
|
84
84
|
- History.rdoc
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/commander.rb
|
92
92
|
- lib/commander/blank.rb
|
93
93
|
- lib/commander/command.rb
|
94
|
+
- lib/commander/configure.rb
|
94
95
|
- lib/commander/core_ext.rb
|
95
96
|
- lib/commander/core_ext/array.rb
|
96
97
|
- lib/commander/core_ext/object.rb
|
@@ -104,14 +105,17 @@ files:
|
|
104
105
|
- lib/commander/help_formatters/terminal_compact/command_help.erb
|
105
106
|
- lib/commander/help_formatters/terminal_compact/help.erb
|
106
107
|
- lib/commander/import.rb
|
108
|
+
- lib/commander/methods.rb
|
107
109
|
- lib/commander/platform.rb
|
108
110
|
- lib/commander/runner.rb
|
109
111
|
- lib/commander/user_interaction.rb
|
110
112
|
- lib/commander/version.rb
|
111
113
|
- spec/command_spec.rb
|
114
|
+
- spec/configure_spec.rb
|
112
115
|
- spec/core_ext/array_spec.rb
|
113
116
|
- spec/core_ext/object_spec.rb
|
114
117
|
- spec/help_formatters/terminal_spec.rb
|
118
|
+
- spec/methods_spec.rb
|
115
119
|
- spec/runner_spec.rb
|
116
120
|
- spec/spec_helper.rb
|
117
121
|
- spec/ui_spec.rb
|
@@ -125,25 +129,27 @@ require_paths:
|
|
125
129
|
- lib
|
126
130
|
required_ruby_version: !ruby/object:Gem::Requirement
|
127
131
|
requirements:
|
128
|
-
- -
|
132
|
+
- - ">="
|
129
133
|
- !ruby/object:Gem::Version
|
130
134
|
version: '0'
|
131
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
136
|
requirements:
|
133
|
-
- -
|
137
|
+
- - ">="
|
134
138
|
- !ruby/object:Gem::Version
|
135
139
|
version: '0'
|
136
140
|
requirements: []
|
137
141
|
rubyforge_project: commander
|
138
|
-
rubygems_version: 2.2.
|
142
|
+
rubygems_version: 2.2.2
|
139
143
|
signing_key:
|
140
144
|
specification_version: 4
|
141
145
|
summary: The complete solution for Ruby command-line executables
|
142
146
|
test_files:
|
143
147
|
- spec/command_spec.rb
|
148
|
+
- spec/configure_spec.rb
|
144
149
|
- spec/core_ext/array_spec.rb
|
145
150
|
- spec/core_ext/object_spec.rb
|
146
151
|
- spec/help_formatters/terminal_spec.rb
|
152
|
+
- spec/methods_spec.rb
|
147
153
|
- spec/runner_spec.rb
|
148
154
|
- spec/spec_helper.rb
|
149
155
|
- spec/ui_spec.rb
|