Class: Haml::I18n::Extractor::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/haml-i18n-extractor/flow/cli.rb

Defined Under Namespace

Classes: CliError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ CLI

Returns a new instance of CLI.



6
7
8
9
# File 'lib/haml-i18n-extractor/flow/cli.rb', line 6

def initialize(opts)
  @options = opts || {}
  @prompter = Haml::I18n::Extractor::Prompter.new # may as well
end

Class Method Details

.option_parserObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/haml-i18n-extractor/flow/cli.rb', line 11

def self.option_parser
  option_parser = Trollop::Parser.new do
    banner <<-EOB

  haml-i18n-extractor --version # print version of this gem
  haml-i18n-extractor --help    # this message
  haml-i18n-extractor <path> [--interactive|--non-interactive] [--other-options]

  See options list (short options available next to long option):\n

    EOB
    version "Current version: #{Haml::I18n::Extractor::VERSION}"
    opt :interactive, "interactive mode", :short => 'i'
    opt :non_interactive, "non interactive mode", :short => 'n'
    opt :yaml_file, "yaml file path, defaults to config/locales/en.yml", :type => String, :short => 'y'
    opt :i18n_scope, "top level i18n scope, defaults to :en", :type => String, :short => 's'
  end
end

.show_help!Object



30
31
32
33
34
# File 'lib/haml-i18n-extractor/flow/cli.rb', line 30

def self.show_help!
  Trollop::with_standard_exception_handling option_parser do
    raise Trollop::HelpNeeded
  end
end

Instance Method Details

#startObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/haml-i18n-extractor/flow/cli.rb', line 36

def start
  check_interactive_or_not_passed
  if @options[:path]
    check_interactive_or_not_passed
    pth = File.expand_path(@options[:path])

    if File.directory?(pth)
      workflow = Haml::I18n::Extractor::Workflow.new(pth, @options)
      workflow.run
    elsif File.exists?(pth)
      @options.merge!(:type => :overwrite)
      extractor = Haml::I18n::Extractor.new(pth, @options)
      extractor.run
    end
  end
end