Class: SpecI18n::CommandLine::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/spec-i18n/command_line/options.rb

Instance Method Summary collapse

Constructor Details

#initialize(output_stream = STDOUT, error_stream = STDERR, options = {}) ⇒ Options

Returns a new instance of Options.



7
8
9
10
11
# File 'lib/spec-i18n/command_line/options.rb', line 7

def initialize(output_stream = STDOUT, error_stream = STDERR, options = {})
  @output_stream = output_stream
  @error_stream = error_stream
  @options = options
end

Instance Method Details



25
26
27
28
# File 'lib/spec-i18n/command_line/options.rb', line 25

def banner(opts)
  opts.banner = [ "Usage: rspec-i18n [options] [LANGUAGE]", "", "Examples:",
    "rspec-i18n --language help", "rspec-i18n --language pt"].join("\n")
end

#parse!(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/spec-i18n/command_line/options.rb', line 13

def parse!(args)
  @args = args
  @args.extend(::OptionParser::Arguable)
  @args.options do |opts|
    banner(opts)
    show_language_and_keywords(opts)
    show_version(opts)
    show_help(opts)
  end.parse!
  self
end


54
55
56
57
# File 'lib/spec-i18n/command_line/options.rb', line 54

def print_and_exit(message)
  @output_stream.puts message
  Kernel.exit(0)
end


49
50
51
52
# File 'lib/spec-i18n/command_line/options.rb', line 49

def print_languages(language)
  return Language.list_languages_and_exit(@output_stream) if language == 'help'
  Language.list_keywords_and_exit(@output_stream, language)  
end

#show_help(opts) ⇒ Object



43
44
45
46
47
# File 'lib/spec-i18n/command_line/options.rb', line 43

def show_help(opts)
  opts.on_tail("-h", "--help", "You're looking at it.") do
    print_and_exit(opts.help)
  end
end

#show_language_and_keywords(opts) ⇒ Object



30
31
32
33
34
35
# File 'lib/spec-i18n/command_line/options.rb', line 30

def show_language_and_keywords(opts)
  opts.on("-l LANGUAGE", "--language LANGUAGE", "List keywords for a particular language",
    %{Run with "--language help" to see all languages}) do |language|
    print_languages(language)
  end
end

#show_version(opts) ⇒ Object



37
38
39
40
41
# File 'lib/spec-i18n/command_line/options.rb', line 37

def show_version(opts)
  opts.on_tail("-v", "--version", "Show version.") do
    print_and_exit(SpecI18n::VERSION)
  end
end