Skip to content

Commit

Permalink
Merge pull request #422 from mjpieters/419-env-vars
Browse files Browse the repository at this point in the history
feat: Add environment variables for most options
  • Loading branch information
rholshausen authored May 21, 2024
2 parents e44458a + c68a0ee commit f582945
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 47 deletions.
24 changes: 12 additions & 12 deletions rust/pact_verifier_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Logging options:
--pretty-log Emits excessively pretty, multi-line logs, optimized for human readability.
--full-log This emits human-readable, single-line logs for each event that occurs, with the current span context displayed before the formatted representation of the event.
--compact-log Emit logs optimized for short line lengths.
-j, --json <json-file> Generate a JSON report of the verification
-x, --junit <junit-file> Generate a JUnit XML report of the verification (requires the junit feature)
-j, --json <json-file> Generate a JSON report of the verification [env: PACT_VERIFIER_JSON_REPORT=]
-x, --junit <junit-file> Generate a JUnit XML report of the verification (requires the junit feature) [env: PACT_VERIFIER_JUNIT_REPORT=]
--no-colour Disables ANSI escape codes in the output [aliases: no-color]

Loading pacts options:
Expand All @@ -39,7 +39,7 @@ Loading pacts options:
-b, --broker-url <broker-url>
URL of the pact broker to fetch pacts from to verify (requires the provider name parameter) [env: PACT_BROKER_BASE_URL=]
--webhook-callback-url <webhook-callback-url>
URL of a Pact to verify via a webhook callback. Requires the broker-url to be set.
URL of a Pact to verify via a webhook callback. Requires the broker-url to be set. [env: PACT_WEBHOOK_CALLBACK_URL=]
--ignore-no-pacts-error
Do not fail if no pacts are found to verify

Expand All @@ -50,31 +50,31 @@ Authentication options:

Provider options:
-h, --hostname <hostname>
Provider hostname (defaults to localhost)
Provider hostname (defaults to localhost) [env: PACT_PROVIDER_HOSTNAME=]
-p, --port <port>
Provider port (defaults to protocol default 80/443)
Provider port (defaults to protocol default 80/443) [env: PACT_PROVIDER_PORT=]
--transport <transport>
Provider protocol transport to use (http, https, grpc, etc.) [default: http]
Provider protocol transport to use (http, https, grpc, etc.) [env: PACT_PROVIDER_TRANSPORT=] [default: http]
--transports <transports>
Allows multiple protocol transports to be configured (http, https, grpc, etc.) with their associated port numbers separated by a colon. For example, use --transports http:8080 grpc:5555 to configure both.
-n, --provider-name <provider-name>
Provider name (defaults to provider)
Provider name (defaults to provider) [env: PACT_PROVIDER_NAME=]
--base-path <base-path>
Base path to add to all requests
Base path to add to all requests [env: PACT_PROVIDER_BASE_PATH=]
--request-timeout <request-timeout>
Sets the HTTP request timeout in milliseconds for requests to the target API and for state change requests.
Sets the HTTP request timeout in milliseconds for requests to the target API and for state change requests. [env: PACT_PROVIDER_REQUEST_TIMEOUT=]
-H, --header <custom-header>
Add a custom header to be included in the calls to the provider. Values must be in the form KEY=VALUE, where KEY and VALUE contain ASCII characters (32-127) only. Can be repeated.
--disable-ssl-verification
Disables validation of SSL certificates

Provider state options:
-s, --state-change-url <state-change-url>
URL to post state change requests to
URL to post state change requests to [env: PACT_PROVIDER_STATE_CHANGE_URL=]
--state-change-as-query
State change request data will be sent as query parameters instead of in the request body
State change request data will be sent as query parameters instead of in the request body [env: PACT_PROVIDER_STATE_CHANGE_AS_QUERY=]
--state-change-teardown
State change teardown requests are to be made after each interaction
State change teardown requests are to be made after each interaction [env: PACT_PROVIDER_STATE_CHANGE_TEARDOWN=]

Filtering interactions:
--filter-description <filter-description>
Expand Down
16 changes: 15 additions & 1 deletion rust/pact_verifier_cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::{Arg, ArgAction, ArgGroup, Command, command};
use clap::builder::{NonEmptyStringValueParser, PossibleValuesParser};
use clap::builder::{FalseyValueParser, NonEmptyStringValueParser, PossibleValuesParser};
use regex::Regex;

