Class: TimeCop::OptionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/time_cop/option_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ OptionParser

Returns a new instance of OptionParser.



7
8
9
# File 'lib/time_cop/option_parser.rb', line 7

def initialize(args)
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/time_cop/option_parser.rb', line 5

def args
  @args
end

Instance Method Details

#parseObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/time_cop/option_parser.rb', line 11

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