thunder 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thunder'
4
+ require 'erb'
5
+
6
+ def thunder_commands(bolt)
7
+ bolt[:commands].map(&:first).map(&:to_s)
8
+ end
9
+
10
+ def thunder_options(command)
11
+ return nil unless command[:options]
12
+
13
+ result = []
14
+ command[:options].each do |opt, option|
15
+ result << "--#{opt}"
16
+ next unless option[:short]
17
+ result << "-#{option[:short]}"
18
+ end
19
+ return result
20
+ end
21
+
22
+ module Thunder
23
+ def start(args=ARGV.dup, options={})
24
+ template = ERB.new <<-TEMPLATE, nil, "%"
25
+ #!/bin/bash
26
+
27
+ % progname = File.basename(ARGV.first)
28
+ __<%= progname %>_command_list() {
29
+ echo "<%= thunder_commands(thunder).join(" ") %>"
30
+ }
31
+
32
+ #TODO: get the options to be completed as well
33
+ % thunder[:commands].each do |name, command|
34
+ % next unless command[:options]
35
+ __<%= progname %>_<%= name.to_s %>_options_list() {
36
+ echo "<%= thunder_options(command).join(" ") %>"
37
+ }
38
+ % end
39
+
40
+ __<%= progname %>_complete() {
41
+ COMPREPLY=($(compgen -W "$(__<%= progname %>_command_list)" -- ${COMP_WORDS[COMP_CWORD]}))
42
+ }
43
+
44
+ complete -o default -o nospace -F __<%= progname %>_complete <%= progname %>
45
+
46
+ TEMPLATE
47
+ context = (proc { |thiz, thunder|
48
+ binding
49
+ }).call(self, self.class.thunder)
50
+ puts template.result(context)
51
+ end
52
+ end
53
+
54
+ if ARGV.size != 1
55
+ puts "Usage: thunder-completion THUNDER_SCRIPT"
56
+ puts
57
+ puts "Prints out the suggested template for a bash completion script for the given thunder script"
58
+ exit 1
59
+ end
60
+
61
+ load File.expand_path(ARGV.first)
@@ -1,4 +1,4 @@
1
1
  module Thunder
2
2
  # Version string for gemspec
3
- VERSION = "0.5.0"
3
+ VERSION = "0.5.1"
4
4
  end
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.0
4
+ version: 0.5.1
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: 2012-12-30 00:00:00.000000000 Z
12
+ date: 2012-12-31 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
- executables: []
16
+ executables:
17
+ - thunder-completion
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
@@ -26,6 +27,7 @@ files:
26
27
  - Rakefile
27
28
  - DESIGN.md
28
29
  - README.md
30
+ - bin/thunder-completion
29
31
  homepage: http://stevenkaras.github.com/thunder
30
32
  licenses: []
31
33
  post_install_message: