Class: SpecI18n::CommandLine::Options
- Inherits:
-
Object
- Object
- SpecI18n::CommandLine::Options
- Defined in:
- lib/spec-i18n/command_line/options.rb
Instance Method Summary collapse
- #banner(opts) ⇒ Object
-
#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
- #show_help(opts) ⇒ Object
- #show_language_and_keywords(opts) ⇒ Object
- #show_version(opts) ⇒ 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
#banner(opts) ⇒ Object
25 26 27 28 |
# File 'lib/spec-i18n/command_line/options.rb', line 25 def (opts) opts. = [ "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. do |opts| (opts) show_language_and_keywords(opts) show_version(opts) show_help(opts) end.parse! self end |
#print_and_exit(message) ⇒ Object
54 55 56 57 |
# File 'lib/spec-i18n/command_line/options.rb', line 54 def print_and_exit() @output_stream.puts Kernel.exit(0) end |
#print_languages(language) ⇒ Object
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 |