Sha256: 285bc3e92769885cf800e7bcf2d247d5e03d4de2d5d80b08d15bfe01beeac7dc

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

require 'spec-i18n/command_line/language_help_formatter'

module SpecI18n
  module CommandLine
    class Options
      
      def initialize(output_stream = STDOUT, error_stream = STDERR, options = {})
        @output_stream = output_stream
        @error_stream = error_stream
        @options = options
      end
      
      def parse!(args)
        @args = args
        @args.extend(::OptionParser::Arguable)
        
        @args.options do |opts|
          opts.banner = [ "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|
            if language == 'help'
              LanguageHelpFormatter.list_languages_and_exit(@output_stream)
            else
              LanguageHelpFormatter.list_keywords_and_exit(language)
            end
          end
          opts.on_tail("-v", "--version", "Show version.") do
            @output_stream.puts SpecI18n::VERSION
            Kernel.exit(0)
          end
          opts.on_tail("-h", "--help", "You're looking at it.") do
            @output_stream.puts opts.help
            Kernel.exit(0)
          end
        end.parse!
        self
      end
      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-i18n-0.2.0 lib/spec-i18n/command_line/options.rb