add confirm prompt for deleting definitions

This commit is contained in:
0xf8 2023-05-30 00:03:39 -04:00
parent 2ecccea343
commit dc34e8e5f4
Signed by: 0xf8
GPG Key ID: 446580D758689584

View File

@ -1,6 +1,6 @@
use anyhow::Result;
use crate::{ ConfigManager, config::Host, input };
use dialoguer::{ Select, Input, theme::ColorfulTheme };
use dialoguer::{ Select, Input, Confirm, theme::ColorfulTheme };
use serde::{ Serialize, Deserialize };
use ssh_key::PrivateKey;
use std::fs;
@ -165,6 +165,7 @@ Host {host}
.arg(host.host.to_owned()).spawn()?.wait()?;
}
1 => { // Edit config
// TODO: replace this with configuer::editor
let editor = std::env::var("EDITOR").expect("EDITOR is not set");
std::process::Command::new(editor)
.arg(host.config.to_owned())
@ -177,9 +178,16 @@ Host {host}
config.save();
}
3 => { // Delete
let confirm = Confirm::with_theme(&ColorfulTheme::default())
.with_prompt("Are you sure you want to delete this definition?")
.default(false)
.interact()?;
if confirm {
config.configs.remove(host);
config.save();
break;
}
} // Back
4 => break,
_ => ()