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(words) ⇒ Object



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

def self.call words
  selectors = []
  previous_option = nil
  split_equals(words).each do | word |
    case word
    when "--pacticipant", "-a"
      selectors << {}
    when "--ignore"
      selectors << { ignore: true }
    when "--latest", "-l"
      selectors << { pacticipant: nil } if selectors.empty?
      selectors.last[:latest] = true
    when "--main-branch"
      selectors << { pacticipant: nil } if selectors.empty?
      selectors.last[:main_branch] = true
      selectors.last[:latest] = true
    when /^\-/
      nil
    else
      case previous_option
      when "--pacticipant", "-a"
        selectors.last[:pacticipant] = word
      when "--ignore"
        selectors.last[:pacticipant] = word
      when "--version", "-e"
        selectors << { pacticipant: nil } if selectors.empty?
        selectors.last[:version] = word
      when "--latest", "-l"
        selectors << { pacticipant: nil } if selectors.empty?
        selectors.last[:tag] = word
      when "--branch"
        selectors << { pacticipant: nil } if selectors.empty?
        selectors.last[:branch] = word
        selectors.last[:latest] = true
      when "--main-branch"
        selectors << { pacticipant: nil } if selectors.empty?
        selectors.last[:main_branch] = true
        selectors.last[:latest] = true
      when "--all"
        selectors << { pacticipant: nil } if selectors.empty?
        selectors.last[:tag] = word
      end
    end
    previous_option = word if word.start_with?("-")
  end
  selectors
end

.split_equals(words) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/pact_broker/client/cli/version_selector_options_parser.rb', line 56

def self.split_equals(words)
  words.flat_map do |word|
    if word.start_with?("-") && word.include?("=")
      word.split('=', 2)
    else
      word
    end
  end
end