Sha256: 03f8cd61654def50727c8a651206bdba2ad8db84cacf6488466201def83ec9a7

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

require 'optparse'

module TimeCop
  class OptionParser
    attr_reader :args

    def initialize(args)
      @args = args
    end

    def parse
      options = {}
      option_parser = ::OptionParser.new do |opts|
        opts.on("-u USERNAME", "--username=USERNAME", "Username to authenticate as") do |username|
          options[:username] = username
        end

        opts.on("-p PASSWORD", "--password=PASSWORD", "Passsword to authenticate with") do |password|
          options[:password] = password
        end

        opts.on("-e EMAIL", "--email=EMAIL", "Email of user to get report for") do |email|
          options[:email] = email
        end

        opts.on('-i', '--interactive', 'Runs in interactive mode') do
          options[:interactive] = true
        end

        opts.on("-h", "--help", "Prints help") do
          puts opts
          exit
        end
      end

      option_parser.parse(args)

      unless ((options[:username] && options[:password]) || options[:interactive])
        puts "Please specify a username and password or run in interactive mode"
        puts option_parser
        exit
      end

      options
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
time_cop-0.8.2 lib/time_cop/option_parser.rb
time_cop-0.8.1 lib/time_cop/option_parser.rb
time_cop-0.8.0 lib/time_cop/option_parser.rb
time_cop-0.7.0 lib/time_cop/option_parser.rb
time_cop-0.6.0 lib/time_cop/option_parser.rb
time_cop-0.5.0 lib/time_cop/option_parser.rb