visionmedia-commander 3.1.6 → 3.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +4 -0
- data/Todo.rdoc +0 -2
- data/commander.gemspec +2 -2
- data/lib/commander/command.rb +1 -3
- data/lib/commander/runner.rb +18 -8
- data/lib/commander/version.rb +1 -1
- data/spec/command_spec.rb +2 -10
- data/spec/runner_spec.rb +22 -22
- data/spec/spec_helper.rb +1 -2
- metadata +2 -2
data/History.rdoc
CHANGED
data/Todo.rdoc
CHANGED
data/commander.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{commander}
|
5
|
-
s.version = "3.1.
|
5
|
+
s.version = "3.1.7"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["TJ Holowaychuk"]
|
9
|
-
s.date = %q{2009-03-
|
9
|
+
s.date = %q{2009-03-24}
|
10
10
|
s.default_executable = %q{commander}
|
11
11
|
s.description = %q{The complete solution for Ruby command-line executables}
|
12
12
|
s.email = %q{tj@vision-media.ca}
|
data/lib/commander/command.rb
CHANGED
data/lib/commander/runner.rb
CHANGED
@@ -35,19 +35,29 @@ module Commander
|
|
35
35
|
# Run command parsing and execution process.
|
36
36
|
|
37
37
|
def run!
|
38
|
+
trace = false
|
38
39
|
require_program :name, :version, :description
|
39
40
|
global_option('--help', 'Display help documentation') { command(:help).run *@args[1..-1]; return }
|
40
41
|
global_option('--version', 'Display version information') { say version; return }
|
42
|
+
global_option('--trace', 'Display backtrace when an error occurs') { trace = true }
|
41
43
|
parse_global_options
|
42
44
|
remove_global_options
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
unless trace
|
46
|
+
begin
|
47
|
+
call_active_command
|
48
|
+
rescue InvalidCommandError
|
49
|
+
say 'invalid command. Use --help for more information'
|
50
|
+
rescue \
|
51
|
+
OptionParser::InvalidOption,
|
52
|
+
OptionParser::InvalidArgument,
|
53
|
+
OptionParser::MissingArgument => e
|
54
|
+
say e
|
55
|
+
rescue Exception => e
|
56
|
+
say "error: #{e}. Use --trace to view backtrace"
|
57
|
+
end
|
58
|
+
else
|
59
|
+
call_active_command
|
60
|
+
end
|
51
61
|
end
|
52
62
|
|
53
63
|
##
|
data/lib/commander/version.rb
CHANGED
data/spec/command_spec.rb
CHANGED
@@ -34,7 +34,7 @@ describe Commander::Command do
|
|
34
34
|
|
35
35
|
describe "#option" do
|
36
36
|
it "should add options" do
|
37
|
-
lambda { @command.option '--recursive' }.should change(@command.options, :length).from(
|
37
|
+
lambda { @command.option '--recursive' }.should change(@command.options, :length).from(1).to(2)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should allow procs as option handlers" do
|
@@ -48,14 +48,6 @@ describe Commander::Command do
|
|
48
48
|
@command.run '--password', 'foo'
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
52
|
-
describe "#options" do
|
53
|
-
it "should distinguish between switches and descriptions" do
|
54
|
-
@command.option '-t', '--trace', 'some description'
|
55
|
-
@command.options[2][:description].should == 'some description'
|
56
|
-
@command.options[2][:switches].should == ['-t', '--trace']
|
57
|
-
end
|
58
|
-
end
|
59
51
|
|
60
52
|
describe "#switch_to_sym" do
|
61
53
|
it "should return a symbol based on the switch name" do
|
@@ -72,7 +64,7 @@ describe Commander::Command do
|
|
72
64
|
describe "should invoke #when_called" do
|
73
65
|
it "with arguments seperated from options" do
|
74
66
|
@command.when_called { |args, options| args.join(' ').should == 'just some args' }
|
75
|
-
@command.run '--
|
67
|
+
@command.run '--verbose', 'just', 'some', 'args'
|
76
68
|
end
|
77
69
|
|
78
70
|
it "calling the #call method by default when an object is called" do
|
data/spec/runner_spec.rb
CHANGED
@@ -62,22 +62,22 @@ describe Commander do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
65
|
+
describe "--trace" do
|
66
|
+
it "should display pretty errors by default" do
|
67
|
+
new_command_runner 'foo' do
|
68
|
+
command(:foo) { |c| c.when_called { raise 'cookies!' } }
|
69
|
+
end.run!
|
70
|
+
@output.string.should == "error: cookies!. Use --trace to view backtrace\n"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should display callstack when using this switch" do
|
74
|
+
lambda {
|
75
|
+
new_command_runner 'foo', '--trace' do
|
76
|
+
command(:foo) { |c| c.when_called { raise 'cookies!' } }
|
77
|
+
end.run!
|
78
|
+
}.should raise_error(RuntimeError)
|
79
|
+
end
|
80
|
+
end
|
81
81
|
|
82
82
|
describe "--version" do
|
83
83
|
it "should output program version" do
|
@@ -200,28 +200,28 @@ describe Commander do
|
|
200
200
|
|
201
201
|
describe "should function correctly" do
|
202
202
|
it "when options are passed before the command name" do
|
203
|
-
new_command_runner '--
|
203
|
+
new_command_runner '--verbose', 'test', 'foo', 'bar' do
|
204
204
|
@command.when_called do |args, options|
|
205
205
|
args.should == ['foo', 'bar']
|
206
|
-
options.
|
206
|
+
options.verbose.should be_true
|
207
207
|
end
|
208
208
|
end.run!
|
209
209
|
end
|
210
210
|
|
211
211
|
it "when options are passed after the command name" do
|
212
|
-
new_command_runner 'test', '--
|
212
|
+
new_command_runner 'test', '--verbose', 'foo', 'bar' do
|
213
213
|
@command.when_called do |args, options|
|
214
214
|
args.should == ['foo', 'bar']
|
215
|
-
options.
|
215
|
+
options.verbose.should be_true
|
216
216
|
end
|
217
217
|
end.run!
|
218
218
|
end
|
219
219
|
|
220
220
|
it "when an argument passed is the same name as the command" do
|
221
|
-
new_command_runner 'test', '--
|
221
|
+
new_command_runner 'test', '--verbose', 'foo', 'test', 'bar' do
|
222
222
|
@command.when_called do |args, options|
|
223
223
|
args.should == ['foo', 'test', 'bar']
|
224
|
-
options.
|
224
|
+
options.verbose.should be_true
|
225
225
|
end
|
226
226
|
end.run!
|
227
227
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -19,8 +19,7 @@ def create_test_command
|
|
19
19
|
c.description = "test description"
|
20
20
|
c.example "description", "command"
|
21
21
|
c.example "description 2", "command 2"
|
22
|
-
c.option
|
23
|
-
c.option "--verbose", "verbose description"
|
22
|
+
c.option '-v', "--verbose", "verbose description"
|
24
23
|
c.when_called do |args, options|
|
25
24
|
"test %s" % args.join
|
26
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visionmedia-commander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TJ Holowaychuk
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-24 00:00:00 -07:00
|
13
13
|
default_executable: commander
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|