Add repo remove command
This commit is contained in:
parent
f77db3c6f8
commit
efafc085f3
4 changed files with 29 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
mod add;
|
mod add;
|
||||||
|
mod remove;
|
||||||
mod show;
|
mod show;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
@ -10,6 +11,7 @@ use crate::Environment;
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
Show(show::Command),
|
Show(show::Command),
|
||||||
Add(add::Command),
|
Add(add::Command),
|
||||||
|
Remove(remove::Command),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
|
|
@ -17,6 +19,7 @@ impl Command {
|
||||||
match self {
|
match self {
|
||||||
Self::Show(command) => command.run(env),
|
Self::Show(command) => command.run(env),
|
||||||
Self::Add(command) => command.run(env),
|
Self::Add(command) => command.run(env),
|
||||||
|
Self::Remove(command) => command.run(env),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
gdn-cli/src/commands/repo/remove.rs
Normal file
23
gdn-cli/src/commands/repo/remove.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
use crate::Environment;
|
||||||
|
|
||||||
|
/// Remove an existing repository.
|
||||||
|
#[derive(Debug, Parser)]
|
||||||
|
pub struct Command {
|
||||||
|
repo: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Command {
|
||||||
|
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
||||||
|
let data = gdn::data::open_and_migrate(env.data_dir.clone())?;
|
||||||
|
let state = gdn::data::load_state(&data)?;
|
||||||
|
let Some(id) = state.resolve_repo_identifier(&self.repo) else {
|
||||||
|
println!("No repo found for identifier {}.", self.repo);
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
gdn::data::remove_repo(&data, id)?;
|
||||||
|
println!("Removed repo {} ({id}).", self.repo);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ pub use crate::repo::VERSION as REPO_VERSION;
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
datadir::{LockedDataDir, UnlockedDataDir},
|
datadir::{LockedDataDir, UnlockedDataDir},
|
||||||
v1::{State, VERSION, add_repo, load_repo, load_repo_version, load_state, tidy},
|
v1::{State, VERSION, add_repo, load_repo, load_repo_version, load_state, remove_repo, tidy},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn migrate(dir: &LockedDataDir) -> anyhow::Result<()> {
|
fn migrate(dir: &LockedDataDir) -> anyhow::Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,8 @@ pub fn remove_repo(dir: &LockedDataDir, id: RepoId) -> anyhow::Result<()> {
|
||||||
state.repos.remove(&id);
|
state.repos.remove(&id);
|
||||||
save_state(dir, state)?;
|
save_state(dir, state)?;
|
||||||
|
|
||||||
// TODO Check if this works with read-only files
|
// This seems to work even with read-only files, so it should work fine for
|
||||||
|
// bare git repos. I don't expect to encounter read-only directories.
|
||||||
fs::remove_dir_all(repo_dir(dir, id))?;
|
fs::remove_dir_all(repo_dir(dir, id))?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue