choosy 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/VERSION.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  date: 31/03/2011
3
3
  version:
4
- tiny: 6
4
+ tiny: 7
5
5
  major: 0
6
6
  minor: 4
@@ -53,6 +53,15 @@ module Choosy
53
53
  end
54
54
  end
55
55
 
56
+ def execute!(args)
57
+ begin
58
+ execute(args)
59
+ rescue Choosy::ClientExecutionError => e
60
+ $stderr << "#{@name}: #{e.message}\n"
61
+ exit 1
62
+ end
63
+ end
64
+
56
65
  def finalize!
57
66
  if @printer.nil?
58
67
  builder.printer :standard
@@ -68,6 +77,10 @@ module Choosy
68
77
  # Override in subclasses
69
78
  end
70
79
 
80
+ def execute(args)
81
+ # Override in subclasses
82
+ end
83
+
71
84
  def handle_help(hc)
72
85
  # Override in subclasses
73
86
  end
@@ -20,16 +20,6 @@ module Choosy
20
20
  raise Choosy::ConfigurationError.new("Parent must be a super command") unless Choosy::SuperCommand
21
21
  end
22
22
 
23
- def execute!(args)
24
- raise Choosy::ConfigurationError.new("No executor given for: #{name}") unless executor
25
- result = parse!(args)
26
- if executor.is_a?(Proc)
27
- executor.call(result.args, result.options)
28
- else
29
- executor.execute!(result.args, result.options)
30
- end
31
- end
32
-
33
23
  def subcommand?
34
24
  !@parent.nil?
35
25
  end
@@ -53,5 +43,15 @@ module Choosy
53
43
 
54
44
  result
55
45
  end
46
+
47
+ def execute(args)
48
+ raise Choosy::ConfigurationError.new("No executor given for: #{name}") unless executor
49
+ result = parse!(args)
50
+ if executor.is_a?(Proc)
51
+ executor.call(result.args, result.options)
52
+ else
53
+ executor.execute!(result.args, result.options)
54
+ end
55
+ end
56
56
  end
57
57
  end
data/lib/choosy/errors.rb CHANGED
@@ -9,4 +9,5 @@ module Choosy
9
9
  ParseError = Class.new(Choosy::Error)
10
10
  SuperParseError = Class.new(Choosy::Error)
11
11
  VersionError = Class.new(Choosy::Error)
12
+ ClientExecutionError = Class.new(Choosy::Error)
12
13
  end
@@ -24,26 +24,6 @@ module Choosy
24
24
  @parsimonious ||= false
25
25
  end
26
26
 
27
- def execute!(args)
28
- super_result = parse!(args)
29
- super_result.subresults.each do |result|
30
- cmd = result.command
31
- if cmd.executor.nil?
32
- raise Choosy::ConfigurationError.new("No executor given for: #{cmd.name}")
33
- end
34
- end
35
-
36
- super_result.subresults.each do |result|
37
- executor = result.command.executor
38
-
39
- if executor.is_a?(Proc)
40
- executor.call(result.args, result.options)
41
- else
42
- executor.execute!(result.args, result.options)
43
- end
44
- end
45
- end
46
-
47
27
  def has_default?
48
28
  !@default_command.nil?
49
29
  end
@@ -63,6 +43,26 @@ module Choosy
63
43
  parser.parse!(args)
64
44
  end
65
45
 
46
+ def execute(args)
47
+ super_result = parse!(args)
48
+ super_result.subresults.each do |result|
49
+ cmd = result.command
50
+ if cmd.executor.nil?
51
+ raise Choosy::ConfigurationError.new("No executor given for: #{cmd.name}")
52
+ end
53
+ end
54
+
55
+ super_result.subresults.each do |result|
56
+ executor = result.command.executor
57
+
58
+ if executor.is_a?(Proc)
59
+ executor.call(result.args, result.options)
60
+ else
61
+ executor.execute!(result.args, result.options)
62
+ end
63
+ end
64
+ end
65
+
66
66
  def handle_help(hc)
67
67
  command_name = hc.message
68
68
 
@@ -107,7 +107,11 @@ module Choosy
107
107
  end
108
108
 
109
109
  def die(message)
110
- raise Choosy::ValidationError.new(message)
110
+ raise Choosy::ClientExecutionError.new(message)
111
+ end
112
+
113
+ def self.die(message)
114
+ raise Choosy::ClientExecutionError.new(message)
111
115
  end
112
116
 
113
117
  private
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 6
9
- version: 0.4.6
8
+ - 7
9
+ version: 0.4.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Gabe McArthur