fn port_value(v: &str) -> Result<u16, String> {
Expand Down Expand Up @@ -70,12 +70,14 @@ pub(crate) fn setup_app() -> Command {
.arg(Arg::new("json-file")
.short('j')
.long("json")
.env("PACT_VERIFIER_JSON_REPORT")
.action(ArgAction::Set)
.value_parser(NonEmptyStringValueParser::new())
.help("Generate a JSON report of the verification"))
.arg(Arg::new("junit-file")
.short('x')
.long("junit")
.env("PACT_VERIFIER_JUNIT_REPORT")
.action(ArgAction::Set)
.value_parser(NonEmptyStringValueParser::new())
.help("Generate a JUnit XML report of the verification (requires the junit feature)"))
Expand Down Expand Up @@ -119,6 +121,7 @@ pub(crate) fn setup_app() -> Command {
.help("URL of the pact broker to fetch pacts from to verify (requires the provider name parameter)"))
.arg(Arg::new("webhook-callback-url")
.long("webhook-callback-url")
.env("PACT_WEBHOOK_CALLBACK_URL")
.requires("broker-url")
.conflicts_with_all(&["file", "dir", "url"])
.action(ArgAction::Set)
Expand Down Expand Up @@ -159,17 +162,20 @@ pub(crate) fn setup_app() -> Command {
.arg(Arg::new("hostname")
.short('h')
.long("hostname")
.env("PACT_PROVIDER_HOSTNAME")
.action(ArgAction::Set)
.value_parser(NonEmptyStringValueParser::new())
.help("Provider hostname (defaults to localhost)"))
.arg(Arg::new("port")
.short('p')
.env("PACT_PROVIDER_PORT")
.long("port")
.action(ArgAction::Set)
.help("Provider port (defaults to protocol default 80/443)")
.value_parser(port_value))
.arg(Arg::new("transport")
.long("transport")
.env("PACT_PROVIDER_TRANSPORT")
.alias("scheme")
.action(ArgAction::Set)
.value_parser(NonEmptyStringValueParser::new())
Expand All @@ -185,16 +191,19 @@ pub(crate) fn setup_app() -> Command {
.arg(Arg::new("provider-name")
.short('n')
.long("provider-name")
.env("PACT_PROVIDER_NAME")
.action(ArgAction::Set)
.value_parser(NonEmptyStringValueParser::new())
.help("Provider name (defaults to provider)"))
.arg(Arg::new("base-path")
.long("base-path")
.env("PACT_PROVIDER_BASE_PATH")
.action(ArgAction::Set)
.value_parser(NonEmptyStringValueParser::new())
.help("Base path to add to all requests"))
.arg(Arg::new("request-timeout")
.long("request-timeout")
.env("PACT_PROVIDER_REQUEST_TIMEOUT")
.action(ArgAction::Set)
.value_parser(integer_value)
.help("Sets the HTTP request timeout in milliseconds for requests to the target API and for state change requests."))
Expand All @@ -215,16 +224,21 @@ pub(crate) fn setup_app() -> Command {
.arg(Arg::new("state-change-url")
.short('s')
.long("state-change-url")
.env("PACT_PROVIDER_STATE_CHANGE_URL")
.action(ArgAction::Set)
.value_parser(NonEmptyStringValueParser::new())
.help("URL to post state change requests to"))
.arg(Arg::new("state-change-as-query")
.long("state-change-as-query")
.env("PACT_PROVIDER_STATE_CHANGE_AS_QUERY")
.action(ArgAction::SetTrue)
.value_parser(FalseyValueParser::new())
.help("State change request data will be sent as query parameters instead of in the request body"))
.arg(Arg::new("state-change-teardown")
.long("state-change-teardown")
.env("PACT_PROVIDER_STATE_CHANGE_TEARDOWN")
.action(ArgAction::SetTrue)
.value_parser(FalseyValueParser::new())
.help("State change teardown requests are to be made after each interaction"))

.group(ArgGroup::new("filtering").multiple(true))
Expand Down
51 changes: 29 additions & 22 deletions rust/pact_verifier_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,56 @@
//! --pretty-log Emits excessively pretty, multi-line logs, optimized for human readability.
//! --full-log This emits human-readable, single-line logs for each event that occurs, with the current span context displayed before the formatted representation of the event.
//! --compact-log Emit logs optimized for short line lengths.
//! -j, --json <json-file> Generate a JSON report of the verification
//! -j, --json <json-file> Generate a JSON report of the verification [env: PACT_VERIFIER_JSON_REPORT=]
//! -x, --junit <junit-file> Generate a JUnit XML report of the verification (requires the junit feature) [env: PACT_VERIFIER_JUNIT_REPORT=]
//! --no-colour Disables ANSI escape codes in the output [aliases: no-color]
//!
//! Loading pacts options:
//! -f, --file <file> Pact file to verify (can be repeated)
//! -d, --dir <dir> Directory of pact files to verify (can be repeated)
//! -u, --url <url> URL of pact file to verify (can be repeated)
//! -b, --broker-url <broker-url> URL of the pact broker to fetch pacts from to verify (requires the provider name parameter) [env: PACT_BROKER_BASE_URL=]
//! --ignore-no-pacts-error Do not fail if no pacts are found to verify
//! -f, --file <file>
//! Pact file to verify (can be repeated)
//! -d, --dir <dir>
//! Directory of pact files to verify (can be repeated)
//! -u, --url <url>
//! URL of pact file to verify (can be repeated)
//! -b, --broker-url <broker-url>
//! URL of the pact broker to fetch pacts from to verify (requires the provider name parameter) [env: PACT_BROKER_BASE_URL=]
//! --webhook-callback-url <webhook-callback-url>
//! URL of a Pact to verify via a webhook callback. Requires the broker-url to be set. [env: PACT_WEBHOOK_CALLBACK_URL=]
//! --ignore-no-pacts-error
//! Do not fail if no pacts are found to verify
//!
//! Authentication options:
//! --user <user> Username to use when fetching pacts from URLS [env: PACT_BROKER_USERNAME=]
//! --password <password> Password to use when fetching pacts from URLS [env: PACT_BROKER_PASSWORD=]
//! -t, --token <token> Bearer token to use when fetching pacts from URLS [env: PACT_BROKER_TOKEN=]
//!
//! Provider options:
//! -h, --hostname <hostname>
//! Provider hostname (defaults to localhost)
//! Provider hostname (defaults to localhost) [env: PACT_PROVIDER_HOSTNAME=]
//! -p, --port <port>
//! Provider port (defaults to protocol default 80/443)
//! Provider port (defaults to protocol default 80/443) [env: PACT_PROVIDER_PORT=]
//! --transport <transport>
//! Provider protocol transport to use (http, https, grpc, etc.) [default: http]
//! Provider protocol transport to use (http, https, grpc, etc.) [env: PACT_PROVIDER_TRANSPORT=] [default: http]
//! --transports <transports>
//! Allows multiple protocol transports to be configured (http, https, grpc, etc.) with their associated port numbers separated by a colon. For example, use --transports http:8080 grpc:5555 to configure both.
//! -n, --provider-name <provider-name>
//! Provider name (defaults to provider)
//! Provider name (defaults to provider) [env: PACT_PROVIDER_NAME=]
//! --base-path <base-path>
//! Base path to add to all requests
//! Base path to add to all requests [env: PACT_PROVIDER_BASE_PATH=]
//! --request-timeout <request-timeout>
//! Sets the HTTP request timeout in milliseconds for requests to the target API and for state change requests.
//! --header <custom-header>
//! Sets the HTTP request timeout in milliseconds for requests to the target API and for state change requests. [env: PACT_PROVIDER_REQUEST_TIMEOUT=]
//! -H, --header <custom-header>
//! Add a custom header to be included in the calls to the provider. Values must be in the form KEY=VALUE, where KEY and VALUE contain ASCII characters (32-127) only. Can be repeated.
//! --disable-ssl-verification
//! Disables validation of SSL certificates
//!
//! Provider state options:
//! -s, --state-change-url <state-change-url>
//! URL to post state change requests to
//! URL to post state change requests to [env: PACT_PROVIDER_STATE_CHANGE_URL=]
//! --state-change-as-query
//! State change request data will be sent as query parameters instead of in the request body
//! State change request data will be sent as query parameters instead of in the request body [env: PACT_PROVIDER_STATE_CHANGE_AS_QUERY=]
//! --state-change-teardown
//! State change teardown requests are to be made after each interaction
//! State change teardown requests are to be made after each interaction [env: PACT_PROVIDER_STATE_CHANGE_TEARDOWN=]
//!
//! Filtering interactions:
//! --filter-description <filter-description>
Expand Down Expand Up @@ -94,12 +107,6 @@
//! Enables Pending Pacts
//! --include-wip-pacts-since <include-wip-pacts-since>
//! Allow pacts that don't match given consumer selectors (or tags) to be verified, without causing the overall task to fail. For more information, see https://pact.io/wip
//! --user <user>
//! Username to use when fetching pacts from URLS [env: PACT_BROKER_USERNAME=]
//! --password <password>
//! Password to use when fetching pacts from URLS [env: PACT_BROKER_PASSWORD=]
//! -t, --token <token>
//! Bearer token to use when fetching pacts from URLS [env: PACT_BROKER_TOKEN=]
//! ```
//!
//! ## Options
Expand Down
24 changes: 12 additions & 12 deletions rust/pact_verifier_cli/tests/cmd/main.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Logging options:
--pretty-log Emits excessively pretty, multi-line logs, optimized for human readability.
--full-log This emits human-readable, single-line logs for each event that occurs, with the current span context displayed before the formatted representation of the event.
--compact-log Emit logs optimized for short line lengths.
-j, --json <json-file> Generate a JSON report of the verification
-x, --junit <junit-file> Generate a JUnit XML report of the verification (requires the junit feature)
-j, --json <json-file> Generate a JSON report of the verification [env: PACT_VERIFIER_JSON_REPORT=]
-x, --junit <junit-file> Generate a JUnit XML report of the verification (requires the junit feature) [env: PACT_VERIFIER_JUNIT_REPORT=]
--no-colour Disables ANSI escape codes in the output [aliases: no-color]

Loading pacts options:
Expand All @@ -25,7 +25,7 @@ Loading pacts options:
-b, --broker-url <broker-url>
URL of the pact broker to fetch pacts from to verify (requires the provider name parameter) [env: PACT_BROKER_BASE_URL=]
--webhook-callback-url <webhook-callback-url>
URL of a Pact to verify via a webhook callback. Requires the broker-url to be set.
URL of a Pact to verify via a webhook callback. Requires the broker-url to be set. [env: PACT_WEBHOOK_CALLBACK_URL=]
--ignore-no-pacts-error
Do not fail if no pacts are found to verify

Expand All @@ -36,31 +36,31 @@ Authentication options:

Provider options:
-h, --hostname <hostname>
Provider hostname (defaults to localhost)
Provider hostname (defaults to localhost) [env: PACT_PROVIDER_HOSTNAME=]
-p, --port <port>
Provider port (defaults to protocol default 80/443)
Provider port (defaults to protocol default 80/443) [env: PACT_PROVIDER_PORT=]
--transport <transport>
Provider protocol transport to use (http, https, grpc, etc.) [default: http]
Provider protocol transport to use (http, https, grpc, etc.) [env: PACT_PROVIDER_TRANSPORT=] [default: http]
--transports <transports>
Allows multiple protocol transports to be configured (http, https, grpc, etc.) with their associated port numbers separated by a colon. For example, use --transports http:8080 grpc:5555 to configure both.
-n, --provider-name <provider-name>
Provider name (defaults to provider)
Provider name (defaults to provider) [env: PACT_PROVIDER_NAME=]
--base-path <base-path>
Base path to add to all requests
Base path to add to all requests [env: PACT_PROVIDER_BASE_PATH=]
--request-timeout <request-timeout>
Sets the HTTP request timeout in milliseconds for requests to the target API and for state change requests.
Sets the HTTP request timeout in milliseconds for requests to the target API and for state change requests. [env: PACT_PROVIDER_REQUEST_TIMEOUT=]
-H, --header <custom-header>
Add a custom header to be included in the calls to the provider. Values must be in the form KEY=VALUE, where KEY and VALUE contain ASCII characters (32-127) only. Can be repeated.
--disable-ssl-verification
Disables validation of SSL certificates

Provider state options:
-s, --state-change-url <state-change-url>
URL to post state change requests to
URL to post state change requests to [env: PACT_PROVIDER_STATE_CHANGE_URL=]
--state-change-as-query
State change request data will be sent as query parameters instead of in the request body
State change request data will be sent as query parameters instead of in the request body [env: PACT_PROVIDER_STATE_CHANGE_AS_QUERY=]
--state-change-teardown
State change teardown requests are to be made after each interaction
State change teardown requests are to be made after each interaction [env: PACT_PROVIDER_STATE_CHANGE_TEARDOWN=]

Filtering interactions:
--filter-description <filter-description>
Expand Down

0 comments on commit f582945

Please sign in to comment.