thunder 0.5.3 → 0.6.0
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/bin/thunder-spec +2 -0
- data/lib/thunder.rb +32 -10
- data/lib/thunder/version.rb +1 -1
- metadata +1 -1
data/bin/thunder-spec
CHANGED
data/lib/thunder.rb
CHANGED
@@ -27,13 +27,30 @@ module Thunder
|
|
27
27
|
options.merge!(parsed_options) if parsed_options
|
28
28
|
if command_spec[:subcommand]
|
29
29
|
return command_spec[:subcommand].start(args, options)
|
30
|
-
elsif parsed_options
|
31
|
-
#TODO: do arity check
|
32
|
-
return send command_spec[:name], *args, options
|
33
|
-
else
|
34
|
-
#TODO: do arity check
|
35
|
-
return send command_spec[:name], *args
|
36
30
|
end
|
31
|
+
if parsed_options
|
32
|
+
args << options
|
33
|
+
end
|
34
|
+
|
35
|
+
if command_spec[:params]
|
36
|
+
min = command_spec[:params].count { |param| param.first == :req}
|
37
|
+
if args.size < min
|
38
|
+
ARGV.insert((ARGV.size - args.size) - 1, "help")
|
39
|
+
puts help_command(command_spec)
|
40
|
+
return
|
41
|
+
end
|
42
|
+
max = if command_spec[:params].map(&:first).include?(:rest)
|
43
|
+
nil
|
44
|
+
else
|
45
|
+
command_spec[:params].size
|
46
|
+
end
|
47
|
+
if !max.nil? && args.size > max
|
48
|
+
ARGV.insert((ARGV.size - args.size) - 1, "help")
|
49
|
+
puts help_command(command_spec)
|
50
|
+
return
|
51
|
+
end
|
52
|
+
end
|
53
|
+
return send command_spec[:name], *args
|
37
54
|
end
|
38
55
|
|
39
56
|
protected
|
@@ -76,10 +93,6 @@ module Thunder
|
|
76
93
|
# @param args [<String>] the arguments list
|
77
94
|
# @param options [Hash] any included options
|
78
95
|
def get_help(args, options)
|
79
|
-
unless self.class.thunder[:help_formatter]
|
80
|
-
require 'thunder/help/default'
|
81
|
-
self.class.thunder[:help_formatter] = Thunder::DefaultHelp
|
82
|
-
end
|
83
96
|
if args.size == 0
|
84
97
|
puts help_list(self.class.thunder[:commands])
|
85
98
|
else
|
@@ -92,6 +105,10 @@ module Thunder
|
|
92
105
|
# @param commands [<Hash>] the commands to list
|
93
106
|
# @return [String] the rendered help
|
94
107
|
def help_list(commands)
|
108
|
+
unless self.class.thunder[:help_formatter]
|
109
|
+
require 'thunder/help/default'
|
110
|
+
self.class.thunder[:help_formatter] = Thunder::DefaultHelp
|
111
|
+
end
|
95
112
|
self.class.thunder[:help_formatter].help_list(commands)
|
96
113
|
end
|
97
114
|
|
@@ -100,6 +117,10 @@ module Thunder
|
|
100
117
|
# @param command_spec [Hash] the command to render detailed help for
|
101
118
|
# @return [String] the rendered help
|
102
119
|
def help_command(command_spec)
|
120
|
+
unless self.class.thunder[:help_formatter]
|
121
|
+
require 'thunder/help/default'
|
122
|
+
self.class.thunder[:help_formatter] = Thunder::DefaultHelp
|
123
|
+
end
|
103
124
|
self.class.thunder[:help_formatter].help_command(command_spec)
|
104
125
|
end
|
105
126
|
|
@@ -136,6 +157,7 @@ module Thunder
|
|
136
157
|
def method_added(method)
|
137
158
|
add_command(method.to_sym)
|
138
159
|
thunder[:commands][method][:params] = instance_method(method).parameters
|
160
|
+
thunder[:commands][method][:arity] = instance_method(method).arity
|
139
161
|
end
|
140
162
|
|
141
163
|
# Set the options processor.
|
data/lib/thunder/version.rb
CHANGED