Skip to content

Commit

Permalink
feat(can-i-deploy): add --latest option to command line
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 31, 2017
1 parent 3516103 commit c7f012d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/pact_broker/client/cli/broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class Broker < CustomThor
desc 'can-i-deploy', "Returns exit code 0 or 1, indicating whether or not the specified application versions are compatible."

method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name. Use once for each pacticipant being checked."
method_option :version, required: true, aliases: "-e", desc: "The application version. Must be entered after the --pacticipant that it relates to."
method_option :version, required: false, aliases: "-e", desc: "The pacticipant version. Must be entered after the --pacticipant that it relates to."
method_option :latest, required: false, aliases: "-l", banner: '[TAG]', desc: "Use the latest pacticipant version. Optionally specify a TAG to use the latest version with the specified tag."
method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
Expand Down Expand Up @@ -87,8 +88,8 @@ def validate_pact_files pact_files
end

def validate_can_i_deploy_selectors selectors
pacticipants_without_versions = selectors.select{ |s| s[:version].nil? }.collect{ |s| s[:pacticipant] }
raise ::Thor::RequiredArgumentMissingError, "No --version provided for pacticipant #{pacticipants_without_versions.join(", ")}" if pacticipants_without_versions.any?
pacticipants_without_versions = selectors.select{ |s| s[:version].nil? && s[:latest].nil? }.collect{ |s| s[:pacticipant] }
raise ::Thor::RequiredArgumentMissingError, "The version must be specified using --version or --latest [TAG] for pacticipant #{pacticipants_without_versions.join(", ")}" if pacticipants_without_versions.any?
end

def publish_pacts pact_files
Expand Down
6 changes: 6 additions & 0 deletions lib/pact_broker/client/cli/version_selector_options_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ def self.call options
case option
when "--pacticipant", "-a"
versions << {}
when "--latest", "-l"
versions << {pacticipant: nil} unless versions.last
versions.last[:latest] = true
when /^\-/
nil
else
Expand All @@ -18,6 +21,9 @@ def self.call options
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?("-")
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ module CLI
invoke_can_i_deploy
end

context "with a missing --version" do
context "with a missing --version and --latest" do
let(:version_selectors) { [{pacticipant: "Foo", version: nil}] }

it "raises an error" do
expect { invoke_can_i_deploy }.to raise_error Thor::RequiredArgumentMissingError, "No --version provided for pacticipant Foo"
expect { invoke_can_i_deploy }.to raise_error Thor::RequiredArgumentMissingError, /The version must be specified/
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ module CLI
],[
["--version", "1.2.3"],
[{ pacticipant: nil, version: "1.2.3" } ]
],[
["--pacticipant", "Foo", "--latest", "--pacticipant", "Bar"],
[{ pacticipant: "Foo", latest: true }, { pacticipant: "Bar" } ]
],[
["--pacticipant", "Foo", "--latest", "prod", "--pacticipant", "Bar"],
[{ pacticipant: "Foo", latest: true, tag: "prod"}, { pacticipant: "Bar" } ]
]
]

Expand Down

0 comments on commit c7f012d

Please sign in to comment.