Skip to content

Commit 8a81c4b

Browse files
Allow passing --yes parameter to bypass prompts (#135)
* Allow passing `--yes` parameter to bypass prompts Makes this tool usable in automated builds such as Docker containers. Addresses #133 * Update readme and guides * rustfmt Co-authored-by: David Cole <[email protected]>
1 parent 7dac401 commit 8a81c4b

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

crates/cli/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ SUBCOMMANDS:
4040
Generates stub PHP files for the extension
4141
4242
$ cargo php install --help
43-
cargo-php-install
43+
cargo-php-install
4444
4545
Installs the extension in the current PHP installation.
4646
@@ -71,8 +71,11 @@ OPTIONS:
7171
--release
7272
Whether to install the release version of the extension
7373
74+
--yes
75+
Bypasses the confirmation prompt
76+
7477
$ cargo php remove --help
75-
cargo-php-remove
78+
cargo-php-remove
7679
7780
Removes the extension in the current PHP installation.
7881
@@ -97,8 +100,11 @@ OPTIONS:
97100
Path to the Cargo manifest of the extension. Defaults to the manifest in the directory
98101
the command is called
99102
103+
--yes
104+
Bypasses the confirmation prompt
105+
100106
$ cargo php stubs --help
101-
cargo-php-stubs
107+
cargo-php-stubs
102108
103109
Generates stub PHP files for the extension.
104110
@@ -120,7 +126,7 @@ OPTIONS:
120126
--manifest <MANIFEST>
121127
Path to the Cargo manifest of the extension. Defaults to the manifest in the directory
122128
the command is called.
123-
129+
124130
This cannot be provided alongside the `ext` option, as that option provides a direct
125131
path to the extension shared library.
126132

crates/cli/src/lib.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ struct Install {
105105
/// the directory the command is called.
106106
#[arg(long)]
107107
manifest: Option<PathBuf>,
108+
/// Whether to bypass the install prompt.
109+
#[clap(long)]
110+
yes: bool,
108111
}
109112

110113
#[derive(Parser)]
@@ -121,6 +124,9 @@ struct Remove {
121124
/// the directory the command is called.
122125
#[arg(long)]
123126
manifest: Option<PathBuf>,
127+
/// Whether to bypass the remove prompt.
128+
#[clap(long)]
129+
yes: bool,
124130
}
125131

126132
#[cfg(not(windows))]
@@ -172,12 +178,13 @@ impl Install {
172178
php_ini = Some(ini_path);
173179
}
174180

175-
if !Confirm::new()
176-
.with_prompt(format!(
177-
"Are you sure you want to install the extension `{}`?",
178-
artifact.name
179-
))
180-
.interact()?
181+
if !self.yes
182+
&& !Confirm::new()
183+
.with_prompt(format!(
184+
"Are you sure you want to install the extension `{}`?",
185+
artifact.name
186+
))
187+
.interact()?
181188
{
182189
bail!("Installation cancelled.");
183190
}
@@ -305,12 +312,13 @@ impl Remove {
305312
bail!("Unable to find extension installed.");
306313
}
307314

308-
if !Confirm::new()
309-
.with_prompt(format!(
310-
"Are you sure you want to remove the extension `{}`?",
311-
artifact.name
312-
))
313-
.interact()?
315+
if !self.yes
316+
&& !Confirm::new()
317+
.with_prompt(format!(
318+
"Are you sure you want to remove the extension `{}`?",
319+
artifact.name
320+
))
321+
.interact()?
314322
{
315323
bail!("Installation cancelled.");
316324
}

guide/src/cargo-php.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ personally recommend for use in Visual Studio Code).
8484

8585
```text
8686
$ cargo php stubs --help
87-
cargo-php-stubs
87+
cargo-php-stubs
8888
8989
Generates stub PHP files for the extension.
9090
@@ -106,7 +106,7 @@ OPTIONS:
106106
--manifest <MANIFEST>
107107
Path to the Cargo manifest of the extension. Defaults to the manifest in the directory
108108
the command is called.
109-
109+
110110
This cannot be provided alongside the `ext` option, as that option provides a direct
111111
path to the extension shared library.
112112
@@ -130,7 +130,7 @@ so you are able to restore if you run into any issues.
130130

131131
```text
132132
$ cargo php install --help
133-
cargo-php-install
133+
cargo-php-install
134134
135135
Installs the extension in the current PHP installation.
136136
@@ -164,6 +164,9 @@ OPTIONS:
164164
165165
--release
166166
Whether to install the release version of the extension
167+
168+
--yes
169+
Bypasses the confirmation prompt
167170
```
168171

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

176179
```text
177180
$ cargo php remove --help
178-
cargo-php-remove
181+
cargo-php-remove
179182
180183
Removes the extension in the current PHP installation.
181184
@@ -203,6 +206,9 @@ OPTIONS:
203206
--manifest <MANIFEST>
204207
Path to the Cargo manifest of the extension. Defaults to the manifest in the directory
205208
the command is called
209+
210+
--yes
211+
Bypasses the confirmation prompt
206212
```
207213

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

0 commit comments

Comments
 (0)