diff --git a/Cargo.lock b/Cargo.lock index 481f1ef0..0523a917 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3087,6 +3087,7 @@ dependencies = [ "log", "notify 5.2.0", "pyo3", + "self-replace", "self_update", "serde", "serde_json", @@ -11989,6 +11990,17 @@ dependencies = [ "libc", ] +[[package]] +name = "self-replace" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03ec815b5eab420ab893f63393878d89c90fdd94c0bcc44c07abb8ad95552fb7" +dependencies = [ + "fastrand 2.3.0", + "tempfile", + "windows-sys 0.52.0", +] + [[package]] name = "self_update" version = "0.27.0" diff --git a/binaries/cli/Cargo.toml b/binaries/cli/Cargo.toml index 20d42015..6fd7e1ce 100644 --- a/binaries/cli/Cargo.toml +++ b/binaries/cli/Cargo.toml @@ -60,6 +60,7 @@ pyo3 = { workspace = true, features = [ "extension-module", "abi3", ], optional = true } +self-replace = "1.5.0" [lib] diff --git a/binaries/cli/src/lib.rs b/binaries/cli/src/lib.rs index bb89de20..ce5c5ec5 100644 --- a/binaries/cli/src/lib.rs +++ b/binaries/cli/src/lib.rs @@ -240,7 +240,7 @@ enum Command { #[clap(long)] quiet: bool, }, - + /// Dora CLI self-management commands Self_ { #[clap(subcommand)] command: SelfSubCommand, @@ -249,11 +249,18 @@ enum Command { #[derive(Debug, clap::Subcommand)] enum SelfSubCommand { + /// Check for updates or update the CLI Update { /// Only check for updates without installing #[clap(long)] check_only: bool, }, + /// Remove The Dora CLI from the system + Uninstall { + /// Force uninstallation without confirmation + #[clap(long)] + force: bool, + }, } #[derive(Debug, clap::Args)] @@ -606,6 +613,30 @@ fn run(args: Args) -> eyre::Result<()> { } } } + SelfSubCommand::Uninstall { force } => { + if !force { + let confirmed = + inquire::Confirm::new("Are you sure you want to uninstall Dora CLI?") + .with_default(false) + .prompt() + .wrap_err("Uninstallation cancelled")?; + + if !confirmed { + println!("Uninstallation cancelled"); + return Ok(()); + } + } + + println!("Uninstalling Dora CLI..."); + match self_replace::self_delete() { + Ok(_) => { + println!("Dora CLI has been successfully uninstalled."); + } + Err(e) => { + bail!("Failed to uninstall Dora CLI: {}", e); + } + } + } }, };