Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Make `rad rm` work without a fork
Adam Szkoda committed 3 years ago
commit 0f47dc9057d79572414c94399f8ef8d19dd91b4d
parent 3d40a606f78f6b13e7617ad8eaea6d32801d73a3
2 files changed +19 -16
modified radicle-cli/examples/rad-rm.md
@@ -20,3 +20,10 @@ We can check our repositories again to see if it was deleted:
```
$ rad ls
```
+

+
Attempting to remove a repository that doesn't exist gives us an error message:
+

+
```
+
$ rad rm rad:z2Jk1mNqyX7AjT4K83jJW9vQoHn4f
+
✗ Remove failed: repository rad:z2Jk1mNqyX7AjT4K83jJW9vQoHn4f was not found
+
```
modified radicle-cli/src/commands/rm.rs
@@ -4,7 +4,6 @@ use std::fs;
use anyhow::anyhow;

use radicle::identity::Id;
-
use radicle::storage::ReadStorage;

use crate::commands::rad_untrack;
use crate::terminal as term;
@@ -19,12 +18,11 @@ Usage

    rad rm <rid> [<option>...]

-
    Removes a project from storage.
+
    Removes a repository from storage.

Options

-
    --no-confirm        Do not ask for confirmation before removal
-
                        (default: false)
+
    --no-confirm        Do not ask for confirmation before removal (default: false)
    --help              Print help
"#,
};
@@ -70,22 +68,20 @@ impl Args for Options {
pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
    let profile = ctx.profile()?;
    let storage = &profile.storage;
-
    let signer = term::signer(&profile)?;
    let id = options.id;
+
    let path = radicle::storage::git::paths::repository(storage, &id);

-
    if let Ok(Some(_)) = storage.get(signer.public_key(), id.to_owned()) {
-
        let path = radicle::storage::git::paths::repository(storage, &id);
+
    if !path.exists() {
+
        anyhow::bail!("repository {id} was not found");
+
    }

-
        if !options.confirm || term::confirm(format!("Remove {id}?")) {
-
            if let Err(e) = rad_untrack::untrack(id.to_owned(), &profile) {
-
                term::warning(&format!("Failed to untrack repository: {e}"));
-
                term::warning("Make sure to untrack this repository when your node is running");
-
            }
-
            fs::remove_dir_all(path)?;
-
            term::success!("Successfully removed {id} from storage");
+
    if !options.confirm || term::confirm(format!("Remove {id}?")) {
+
        if let Err(e) = rad_untrack::untrack(id.to_owned(), &profile) {
+
            term::warning(&format!("Failed to untrack repository: {e}"));
+
            term::warning("Make sure to untrack this repository when your node is running");
        }
-
    } else {
-
        anyhow::bail!("project {} does not exist", &id)
+
        fs::remove_dir_all(path)?;
+
        term::success!("Successfully removed {id} from storage");
    }

    Ok(())