cli: Make `rad rm` work without a fork
This commit is contained in:
parent
3d40a606f7
commit
0f47dc9057
|
|
@ -20,3 +20,10 @@ We can check our repositories again to see if it was deleted:
|
||||||
```
|
```
|
||||||
$ rad ls
|
$ 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
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ use std::fs;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
|
||||||
use radicle::identity::Id;
|
use radicle::identity::Id;
|
||||||
use radicle::storage::ReadStorage;
|
|
||||||
|
|
||||||
use crate::commands::rad_untrack;
|
use crate::commands::rad_untrack;
|
||||||
use crate::terminal as term;
|
use crate::terminal as term;
|
||||||
|
|
@ -19,12 +18,11 @@ Usage
|
||||||
|
|
||||||
rad rm <rid> [<option>...]
|
rad rm <rid> [<option>...]
|
||||||
|
|
||||||
Removes a project from storage.
|
Removes a repository from storage.
|
||||||
|
|
||||||
Options
|
Options
|
||||||
|
|
||||||
--no-confirm Do not ask for confirmation before removal
|
--no-confirm Do not ask for confirmation before removal (default: false)
|
||||||
(default: false)
|
|
||||||
--help Print help
|
--help Print help
|
||||||
"#,
|
"#,
|
||||||
};
|
};
|
||||||
|
|
@ -70,22 +68,20 @@ impl Args for Options {
|
||||||
pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
let profile = ctx.profile()?;
|
let profile = ctx.profile()?;
|
||||||
let storage = &profile.storage;
|
let storage = &profile.storage;
|
||||||
let signer = term::signer(&profile)?;
|
|
||||||
let id = options.id;
|
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()) {
|
if !path.exists() {
|
||||||
let path = radicle::storage::git::paths::repository(storage, &id);
|
anyhow::bail!("repository {id} was not found");
|
||||||
|
}
|
||||||
|
|
||||||
if !options.confirm || term::confirm(format!("Remove {id}?")) {
|
if !options.confirm || term::confirm(format!("Remove {id}?")) {
|
||||||
if let Err(e) = rad_untrack::untrack(id.to_owned(), &profile) {
|
if let Err(e) = rad_untrack::untrack(id.to_owned(), &profile) {
|
||||||
term::warning(&format!("Failed to untrack repository: {e}"));
|
term::warning(&format!("Failed to untrack repository: {e}"));
|
||||||
term::warning("Make sure to untrack this repository when your node is running");
|
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");
|
|
||||||
}
|
}
|
||||||
} else {
|
fs::remove_dir_all(path)?;
|
||||||
anyhow::bail!("project {} does not exist", &id)
|
term::success!("Successfully removed {id} from storage");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue