choosy 0.4.6 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/VERSION.yml +1 -1
- data/lib/choosy/base_command.rb +13 -0
- data/lib/choosy/command.rb +10 -10
- data/lib/choosy/errors.rb +1 -0
- data/lib/choosy/super_command.rb +20 -20
- data/lib/choosy/terminal.rb +5 -1
- metadata +2 -2
data/lib/VERSION.yml
CHANGED
data/lib/choosy/base_command.rb
CHANGED
@@ -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
|
data/lib/choosy/command.rb
CHANGED
@@ -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
data/lib/choosy/super_command.rb
CHANGED
@@ -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
|
|
data/lib/choosy/terminal.rb
CHANGED
@@ -107,7 +107,11 @@ module Choosy
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def die(message)
|
110
|
-
raise Choosy::
|
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
|