Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing --yes parameter to bypass prompts #135

Merged
merged 3 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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