]> git.proxmox.com Git - proxmox-backup.git/commitdiff
backup_manager: use confirmation helper in wipe-disk command
authorGabriel Goller <g.goller@proxmox.com>
Wed, 19 Jun 2024 10:15:44 +0000 (12:15 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 3 Jul 2024 08:57:00 +0000 (10:57 +0200)
Use `Confirmation` helper in the wipe-disk command prompt.

Improves: 887d83cb (cli: add interactive confirmation for block device wipe, 2023-11-29)
Cc: Markus Frank <m.frank@proxmox.com>
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
src/bin/proxmox_backup_manager/disk.rs

index 9c55a989b05466b90442bdbbc1b7c86e4bb19559..d0fdfc6f9e6fae02845c7ab8858d6d0136b4fe8a 100644 (file)
@@ -3,7 +3,7 @@ use serde_json::Value;
 
 use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
 use proxmox_schema::api;
-use std::io::{IsTerminal, Write};
+use std::io::IsTerminal;
 
 use pbs_api_types::{
     ZfsCompressionType, ZfsRaidLevel, BLOCKDEVICE_DISK_AND_PARTITION_NAME_SCHEMA,
@@ -155,17 +155,16 @@ async fn wipe_disk(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<
 
     // If we're on a TTY, query the user
     if std::io::stdin().is_terminal() {
-        println!("You are about to wipe block device {}.", param["disk"]);
-        print!("Are you sure you want to continue? (y/N): ");
-        let _ = std::io::stdout().flush();
-        use std::io::{BufRead, BufReader};
-        let mut line = String::new();
-        match BufReader::new(std::io::stdin()).read_line(&mut line) {
-            Ok(_) => match line.trim() {
-                "y" | "Y" => (), // continue
-                _ => bail!("Aborting."),
-            },
-            Err(err) => bail!("Failed to read line - {err}."),
+        let confirmation = Confirmation::query_with_default(
+            format!(
+                "You are about to wipe block device {}. Are you sure you want to continue?",
+                param["disk"]
+            )
+            .as_str(),
+            Confirmation::No,
+        )?;
+        if confirmation.is_no() {
+            bail!("Aborting.");
         }
     }