thunder 0.6.3 → 0.7.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1250c4a71eb698607638e27011a1f6c97ce1c579
4
+ data.tar.gz: 9d6bb6dc9b8c72bbf53d70efa298dc51794f7cdf
5
+ SHA512:
6
+ metadata.gz: d2228226de16c78009f1c32a07bed754d1b518dfb8dadf0490360f9e2aa5face229d66db57ab48e59ea292b678854708c95ae0f433dc0c9faf23752b20391237
7
+ data.tar.gz: 94c8cfcfdaeec9a1e2c9e6f349fa62bfc1293e4a2b161753255f83039507864eb984fa945b162d304433b42123f3ce983a00dda77db73a8edae043c92b8e7012
@@ -7,11 +7,9 @@ def thunder_commands(spec)
7
7
  spec[:commands].map(&:first).map(&:to_s)
8
8
  end
9
9
 
10
- def thunder_options(command)
11
- return nil unless command[:options]
12
-
10
+ def thunder_options(spec)
13
11
  result = []
14
- command[:options].each do |opt, option|
12
+ spec.each do |opt, option|
15
13
  result << "--#{opt}"
16
14
  next unless option[:short]
17
15
  result << "-#{option[:short]}"
@@ -27,9 +25,39 @@ def indent(text, amount, indent=" ")
27
25
  return result
28
26
  end
29
27
 
28
+ def thunder_completion_options(spec)
29
+ default_template = ERB.new <<-TEMPLATE, nil, "%>"
30
+ if [[ $current_word == "-" ]]; then
31
+ words="<%= thunder_options(spec).join(" ") %>"
32
+ fi
33
+ TEMPLATE
34
+ default_template.filename="thunder-completion-options"
35
+ default_template = default_template.result(binding)
36
+ template = ERB.new <<-TEMPLATE, nil, "%>"
37
+ % complex_options = false
38
+ % complex_options = true if spec.values.any? { |option| option[:type] != Thunder::Boolean }
39
+ % if complex_options
40
+ case $previous_word; in
41
+ % spec.select { |name, option| option[:type] != Thunder::Boolean }.each do |name, option|
42
+ <%= ["--"+name.to_s, option[:short] ? "-"+option[:short].to_s : nil ].compact.join("|") %>)
43
+ # placeholder for proper completion
44
+ ;;
45
+ % end
46
+ *)
47
+ <%= indent(default_template, 8) %>
48
+ ;;
49
+ esac
50
+ % else
51
+ <%= default_template %>
52
+ % end
53
+ TEMPLATE
54
+ template.filename="thunder-completion-options-complex"
55
+ return template.result(binding)
56
+ end
57
+
30
58
  def thunder_completion(depth, spec)
31
- template = ERB.new <<-TEMPLATE, nil, "%>"
32
- if ((COMP_CWORD == <%= depth+1 %>)); then
59
+ template = ERB.new <<-TEMPLATE, nil, "%>"
60
+ if (($which_word == <%= depth+1 %>)); then
33
61
  # display only commands
34
62
  words="<%= thunder_commands(spec).join(" ") %>"
35
63
  else
@@ -41,9 +69,7 @@ else
41
69
  words="<%= thunder_commands(spec).join(" ") %>"
42
70
  % end
43
71
  % if command[:options]
44
- if [[ ${COMP_WORDS[COMP_CWORD]:0:1} == "-" ]]; then
45
- words="<%= thunder_options(command).join(" ") %>"
46
- fi
72
+ <%= indent(thunder_completion_options(command[:options]), 8) %>
47
73
  % end
48
74
  % if command[:subcommand]
49
75
  <%= indent(thunder_completion(depth+1, command[:subcommand].class.thunder), 8) %>
@@ -52,8 +78,9 @@ else
52
78
  % end
53
79
  esac
54
80
  fi
55
- TEMPLATE
56
- return template.result(binding)
81
+ TEMPLATE
82
+ template.filename="thunder-completion-main-#{depth}"
83
+ return template.result(binding)
57
84
  end
58
85
 
59
86
  module Thunder
@@ -63,13 +90,23 @@ module Thunder
63
90
 
64
91
  % progname = File.basename(ARGV.first)
