Module: I18nTemplate::Runner

Defined in:
lib/i18n_template/runner.rb,
lib/i18n_template/runner/base.rb,
lib/i18n_template/runner/extract_phrases.rb

Defined Under Namespace

Classes: Base, ExtractPhrases

Class Method Summary collapse

Class Method Details

.runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/i18n_template/runner.rb', line 9

def run
  options = {}

  option_parser = OptionParser.new do |op|
    op.banner = "Usage: #{File.basename($0)} COMMAND [OPTIONS]"

    I18nTemplate.runners.each do |runner|
      op.separator ""
      op.separator "#{runner.command} - #{runner.description}"
      runner.add_options!(op, options)
    end

    op.separator ""
    op.on(
      "--verbose",
      "turn on verbosity"
    ) { |v| options[:verbose] = true }

    op.separator ""
    op.on_tail("-h", "--help", "Show this message") { puts op; exit }
    op.on_tail('-v', '--version', "Show version")   { puts I18nTemplate::VERSION; exit }
  end

  begin
    option_parser.parse!(ARGV)
  rescue OptionParser::ParseError => e
    warn e.message
    puts option_parser
    exit 1
  end

  I18nTemplate.runners.each do |runner|
    runner.default_options.each do |key, value|
      options[key] = value unless options.key?(key)
    end
  end

  command = ARGV.first

  runner = I18nTemplate.runners.detect { |klass| klass.command == command }

  unless runner
    warn "Unknown command '#{command}'"
    puts option_parser
    exit 1
  end

  runner.new(options).run
end