Module: Cli

Defined in:
lib/cli.rb

Class Method Summary collapse

Class Method Details

.options!(args = ARGV) ⇒ Object



6
7
8
9
10
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
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cli.rb', line 6

def self.options!(args = ARGV)

  options = {}

  OptionParser.new do |opts|
    opts.banner = <<-STRING.gsub(/^ +/, '')
    Extracts from TargetProcess the cumulative flow for a specific team, and prints it in CSV format

    Usage:   #{$PROGRAM_NAME} [options]

    STRING

    opts.on("-t", "--team TEAM_ABBREVIATION", "(required) select a team to filter the data") do |team|
      options[:team] = team
    end

    opts.on("-p", "--project PROJ_ABBREVIATION", "(required) select a project to filter the data") do |project|
      options[:project] = project
    end

    opts.on("-u", "--username USERNAME", "(required) username to log on TargetProcess") do |username|
      options[:username] = username
    end

    opts.on("-b", "--base-uri URI", "(required) URI of TargetProcess") do |uri|
      options[:base_uri] = uri
    end

    opts.on("--states STATES", "included states, separated by commas") do |states|
      options[:states] = states.split(',').map(&:chomp)
    end

    options[:day] = "tuesday"
    opts.on("-d", "--day DAY", %w{monday tuesday wednesday thursday friday saturday sunday},
            "day of week used as iteration start (defaults to tuesday)") do |day|
      options[:day] = day
    end

    options[:verify] = true
    opts.on("--[no-]verify", "verify ssl certificates") do |verify|
      options[:verify] = verify
    end

  end.parse!(args)

  unless options[:username] then
    options[:username] = get_input("Username: ")
  end

  options[:password] = get_input("Password: ", echo: false)

  options
end