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