Skip to content

Commit

Permalink
Add remove management command (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Apr 24, 2024
1 parent 48a0d3a commit 4c65522
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion docs/runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,21 @@ Built applications have a single top-level command group named `self` ([by defau

These commands are always exposed.

#### Remove

```
<EXE> self remove
```

This will wipe the installation.

#### Restore

```
<EXE> self restore
```

This will wipe the installation and start fresh.
This will wipe the installation and then reinstall.

#### Update

Expand Down
2 changes: 2 additions & 0 deletions src/commands/self_cmd/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand All @@ -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(),
}
Expand Down
1 change: 1 addition & 0 deletions src/commands/self_cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
24 changes: 24 additions & 0 deletions src/commands/self_cmd/remove.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
}
11 changes: 2 additions & 9 deletions src/commands/self_cmd/restore.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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(())
Expand Down

0 comments on commit 4c65522

Please sign in to comment.