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 CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ === 3.1.7 / 2009-03-24
3
+
4
+ * Added global --trace option
5
+
2
6
  === 3.1.6 / 2009-03-22
3
7
 
4
8
  * Changed Options struct to always use symbols
data/Todo.rdoc CHANGED
@@ -1,8 +1,6 @@
1
1
 
2
2
  == Major
3
3
 
4
- * Change Options to use hash @table ... open struct
5
- * Add to_hash or __hash__ method to Options, revise rbind
6
4
  * Finish global --trace
7
5
  * 1.9.x compatability
8
6
  * Publish RDoc on mini page / screencasts
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.6"
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-22}
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}
@@ -26,9 +26,7 @@ module Commander
26
26
  end
27
27
 
28
28
  def default defaults = {}
29
- defaults.each do |key, value|
30
- __send__ :"#{key}=", value if __send__(key).nil?
31
- end
29
+ @table = defaults.merge! @table
32
30
  end
33
31
  end
34
32
 
@@ -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
- call_active_command
44
- rescue InvalidCommandError
45
- say 'invalid command. Use --help for more information'
46
- rescue \
47
- OptionParser::InvalidOption,
48
- OptionParser::InvalidArgument,
49
- OptionParser::MissingArgument => e
50
- say e
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
  ##
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Commander
3
- VERSION = '3.1.6'
3
+ VERSION = '3.1.7'
4
4
  end
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(2).to(3)
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 '--trace', 'just', 'some', 'args'
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
- # describe "--trace" do
66
- # it "should display pretty errors by default" do
67
- # new_command_runner 'test' do
68
- # raise 'cookies!'
69
- # end.run!
70
- # @output.should == 'error: cookies!. use --trace to view backtrace'
71
- # end
72
- #
73
- # it "should display callstack when using this switch" do
74
- # lambda {
75
- # new_command_runner 'test', '--trace' do
76
- # raise 'cookies!'
77
- # end.run!
78
- # }.should raise_error
79
- # end
80
- # end
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 '--trace', 'test', 'foo', 'bar' do
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.trace.should be_true
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', '--trace', 'foo', 'bar' do
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.trace.should be_true
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', '--trace', 'foo', 'test', 'bar' do
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.trace.should be_true
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 "-t", "--trace", "trace description"
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.6
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-22 00:00:00 -07:00
12
+ date: 2009-03-24 00:00:00 -07:00
13
13
  default_executable: commander
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency