-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): specify pact urls as the arguments to pact-provider-verifi…
…er instead of using --pact-urls option
- Loading branch information
Showing
11 changed files
with
315 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
require 'pact/provider_verifier/cli' | ||
Pact::ProviderVerifier::CLI.start | ||
require 'pact/provider_verifier/cli/verify' | ||
Pact::ProviderVerifier::CLI::Verify.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require 'thor' | ||
|
||
module Pact | ||
module ProviderVerifier | ||
module CLI | ||
## | ||
# Custom Thor task allows the following: | ||
# | ||
# `script arg1 arg2` to be interpreted as `script <default_task> arg1 arg2` | ||
# `--option 1 --option 2` to be interpreted as `--option 1 2` (the standard Thor format for multiple value options) | ||
# `script --help` to display the help for the default task instead of the command list | ||
# | ||
class CustomThor < ::Thor | ||
|
||
no_commands do | ||
def self.start given_args = ARGV, config = {} | ||
super(massage_args(given_args)) | ||
end | ||
|
||
def help *args | ||
if args.empty? | ||
super(self.class.default_task) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def self.massage_args argv | ||
prepend_default_task_name(turn_muliple_tag_options_into_array(argv)) | ||
end | ||
|
||
def self.prepend_default_task_name argv | ||
if known_first_arguments.include?(argv[0]) | ||
argv | ||
else | ||
[default_command] + argv | ||
end | ||
end | ||
|
||
# other task names, help, and the help shortcuts | ||
def self.known_first_arguments | ||
@known_first_arguments ||= tasks.keys + ::Thor::HELP_MAPPINGS + ['help'] | ||
end | ||
|
||
def self.turn_muliple_tag_options_into_array argv | ||
new_argv = [] | ||
opt_name = nil | ||
argv.each_with_index do | arg, i | | ||
if arg.start_with?('-') | ||
opt_name = arg | ||
existing = new_argv.find { | a | a.first == opt_name } | ||
if !existing | ||
new_argv << [arg] | ||
end | ||
else | ||
if opt_name | ||
existing = new_argv.find { | a | a.first == opt_name } | ||
existing << arg | ||
opt_name = nil | ||
else | ||
new_argv << [arg] | ||
end | ||
end | ||
end | ||
new_argv.flatten | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'thor' | ||
require 'socket' | ||
require 'pact/provider_verifier/app' | ||
require 'pact/provider_verifier/cli/custom_thor' | ||
|
||
module Pact | ||
module ProviderVerifier | ||
module CLI | ||
class Verify < CustomThor | ||
desc 'PACT_URL ...', "Verify pact(s) against a provider. Supports local and networked (http-based) files." | ||
method_option :provider_base_url, aliases: "-h", desc: "Provider host URL", :required => true | ||
method_option :provider_states_setup_url, aliases: "-c", desc: "Base URL to setup the provider states at", :required => false | ||
method_option :provider_app_version, aliases: "-a", desc: "Provider application version, required when publishing verification results", :required => false | ||
method_option :publish_verification_results, aliases: "-r", desc: "Publish verification results to the broker", required: false | ||
method_option :broker_username, aliases: "-n", desc: "Pact Broker basic auth username", :required => false | ||
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password", :required => false | ||
method_option :custom_provider_header, desc: "Header to add to provider state set up and pact requests. eg 'Authorization: Basic cGFjdDpwYWN0'", :required => false | ||
method_option :provider_states_url, aliases: "-s", desc: "DEPRECATED", :required => false | ||
method_option :verbose, aliases: "-v", desc: "Verbose output", :required => false | ||
method_option :pact_urls, aliases: "-u", desc: "DEPRECATED. Please provide as space separated arguments.", :required => false | ||
|
||
def verify(*pact_urls) | ||
print_deprecation_warnings | ||
Pact::ProviderVerifier::App.call(merged_urls(pact_urls), options) | ||
end | ||
|
||
default_task :verify | ||
|
||
desc 'version', 'Show the pact-provider-verifier gem version' | ||
def version | ||
require 'pact/provider_verifier/version' | ||
puts Pact::ProviderVerifier::VERSION | ||
end | ||
|
||
no_commands do | ||
def merged_urls pact_urls_from_args | ||
from_opts = options.pact_urls ? options.pact_urls.split(',') : [] | ||
from_opts + pact_urls_from_args | ||
end | ||
|
||
def print_deprecation_warnings | ||
if options.pact_urls | ||
$stderr.puts "WARN: The --pact-urls option is deprecated. Please pass in a space separated list of URLs as the first arguments to the pact-provider-verifier command." | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.