From 55d0f405a4bb909846c253dc126765acada028f9 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Tue, 23 Apr 2024 22:52:57 -0400 Subject: [PATCH] Add `remove` management command --- docs/changelog.md | 4 ++++ docs/runtime.md | 10 +++++++++- src/commands/self_cmd/cli.rs | 2 ++ src/commands/self_cmd/mod.rs | 1 + src/commands/self_cmd/remove.rs | 24 ++++++++++++++++++++++++ src/commands/self_cmd/restore.rs | 11 ++--------- 6 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 src/commands/self_cmd/remove.rs diff --git a/docs/changelog.md b/docs/changelog.md index 71ef32a..cee717a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased +***Added:*** + +- Add `remove` management command + ***Fixed:*** - Fix UV and the `VIRTUAL_ENV` environment variable on non-Windows systems diff --git a/docs/runtime.md b/docs/runtime.md index fa067f6..9d5cdc2 100644 --- a/docs/runtime.md +++ b/docs/runtime.md @@ -88,13 +88,21 @@ Built applications have a single top-level command group named `self` ([by defau These commands are always exposed. +#### Remove + +``` + self remove +``` + +This will wipe the installation. + #### Restore ``` self restore ``` -This will wipe the installation and start fresh. +This will wipe the installation and then reinstall. #### Update diff --git a/src/commands/self_cmd/cli.rs b/src/commands/self_cmd/cli.rs index 1ffd2c7..e62d071 100644 --- a/src/commands/self_cmd/cli.rs +++ b/src/commands/self_cmd/cli.rs @@ -15,6 +15,7 @@ enum Commands { Pip(super::pip::Cli), Python(super::python::Cli), PythonPath(super::python_path::Cli), + Remove(super::remove::Cli), Restore(super::restore::Cli), Update(super::update::Cli), } @@ -26,6 +27,7 @@ impl Cli { Commands::Pip(cli) => cli.exec(), Commands::Python(cli) => cli.exec(), Commands::PythonPath(cli) => cli.exec(), + Commands::Remove(cli) => cli.exec(), Commands::Restore(cli) => cli.exec(), Commands::Update(cli) => cli.exec(), } diff --git a/src/commands/self_cmd/mod.rs b/src/commands/self_cmd/mod.rs index 91cfa1b..e861a31 100644 --- a/src/commands/self_cmd/mod.rs +++ b/src/commands/self_cmd/mod.rs @@ -3,5 +3,6 @@ pub mod metadata; pub mod pip; pub mod python; pub mod python_path; +pub mod remove; pub mod restore; pub mod update; diff --git a/src/commands/self_cmd/remove.rs b/src/commands/self_cmd/remove.rs new file mode 100644 index 0000000..1430f9e --- /dev/null +++ b/src/commands/self_cmd/remove.rs @@ -0,0 +1,24 @@ +use std::fs; + +use anyhow::Result; +use clap::Args; + +use crate::{app, terminal}; + +/// Remove the installation +#[derive(Args, Debug)] +#[command()] +pub struct Cli {} + +impl Cli { + pub fn exec(self) -> Result<()> { + if app::install_dir().is_dir() { + let spinner = terminal::spinner("Removing installation".to_string()); + let result = fs::remove_dir_all(app::install_dir()); + spinner.finish_and_clear(); + result?; + } + + Ok(()) + } +} diff --git a/src/commands/self_cmd/restore.rs b/src/commands/self_cmd/restore.rs index d7d7540..67c1a9f 100644 --- a/src/commands/self_cmd/restore.rs +++ b/src/commands/self_cmd/restore.rs @@ -1,9 +1,7 @@ -use std::fs; - use anyhow::Result; use clap::Args; -use crate::{app, distribution, terminal}; +use crate::distribution; /// Restore the installation #[derive(Args, Debug)] @@ -12,12 +10,7 @@ pub struct Cli {} impl Cli { pub fn exec(self) -> Result<()> { - if app::install_dir().is_dir() { - let spinner = terminal::spinner("Removing installation".to_string()); - let result = fs::remove_dir_all(app::install_dir()); - spinner.finish_and_clear(); - result?; - } + super::remove::Cli {}.exec()?; distribution::ensure_ready()?; Ok(())