thunder 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/thunder-completion +21 -8
- data/bin/thunder-spec +27 -0
- data/lib/thunder.rb +14 -11
- data/lib/thunder/version.rb +1 -1
- metadata +4 -2
data/bin/thunder-completion
CHANGED
@@ -25,20 +25,33 @@ module Thunder
|
|
25
25
|
#!/bin/bash
|
26
26
|
|
27
27
|
% progname = File.basename(ARGV.first)
|
28
|
-
__<%= progname %>
|
29
|
-
|
28
|
+
__<%= progname %>_commands() {
|
29
|
+
echo "<%= thunder_commands(thunder).join(" ") %>"
|
30
30
|
}
|
31
|
-
|
32
|
-
#TODO: get the options to be completed as well
|
33
31
|
% thunder[:commands].each do |name, command|
|
34
|
-
%
|
35
|
-
|
36
|
-
|
32
|
+
% name = name.to_s
|
33
|
+
% if command[:options]
|
34
|
+
|
35
|
+
__<%= progname %>_<%= name %>_options() {
|
36
|
+
echo "<%= thunder_options(command).join(" ") %>"
|
37
37
|
}
|
38
|
+
% end
|
38
39
|
% end
|
39
40
|
|
40
41
|
__<%= progname %>_complete() {
|
41
|
-
|
42
|
+
local words=""
|
43
|
+
if [[ ${COMP_WORDS[COMP_CWORD]:0:1} == "-" ]]; then
|
44
|
+
if ((COMP_CWORD == 1)); then
|
45
|
+
words=
|
46
|
+
else
|
47
|
+
local command="__<%= progname %>_${COMP_WORDS[1]}_options"
|
48
|
+
words=$($command)
|
49
|
+
fi
|
50
|
+
elif ((COMP_CWORD == 1)); then
|
51
|
+
# display only commands
|
52
|
+
words=$(__<%= progname %>_commands)
|
53
|
+
fi
|
54
|
+
COMPREPLY=($(compgen -W "$words" -- ${COMP_WORDS[COMP_CWORD]}))
|
42
55
|
}
|
43
56
|
|
44
57
|
complete -o default -o nospace -F __<%= progname %>_complete <%= progname %>
|
data/bin/thunder-spec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'thunder'
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
module Thunder
|
7
|
+
def start(args=ARGV.dup, options={})
|
8
|
+
spec = self.class.thunder
|
9
|
+
pp renderThunderSpec(spec)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def renderThunderSpec(spec)
|
14
|
+
spec[:commands].each do |name, command|
|
15
|
+
command[:subcommand] = renderThunderSpec(command[:subcommand].class.thunder) if command[:subcommand]
|
16
|
+
end
|
17
|
+
spec
|
18
|
+
end
|
19
|
+
|
20
|
+
if ARGV.size != 1
|
21
|
+
puts "Usage: thunder-spec THUNDER_SCRIPT"
|
22
|
+
puts
|
23
|
+
puts "Dumps the thunder spec to the command line for debugging and analysis"
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
load File.expand_path(ARGV.first)
|
data/lib/thunder.rb
CHANGED
@@ -134,15 +134,8 @@ module Thunder
|
|
134
134
|
# @api private
|
135
135
|
# Registers a method as a thunder task
|
136
136
|
def method_added(method)
|
137
|
-
|
138
|
-
|
139
|
-
thunder[:commands][method] = {
|
140
|
-
name: method,
|
141
|
-
}
|
142
|
-
attributes.each do |key|
|
143
|
-
thunder[:commands][method][key] = thunder[key]
|
144
|
-
thunder[key] = nil
|
145
|
-
end
|
137
|
+
add_command(method.to_sym)
|
138
|
+
thunder[:commands][method][:params] = instance_method(method).parameters
|
146
139
|
end
|
147
140
|
|
148
141
|
# Set the options processor.
|
@@ -196,7 +189,6 @@ module Thunder
|
|
196
189
|
# @example
|
197
190
|
# option "verbose", desc: "print extra information"
|
198
191
|
def option(name, options={})
|
199
|
-
#TODO: have this generate YARDoc for the option (as it should match a method option)
|
200
192
|
name = name.to_sym
|
201
193
|
options[:name] = name
|
202
194
|
options[:short] ||= name[0]
|
@@ -211,9 +203,20 @@ module Thunder
|
|
211
203
|
# @param command [Symbol,String] the command that transfers processing to the provided handler
|
212
204
|
# @param handler [Thunder] the handler that processes the request
|
213
205
|
def subcommand(command, handler)
|
214
|
-
|
206
|
+
add_command(command.to_sym)
|
215
207
|
thunder[:commands][command.to_sym][:subcommand] = handler
|
216
208
|
end
|
217
209
|
|
210
|
+
private
|
211
|
+
def add_command(command)
|
212
|
+
attributes = [:usage, :description, :options, :long_description]
|
213
|
+
return unless attributes.reduce(nil) { |a, key| a || thunder[key] }
|
214
|
+
thunder[:commands][command] = {
|
215
|
+
name: command,
|
216
|
+
}
|
217
|
+
attributes.each do |key|
|
218
|
+
thunder[:commands][command][key] = thunder.delete(key)
|
219
|
+
end
|
220
|
+
end
|
218
221
|
end
|
219
222
|
end
|
data/lib/thunder/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thunder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-01 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Thunder does command line interfaces. Nothing more, nothing less.
|
15
15
|
email: steven.karas@gmail.com
|
16
16
|
executables:
|
17
|
+
- thunder-spec
|
17
18
|
- thunder-completion
|
18
19
|
extensions: []
|
19
20
|
extra_rdoc_files: []
|
@@ -27,6 +28,7 @@ files:
|
|
27
28
|
- Rakefile
|
28
29
|
- DESIGN.md
|
29
30
|
- README.md
|
31
|
+
- bin/thunder-spec
|
30
32
|
- bin/thunder-completion
|
31
33
|
homepage: http://stevenkaras.github.com/thunder
|
32
34
|
licenses: []
|