diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 90d1f57e..02fc113c 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -15,7 +15,7 @@ exclude = [ [dependencies] pact-plugin-driver = "0.6.1" -clap = { version = "4.4.11", features = [ "derive", "cargo" ] } +clap = { version = "4.4.11", features = [ "derive", "cargo", "env" ] } comfy-table = "7.1.1" home = "0.5.9" anyhow = "1.0.86" diff --git a/cli/README.md b/cli/README.md index 5c3f11a2..fa829aad 100644 --- a/cli/README.md +++ b/cli/README.md @@ -141,6 +141,11 @@ Options: -v, --version The version to install. This is only used for known plugins + --skip-load + Skip auto-loading of plugin + + [env: PACT_PLUGIN_CLI_SKIP_LOAD=] + -h, --help Print help (see a summary with '-h') diff --git a/cli/src/install.rs b/cli/src/install.rs index 3c3df48d..479ab969 100644 --- a/cli/src/install.rs +++ b/cli/src/install.rs @@ -25,7 +25,8 @@ pub fn install_plugin( _source_type: &Option, override_prompt: bool, skip_if_installed: bool, - version: &Option + version: &Option, + skip_load: bool, ) -> anyhow::Result<()> { let runtime = tokio::runtime::Builder::new_multi_thread() .enable_all() @@ -37,9 +38,9 @@ pub fn install_plugin( let install_url = Url::parse(source.as_str()); if let Ok(install_url) = install_url { - install_plugin_from_url(&http_client, install_url.as_str(), override_prompt, skip_if_installed).await + install_plugin_from_url(&http_client, install_url.as_str(), override_prompt, skip_if_installed,skip_load).await } else { - install_known_plugin(&http_client, source.as_str(), override_prompt, skip_if_installed, version).await + install_known_plugin(&http_client, source.as_str(), override_prompt, skip_if_installed, version, skip_load).await } }); @@ -53,7 +54,8 @@ async fn install_known_plugin( name: &str, override_prompt: bool, skip_if_installed: bool, - version: &Option + version: &Option, + skip_load: bool, ) -> anyhow::Result<()> { let index = fetch_repository_index(&http_client, Some(DEFAULT_INDEX)).await?; if let Some(entry) = index.entries.get(name) { @@ -65,7 +67,7 @@ async fn install_known_plugin( entry.latest_version.as_str() }; if let Some(version_entry) = entry.versions.iter().find(|v| v.version == version) { - install_plugin_from_url(&http_client, version_entry.source.value().as_str(), override_prompt, skip_if_installed).await + install_plugin_from_url(&http_client, version_entry.source.value().as_str(), override_prompt, skip_if_installed,skip_load).await } else { Err(anyhow!("'{}' is not a valid version for plugin '{}'", version, name)) } @@ -78,7 +80,8 @@ async fn install_plugin_from_url( http_client: &Client, source_url: &str, override_prompt: bool, - skip_if_installed: bool + skip_if_installed: bool, + skip_load: bool ) -> anyhow::Result<()> { let response = fetch_json_from_url(source_url, &http_client).await?; if let Some(map) = response.as_object() { @@ -104,13 +107,17 @@ async fn install_plugin_from_url( download_plugin_executable(&manifest, &plugin_dir, &http_client, url, &tag, true).await?; env::set_var("pact_do_not_track", "true"); - load_plugin(&manifest.as_dependency()) + if !skip_load { + load_plugin(&manifest.as_dependency()) .await .and_then(|plugin| { - println!("Installed plugin {} version {} OK", manifest.name, manifest.version); - plugin.kill(); - Ok(()) - }) + println!("Installed plugin {} version {} OK", manifest.name, manifest.version); + plugin.kill(); + Ok(()) + }) } + else { + return Ok(()) + } } else { println!("Skipping installing plugin {} version {} as it is already installed", manifest.name, manifest.version); Ok(()) diff --git a/cli/src/main.rs b/cli/src/main.rs index 5e63927b..cd308e95 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -76,7 +76,11 @@ enum Commands { #[clap(short, long)] /// The version to install. This is only used for known plugins. - version: Option + version: Option, + + #[clap(long,env="PACT_PLUGIN_CLI_SKIP_LOAD")] + /// Skip auto-loading of plugin + skip_load: bool }, /// Remove a plugin @@ -232,8 +236,8 @@ fn main() -> Result<(), ExitCode> { let result = match &cli.command { Commands::List(command) => list_plugins(command), Commands::Env => print_env(), - Commands::Install { yes, skip_if_installed, source, source_type, version } => { - install::install_plugin(source, source_type, *yes || cli.yes, *skip_if_installed, version) + Commands::Install { yes, skip_if_installed, source, source_type, version, skip_load } => { + install::install_plugin(source, source_type, *yes || cli.yes, *skip_if_installed, version, *skip_load) }, Commands::Remove { yes, name, version } => remove_plugin(name, version, *yes || cli.yes), Commands::Enable { name, version } => enable_plugin(name, version), diff --git a/cli/tests/cmd/install.stdout b/cli/tests/cmd/install.stdout index f4c735ec..839297bb 100644 --- a/cli/tests/cmd/install.stdout +++ b/cli/tests/cmd/install.stdout @@ -23,5 +23,10 @@ Options: -v, --version The version to install. This is only used for known plugins + --skip-load + Skip auto-loading of plugin + + [env: PACT_PLUGIN_CLI_SKIP_LOAD=] + -h, --help Print help (see a summary with '-h')