Class: OptParseGen::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/optparsegen.rb

Overview

An ERB based renderer.

Class Method Summary collapse

Class Method Details

.render(options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/optparsegen.rb', line 26

def self.render(options)
  ERB.new(%Q(require 'optparse'

options = Struct.new(<%= options.map { |o| o.symbol_name }.join(', ') %>).new

OptionParser.new do |opts|
<% for o in options.select { |o| o.name != "help" } %>
  opts.on(<%= o.opt_args.map { |arg| "'\#{arg}'" }.join(', ') %>) do |v|
options.<%= o.underscored_name %> = v
  end

<% end %>
  opts.on_tail('-h', '--help', 'Shows this usage text.') do
puts opts
exit
  end
end.parse!
), 0, '>').result(binding)
end