Skip to content

Commit 7128db0

Browse files
committed
Add confirmation prompt to pecos upgrade
1 parent 68bbdee commit 7128db0

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

crates/pecos/src/bin/cli.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,13 @@ pub fn run_uninstall(targets: &[String], all: bool, yes: bool) -> pecos_build::R
626626
/// # Errors
627627
///
628628
/// Returns an error if any target fails to upgrade.
629-
pub fn run_upgrade(targets: &[String], all: bool, no_configure: bool) -> pecos_build::Result<()> {
630-
upgrade_cmd::run(targets, all, no_configure)
629+
pub fn run_upgrade(
630+
targets: &[String],
631+
all: bool,
632+
no_configure: bool,
633+
yes: bool,
634+
) -> pecos_build::Result<()> {
635+
upgrade_cmd::run(targets, all, no_configure, yes)
631636
}
632637

633638
/// Run the sys-info command

crates/pecos/src/bin/cli/upgrade_cmd.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
55
use pecos_build::Result;
66
use pecos_build::errors::Error;
7+
use pecos_build::prompt::{PromptMode, confirm};
78

89
/// Known upgradeable targets
910
const KNOWN_TARGETS: &[&str] = &["cuda", "llvm", "cuquantum"];
1011

1112
/// Run the upgrade command
12-
pub fn run(targets: &[String], all: bool, no_configure: bool) -> Result<()> {
13+
pub fn run(targets: &[String], all: bool, no_configure: bool, yes: bool) -> Result<()> {
1314
let targets: Vec<&str> = if all {
1415
KNOWN_TARGETS.to_vec()
1516
} else {
@@ -34,6 +35,23 @@ pub fn run(targets: &[String], all: bool, no_configure: bool) -> Result<()> {
3435
ordered
3536
};
3637

38+
println!("This will force-reinstall:");
39+
for target in &targets {
40+
println!(" {target}");
41+
}
42+
println!();
43+
44+
let mode = if yes {
45+
PromptMode::AcceptAll
46+
} else {
47+
PromptMode::Interactive
48+
};
49+
50+
if !confirm("Continue?", false, mode) {
51+
println!("Cancelled.");
52+
return Ok(());
53+
}
54+
3755
let total = targets.len();
3856
for (i, target) in targets.iter().enumerate() {
3957
println!("[{}/{}] Upgrading {target}...", i + 1, total);
@@ -42,7 +60,7 @@ pub fn run(targets: &[String], all: bool, no_configure: bool) -> Result<()> {
4260
println!();
4361
}
4462

45-
println!("All done.");
63+
println!("All done. Run `just build` to rebuild PECOS.");
4664
Ok(())
4765
}
4866

crates/pecos/src/bin/pecos.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ enum Commands {
235235
/// Skip automatic configuration after installation (applies to llvm)
236236
#[arg(long)]
237237
no_configure: bool,
238+
239+
/// Skip confirmation prompt
240+
#[arg(long, short)]
241+
yes: bool,
238242
},
239243
/// Show system tools and project info
240244
#[command(name = "sys-info")]
@@ -764,7 +768,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
764768
targets,
765769
all,
766770
no_configure,
767-
} => cli::run_upgrade(targets, *all, *no_configure)?,
771+
yes,
772+
} => cli::run_upgrade(targets, *all, *no_configure, *yes)?,
768773
Commands::SysInfo => cli::run_sys_info()?,
769774
Commands::List { verbose } => cli::run_list(*verbose)?,
770775
Commands::Self_ { command } => cli::run_self(command.clone())?,

0 commit comments

Comments
 (0)