thunder-1.8.7 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/thunder-spec +2 -0
- data/lib/thunder.rb +30 -10
- data/lib/thunder/version.rb +1 -1
- metadata +4 -4
data/bin/thunder-spec
CHANGED
data/lib/thunder.rb
CHANGED
@@ -27,14 +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
|
-
|
31
|
-
|
30
|
+
end
|
31
|
+
if parsed_options
|
32
32
|
args << options
|
33
|
-
return send command_spec[:name], *args
|
34
|
-
else
|
35
|
-
#TODO: do arity check
|
36
|
-
return send command_spec[:name], *args
|
37
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
|
38
54
|
end
|
39
55
|
|
40
56
|
protected
|
@@ -77,10 +93,6 @@ module Thunder
|
|
77
93
|
# @param args [<String>] the arguments list
|
78
94
|
# @param options [Hash] any included options
|
79
95
|
def get_help(args, options)
|
80
|
-
unless self.class.thunder[:help_formatter]
|
81
|
-
require 'thunder/help/default'
|
82
|
-
self.class.thunder[:help_formatter] = Thunder::DefaultHelp
|
83
|
-
end
|
84
96
|
if args.size == 0
|
85
97
|
puts help_list(self.class.thunder[:commands])
|
86
98
|
else
|
@@ -93,6 +105,10 @@ module Thunder
|
|
93
105
|
# @param commands [<Hash>] the commands to list
|
94
106
|
# @return [String] the rendered help
|
95
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
|
96
112
|
self.class.thunder[:help_formatter].help_list(commands)
|
97
113
|
end
|
98
114
|
|
@@ -101,6 +117,10 @@ module Thunder
|
|
101
117
|
# @param command_spec [Hash] the command to render detailed help for
|
102
118
|
# @return [String] the rendered help
|
103
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
|
104
124
|
self.class.thunder[:help_formatter].help_command(command_spec)
|
105
125
|
end
|
106
126
|
|
data/lib/thunder/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thunder-1.8.7
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Steven Karas
|