65
92
  __<%= progname %>_completion() {
93
+ local current_word=${COMP_WORDS[COMP_CWORD]}
94
+ local previous_word=${COMP_WORDS[COMP_CWORD-1]}
95
+ local all_words=("${COMP_WORDS[@]}")
96
+ local which_word=$COMP_CWORD
97
+ if [[ $current_word == *"="* ]]; then
98
+ previous_word=${current_word%=*}
99
+ current_word=${current_word#*=}
100
+ fi
101
+
66
102
  local words=""
67
103
  <%= indent(thunder_completion(0, self.class.thunder), 4) %>
68
- COMPREPLY=($(compgen -W "$words" -- ${COMP_WORDS[COMP_CWORD]}))
104
+ COMPREPLY=($(compgen -W "$words" -- $current_word))
69
105
  }
70
106
 
71
107
  complete -o default -o nospace -F __<%= progname %>_completion <%= progname %>
72
108
  TEMPLATE
109
+ template.filename="thunder-complete-start"
73
110
  puts template.result(binding)
74
111
  end
75
112
  end
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path("../../lib/thunder", __FILE__)
4
+ require 'erb'
5
+
6
+ def generate_man_page(script_name, spec)
7
+ template = ERB.new <<-TEMPLATE, nil, "%"
8
+ .TH <%= script_name.upcase %> 1 "<%= Time.new.strftime("%d %b %Y") %>" "<%= script_name.to_s %> 1.0" "<%= script_name.to_s %> Manual"
9
+ .SH NAME
10
+ <%= script_name %> \\- very short summary of your program
11
+ .SH SYNOPSIS
12
+ % spec[:commands].each do |_, command|
13
+ .PP
14
+ .B <%= script_name %> <%= command[:name].to_s %>
15
+ % (command[:params] || []).each do |type, param|
16
+ % next if command[:options] and param == :options
17
+ % case type
18
+ % when :req
19
+ .I <%= param.to_s %>
20
+ % when :opt
21
+ [ \\fI<%= param.to_s %>\\fR ]
22
+ % when :rest
23
+ [ \\fI<%= param.to_s %>\\fR... ]
24
+ % when :block
25
+ % end
26
+ % end
27
+ % (command[:options] || []).each do |_, option|
28
+ [ \\fB\\-\\-<%= option[:name] %><%= " \\\\fI"+option[:name].to_s unless option[:type] == Thunder::Boolean %> \\fR]
29
+ % end
30
+ % end
31
+ .SH DESCRIPTION
32
+ <%= script_name %> prints the string "Hello world" on standard output.
33
+ .SH COMMANDS
34
+ % spec[:commands].each do |_, command|
35
+ .SS "<%= command[:name].to_s %>"
36
+ <%= command[:description] unless command[:description].empty? %>
37
+ <%= (command[:long_description] || "").split(".").join(".\n") %>
38
+ % (command[:options] || []).each do |_, option|
39
+ .B --<%= option[:name] %><%= " \\\\fI"+option[:name].to_s+"\\\\fR" unless option[:type] == Thunder::Boolean %>
40
+ .RS
41
+ <%= option[:description] || "This option does xxx" %>
42
+ .RE
43
+ % end
44
+ % end
45
+ .SH AUTHOR
46
+ Anon Y. Mouse
47
+ TEMPLATE
48
+ template.filename="thunder-manual-start"
49
+ return template.result(binding).split("\n").reject(&:empty?).join("\n")
50
+ end
51
+
52
+ module Thunder
53
+ def start(args=ARGV.dup, options={})
54
+ puts generate_man_page(ARGV.first, self.class.thunder)
55
+ end
56
+ end
57
+
58
+ if ARGV.size != 1
59
+ puts "Usage: #{File.basename(__FILE__)} THUNDER_SCRIPT"
60
+ puts
61
+ puts "Prints out the suggested template for a bash completion script for the given thunder script"
62
+ exit 1
63
+ end
64
+
65
+ load File.expand_path(ARGV.first)
@@ -48,7 +48,7 @@ Usage:
48
48
  # @return [(String, String)] the formatted option and its description
49
49
  def format_option(option_spec)
50
50
  usage = " -#{option_spec[:short]}, --#{option_spec[:name]}"
51
- usage << " [#{option_spec[:name].to_s.upcase}]" unless option_spec[:type] == Boolean
51
+ usage << " [#{option_spec[:name].to_s.upcase}]" unless option_spec[:type] == Thunder::Boolean
52
52
  return usage, option_spec[:desc]
53
53
  end
54
54
 
@@ -13,7 +13,7 @@ class Thunder::TrollopAdapter
13
13
  type = option_spec[:type]
14
14
  type = :flag if type == Thunder::Boolean
15
15
  opt_options[:type] = type
16
- opt_options[:default] = option_spec[:default] if options_spec.has_key? :default
16
+ opt_options[:default] = option_spec[:default] if option_spec.has_key? :default
17
17
  opt_options[:short] = "-" + option_spec[:short]
18
18
 
19
19
  opt name, description, opt_options
@@ -1,4 +1,4 @@
1
1
  module Thunder
2
2
  # Version string for gemspec
3
- VERSION = "0.6.3"
3
+ VERSION = "0.7.0"
4
4
  end
metadata CHANGED
@@ -1,59 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thunder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
5
- prerelease:
4
+ version: 0.7.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Steven Karas
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-09 00:00:00.000000000 Z
11
+ date: 2013-11-11 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Thunder does command line interfaces. Nothing more, nothing less.
15
14
  email: steven.karas@gmail.com
16
15
  executables:
17
- - thunder-completion
18
16
  - thunder-spec
17
+ - thunder-completion
18
+ - thunder-manual
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - lib/thunder/help/default.rb
23
+ - lib/thunder/version.rb
23
24
  - lib/thunder/options/optparse.rb
24
25
  - lib/thunder/options/trollop.rb
25
- - lib/thunder/version.rb
26
26
  - lib/thunder.rb
27
27
  - spec/spec_thunder.rb
28
- - DESIGN.md
29
28
  - Rakefile
29
+ - DESIGN.md
30
30
  - README.md
31
- - bin/thunder-completion
32
31
  - bin/thunder-spec
32
+ - bin/thunder-completion
33
+ - bin/thunder-manual
33
34
  homepage: http://stevenkaras.github.com/thunder
34
35
  licenses:
35
36
  - MIT
37
+ metadata: {}
36
38
  post_install_message:
37
39
  rdoc_options: []
38
40
  require_paths:
39
41
  - lib
40
42
  required_ruby_version: !ruby/object:Gem::Requirement
41
- none: false
42
43
  requirements:
43
- - - ! '>='
44
+ - - '>='
44
45
  - !ruby/object:Gem::Version
45
46
  version: '0'
46
47
  required_rubygems_version: !ruby/object:Gem::Requirement
47
- none: false
48
48
  requirements:
49
- - - ! '>='
49
+ - - '>='
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  requirements: []
53
53
  rubyforge_project:
54
- rubygems_version: 1.8.25
54
+ rubygems_version: 2.0.3
55
55
  signing_key:
56
- specification_version: 3
56
+ specification_version: 4
57
57
  summary: Thunder makes command lines apps easy!
58
58
  test_files: []
59
59
  has_rdoc: