Skip to content

Commit

Permalink
Allow passing --yes parameter to bypass prompts (davidcole1340#135)
Browse files Browse the repository at this point in the history
* Allow passing `--yes` parameter to bypass prompts

Makes this tool usable in automated builds such as Docker containers.

Addresses davidcole1340#133

* Update readme and guides

* rustfmt

Co-authored-by: David Cole <[email protected]>
  • Loading branch information
roborourke and davidcole1340 authored Sep 30, 2022
1 parent 7dac401 commit 8a81c4b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
14 changes: 10 additions & 4 deletions crates/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ SUBCOMMANDS:
Generates stub PHP files for the extension
$ cargo php install --help
cargo-php-install
cargo-php-install
Installs the extension in the current PHP installation.
Expand Down Expand Up @@ -71,8 +71,11 @@ OPTIONS:
--release
Whether to install the release version of the extension
--yes
Bypasses the confirmation prompt
$ cargo php remove --help
cargo-php-remove
cargo-php-remove
Removes the extension in the current PHP installation.
Expand All @@ -97,8 +100,11 @@ OPTIONS:
Path to the Cargo manifest of the extension. Defaults to the manifest in the directory
the command is called
--yes
Bypasses the confirmation prompt
$ cargo php stubs --help
cargo-php-stubs
cargo-php-stubs
Generates stub PHP files for the extension.
Expand All @@ -120,7 +126,7 @@ OPTIONS:
--manifest <MANIFEST>
Path to the Cargo manifest of the extension. Defaults to the manifest in the directory
the command is called.
This cannot be provided alongside the `ext` option, as that option provides a direct
path to the extension shared library.
Expand Down
32 changes: 20 additions & 12 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ struct Install {
/// the directory the command is called.
#[arg(long)]
manifest: Option<PathBuf>,
/// Whether to bypass the install prompt.
#[clap(long)]
yes: bool,
}

#[derive(Parser)]
Expand All @@ -121,6 +124,9 @@ struct Remove {
/// the directory the command is called.
#[arg(long)]
manifest: Option<PathBuf>,
/// Whether to bypass the remove prompt.
#[clap(long)]
yes: bool,
}

#[cfg(not(windows))]
Expand Down Expand Up @@ -172,12 +178,13 @@ impl Install {
php_ini = Some(ini_path);
}

if !Confirm::new()
.with_prompt(format!(
"Are you sure you want to install the extension `{}`?",
artifact.name
))
.interact()?
if !self.yes
&& !Confirm::new()
.with_prompt(format!(
"Are you sure you want to install the extension `{}`?",
artifact.name
))
.interact()?
{
bail!("Installation cancelled.");
}
Expand Down Expand Up @@ -305,12 +312,13 @@ impl Remove {
bail!("Unable to find extension installed.");
}

if !Confirm::new()
.with_prompt(format!(
"Are you sure you want to remove the extension `{}`?",
artifact.name
))
.interact()?
if !self.yes
&& !Confirm::new()
.with_prompt(format!(
"Are you sure you want to remove the extension `{}`?",
artifact.name
))
.interact()?
{
bail!("Installation cancelled.");
}
Expand Down
14 changes: 10 additions & 4 deletions guide/src/cargo-php.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ personally recommend for use in Visual Studio Code).

```text
$ cargo php stubs --help
cargo-php-stubs
cargo-php-stubs
Generates stub PHP files for the extension.
Expand All @@ -106,7 +106,7 @@ OPTIONS:
--manifest <MANIFEST>
Path to the Cargo manifest of the extension. Defaults to the manifest in the directory
the command is called.
This cannot be provided alongside the `ext` option, as that option provides a direct
path to the extension shared library.
Expand All @@ -130,7 +130,7 @@ so you are able to restore if you run into any issues.

```text
$ cargo php install --help
cargo-php-install
cargo-php-install
Installs the extension in the current PHP installation.
Expand Down Expand Up @@ -164,6 +164,9 @@ OPTIONS:
--release
Whether to install the release version of the extension
--yes
Bypasses the confirmation prompt
```

## Extension Removal
Expand All @@ -175,7 +178,7 @@ from your `php.ini` if present.

```text
$ cargo php remove --help
cargo-php-remove
cargo-php-remove
Removes the extension in the current PHP installation.
Expand Down Expand Up @@ -203,6 +206,9 @@ OPTIONS:
--manifest <MANIFEST>
Path to the Cargo manifest of the extension. Defaults to the manifest in the directory
the command is called
--yes
Bypasses the confirmation prompt
```

[`cargo-php`]: https://crates.io/crates/cargo-php
Expand Down

0 comments on commit 8a81c4b

Please sign in to comment.