thunder 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -7
- data/bin/thunder-completion +45 -35
- data/bin/thunder-spec +1 -1
- data/lib/thunder/help/default.rb +6 -6
- data/lib/thunder/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -7,6 +7,10 @@ Usage
|
|
7
7
|
|
8
8
|
gem install thunder
|
9
9
|
|
10
|
+
or if you're running [ruby 1.8.7](http://www.ruby-lang.org/en/news/2011/10/06/plans-for-1-8-7):
|
11
|
+
|
12
|
+
gem install thunder-1.8.7
|
13
|
+
|
10
14
|
see '[sample](http://github.com/stevenkaras/thunder/blob/master/sample)' for a quick overview of all features
|
11
15
|
|
12
16
|
Philosophy
|
@@ -21,13 +25,13 @@ Goals
|
|
21
25
|
-----
|
22
26
|
Provide a simple, DRY syntatic sugar library that provides the necessary services to create command line mappings to ruby methods. It will not provide any other services.
|
23
27
|
|
24
|
-
|
28
|
+
Notable features as of the current release:
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
* options parsing for commands
|
31
|
+
* default commands
|
32
|
+
* subcommands (ala git)
|
33
|
+
* integrated help system
|
34
|
+
* bash completion script generator
|
31
35
|
|
32
36
|
Development
|
33
37
|
-----------
|
@@ -35,4 +39,4 @@ If you'd like to contribute, fork, commit, and request a pull. I'll get around t
|
|
35
39
|
|
36
40
|
License
|
37
41
|
-------
|
38
|
-
MIT License
|
42
|
+
MIT License
|
data/bin/thunder-completion
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
require 'thunder'
|
4
4
|
require 'erb'
|
5
5
|
|
6
|
-
def thunder_commands(
|
7
|
-
|
6
|
+
def thunder_commands(spec)
|
7
|
+
spec[:commands].map(&:first).map(&:to_s)
|
8
8
|
end
|
9
9
|
|
10
10
|
def thunder_options(command)
|
@@ -19,53 +19,63 @@ def thunder_options(command)
|
|
19
19
|
return result
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
def indent(text, amount, indent=" ")
|
23
|
+
result = ""
|
24
|
+
text.lines do |line|
|
25
|
+
result << indent * amount + line
|
26
|
+
end
|
27
|
+
return result
|
28
|
+
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
def thunder_completion(depth, spec)
|
31
|
+
template = ERB.new <<-TEMPLATE, nil, "%>"
|
32
|
+
if ((COMP_CWORD == <%= depth+1 %>)); then
|
33
|
+
# display only commands
|
34
|
+
words="<%= thunder_commands(spec).join(" ") %>"
|
35
|
+
else
|
36
|
+
case ${COMP_WORDS[<%= depth+1 %>]} in
|
37
|
+
% spec[:commands].each do |name, command|
|
32
38
|
% name = name.to_s
|
39
|
+
<%= name %>)
|
40
|
+
% if name == "help"
|
41
|
+
words="<%= thunder_commands(spec).join(" ") %>"
|
42
|
+
% end
|
33
43
|
% if command[:options]
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
44
|
+
if [[ ${COMP_WORDS[COMP_CWORD]:0:1} == "-" ]]; then
|
45
|
+
words="<%= thunder_options(command).join(" ") %>"
|
46
|
+
fi
|
47
|
+
% end
|
48
|
+
% if command[:subcommand]
|
49
|
+
<%= indent(thunder_completion(depth+1, command[:subcommand].class.thunder), 8) %>
|
38
50
|
% end
|
51
|
+
;;
|
39
52
|
% end
|
53
|
+
esac
|
54
|
+
fi
|
55
|
+
TEMPLATE
|
56
|
+
return template.result(binding)
|
57
|
+
end
|
40
58
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
elif ((COMP_CWORD == 1)); then
|
51
|
-
# display only commands
|
52
|
-
words=$(__<%= progname %>_commands)
|
53
|
-
fi
|
59
|
+
module Thunder
|
60
|
+
def start(args=ARGV.dup, options={})
|
61
|
+
template = ERB.new <<-TEMPLATE, nil, "%>"
|
62
|
+
#!/bin/bash
|
63
|
+
|
64
|
+
% progname = File.basename(ARGV.first)
|
65
|
+
__<%= progname %>_completion() {
|
66
|
+
local words=""
|
67
|
+
<%= indent(thunder_completion(0, self.class.thunder), 4) %>
|
54
68
|
COMPREPLY=($(compgen -W "$words" -- ${COMP_WORDS[COMP_CWORD]}))
|
55
69
|
}
|
56
70
|
|
57
|
-
complete -o default -o nospace -F __<%= progname %>
|
58
|
-
|
71
|
+
complete -o default -o nospace -F __<%= progname %>_completion <%= progname %>
|
59
72
|
TEMPLATE
|
60
|
-
|
61
|
-
binding
|
62
|
-
}).call(self, self.class.thunder)
|
63
|
-
puts template.result(context)
|
73
|
+
puts template.result(binding)
|
64
74
|
end
|
65
75
|
end
|
66
76
|
|
67
77
|
if ARGV.size != 1
|
68
|
-
puts "Usage:
|
78
|
+
puts "Usage: #{File.basename(__FILE__)} THUNDER_SCRIPT"
|
69
79
|
puts
|
70
80
|
puts "Prints out the suggested template for a bash completion script for the given thunder script"
|
71
81
|
exit 1
|
data/bin/thunder-spec
CHANGED
@@ -18,7 +18,7 @@ def renderThunderSpec(spec)
|
|
18
18
|
end
|
19
19
|
|
20
20
|
if ARGV.size != 1
|
21
|
-
puts "Usage:
|
21
|
+
puts "Usage: #{File.basename(__FILE__)} THUNDER_SCRIPT"
|
22
22
|
puts
|
23
23
|
puts "Dumps the thunder spec to the command line for debugging and analysis"
|
24
24
|
exit 1
|
data/lib/thunder/help/default.rb
CHANGED
@@ -54,7 +54,7 @@ Usage:
|
|
54
54
|
end
|
55
55
|
|
56
56
|
# determine the preamble
|
57
|
-
#
|
57
|
+
#
|
58
58
|
# @return [String] the preamble
|
59
59
|
def determine_preamble
|
60
60
|
preamble = "#{File.basename($0)}"
|
@@ -80,15 +80,15 @@ Usage:
|
|
80
80
|
# @param separator [String]
|
81
81
|
# @return [String] a two-column table
|
82
82
|
def render_table(data, separator = " # ")
|
83
|
-
column_width = data.group_by do |
|
84
|
-
|
83
|
+
column_width = data.group_by do |row|
|
84
|
+
row.first.size
|
85
85
|
end.max.first
|
86
86
|
"".tap do |output|
|
87
|
-
data.each do |
|
88
|
-
output << "%-#{column_width}s#{separator}%s\n" %
|
87
|
+
data.each do |row|
|
88
|
+
output << "%-#{column_width}s#{separator}%s\n" % row
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
94
|
-
end
|
94
|
+
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-02 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
|