Class: PactBroker::Client::CLI::VersionSelectorOptionsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/client/cli/version_selector_options_parser.rb

Class Method Summary collapse

Class Method Details

.call(options) ⇒ Object



5
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
# File 'lib/pact_broker/client/cli/version_selector_options_parser.rb', line 5

def self.call options
  versions = []
  last_flag = nil
  options.each do | option |
    case option
    when "--pacticipant", "-a"
      versions << {}
    when "--latest", "-l"
      versions << {pacticipant: nil} unless versions.last
      versions.last[:latest] = true
    when /^\-/
      nil
    else
      case last_flag
      when "--pacticipant", "-a"
        versions.last[:pacticipant] = option
      when "--version", "-e"
        versions << {pacticipant: nil} unless versions.last
        versions.last[:version] = option
      when "--latest", "-l"
        versions << {pacticipant: nil} unless versions.last
        versions.last[:tag] = option
      end
    end
    last_flag = option if option.start_with?("-")
  end
  versions
end