Class: SpecI18n::CommandLine::Options
- Inherits:
-
Object
- Object
- SpecI18n::CommandLine::Options
- Defined in:
- lib/spec-i18n/command_line/options.rb
Instance Method Summary collapse
-
#initialize(output_stream = STDOUT, error_stream = STDERR, options = {}) ⇒ Options
constructor
A new instance of Options.
- #parse!(args) ⇒ Object
- #print_and_exit(message) ⇒ Object
- #print_languages(language) ⇒ Object
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, = {}) @output_stream = output_stream @error_stream = error_stream @options = end |
Instance Method Details
#parse!(args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/spec-i18n/command_line/options.rb', line 13 def parse!(args) @args = args @args.extend(::OptionParser::Arguable) @args. do |opts| opts. = [ "Usage: rspec-i18n [options] [LANGUAGE]", "", "Examples:", "rspec-i18n --language help", "rspec-i18n --language pt"].join("\n") 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 opts.on_tail("-v", "--version", "Show version.") do print_and_exit(SpecI18n::VERSION) end opts.on_tail("-h", "--help", "You're looking at it.") do print_and_exit(opts.help) end end.parse! self end |
#print_and_exit(message) ⇒ Object
41 42 43 44 |
# File 'lib/spec-i18n/command_line/options.rb', line 41 def print_and_exit() @output_stream.puts Kernel.exit(0) end |
#print_languages(language) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/spec-i18n/command_line/options.rb', line 33 def print_languages(language) if language == 'help' LanguageHelpFormatter.list_languages_and_exit(@output_stream) else LanguageHelpFormatter.list_keywords_and_exit(@output_stream, language) end end |