diff options
| author | David Lönnhager <david.l@mullvad.net> | 2023-05-03 11:20:31 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2023-05-03 11:20:31 +0200 |
| commit | 49ea114adddba1a1db6ffc6c440e743c01797a47 (patch) | |
| tree | 66f1bf1e3e1d208e233e5622045503abe85a3a89 /mullvad-cli/src/cmds/reset.rs | |
| parent | beaa6d3b80d9c9dfed99c710c793830db3ddc7ec (diff) | |
| parent | aade46c9c73c874e4153caa450e713d8f8b37760 (diff) | |
| download | mullvadvpn-49ea114adddba1a1db6ffc6c440e743c01797a47.tar.xz mullvadvpn-49ea114adddba1a1db6ffc6c440e743c01797a47.zip | |
Merge branch 'update-clap'
Diffstat (limited to 'mullvad-cli/src/cmds/reset.rs')
| -rw-r--r-- | mullvad-cli/src/cmds/reset.rs | 60 |
1 files changed, 24 insertions, 36 deletions
diff --git a/mullvad-cli/src/cmds/reset.rs b/mullvad-cli/src/cmds/reset.rs index d3e3ec3e62..a8c275a042 100644 --- a/mullvad-cli/src/cmds/reset.rs +++ b/mullvad-cli/src/cmds/reset.rs @@ -1,44 +1,32 @@ -use crate::{new_rpc_client, Command, Error, Result}; +use anyhow::Result; +use mullvad_management_interface::MullvadProxyClient; use std::io::stdin; -pub struct Reset; -#[mullvad_management_interface::async_trait] -impl Command for Reset { - fn name(&self) -> &'static str { - "factory-reset" +pub async fn handle() -> Result<()> { + if receive_confirmation().await { + let mut rpc = MullvadProxyClient::new().await?; + rpc.factory_reset().await?; + #[cfg(target_os = "linux")] + println!("If you're running systemd, to remove all logs, you must use journalctl"); } + Ok(()) +} - fn clap_subcommand(&self) -> clap::App<'static> { - clap::App::new(self.name()).about("Reset settings, caches and logs") - } +async fn receive_confirmation() -> bool { + println!("Are you sure you want to disconnect, log out, delete all settings, logs and cache files for the Mullvad VPN system service? [Yes/No (default)]"); - async fn run(&self, _: &clap::ArgMatches) -> Result<()> { - let mut rpc = new_rpc_client().await?; - if Self::receive_confirmation() { - rpc.factory_reset(()) - .await - .map_err(|error| Error::RpcFailedExt("FAILED TO PERFORM FACTORY RESET", error))?; - #[cfg(target_os = "linux")] - println!("If you're running systemd, to remove all logs, you must use journalctl"); + tokio::task::spawn_blocking(|| loop { + let mut buf = String::new(); + if let Err(e) = stdin().read_line(&mut buf) { + eprintln!("Couldn't read from STDIN: {e}"); + return false; } - Ok(()) - } -} - -impl Reset { - fn receive_confirmation() -> bool { - println!("Are you sure you want to disconnect, log out, delete all settings, logs and cache files for the Mullvad VPN system service? [Yes/No (default)]"); - loop { - let mut buf = String::new(); - if let Err(e) = stdin().read_line(&mut buf) { - eprintln!("Couldn't read from STDIN: {e}"); - return false; - } - match buf.trim() { - "Yes" => return true, - "No" | "no" | "" => return false, - _ => println!("Unexpected response. Please enter \"Yes\" or \"No\""), - } + match buf.trim() { + "Yes" => return true, + "No" | "no" | "" => return false, + _ => eprintln!("Unexpected response. Please enter \"Yes\" or \"No\""), } - } + }) + .await + .unwrap() } |
