Add repo rename command
This commit is contained in:
parent
357de970ee
commit
3390526522
4 changed files with 32 additions and 3 deletions
|
|
@ -2,6 +2,7 @@ mod add;
|
||||||
mod info;
|
mod info;
|
||||||
mod list;
|
mod list;
|
||||||
mod remove;
|
mod remove;
|
||||||
|
mod rename;
|
||||||
mod select;
|
mod select;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
@ -25,6 +26,9 @@ pub enum Command {
|
||||||
#[command(visible_alias = "a")]
|
#[command(visible_alias = "a")]
|
||||||
Add(add::Command),
|
Add(add::Command),
|
||||||
|
|
||||||
|
#[command(visible_alias = "rn")]
|
||||||
|
Rename(rename::Command),
|
||||||
|
|
||||||
#[command(visible_alias = "r")]
|
#[command(visible_alias = "r")]
|
||||||
Remove(remove::Command),
|
Remove(remove::Command),
|
||||||
}
|
}
|
||||||
|
|
@ -36,6 +40,7 @@ impl Command {
|
||||||
Self::Info(command) => command.run(env),
|
Self::Info(command) => command.run(env),
|
||||||
Self::Select(command) => command.run(env),
|
Self::Select(command) => command.run(env),
|
||||||
Self::Add(command) => command.run(env),
|
Self::Add(command) => command.run(env),
|
||||||
|
Self::Rename(command) => command.run(env),
|
||||||
Self::Remove(command) => command.run(env),
|
Self::Remove(command) => command.run(env),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
gdn-cli/src/commands/repo/rename.rs
Normal file
24
gdn-cli/src/commands/repo/rename.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
use crate::Environment;
|
||||||
|
|
||||||
|
/// Rename an existing repository.
|
||||||
|
#[derive(Debug, Parser)]
|
||||||
|
pub struct Command {
|
||||||
|
repo: String,
|
||||||
|
name: 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::rename_repo(&data, id, self.name.clone())?;
|
||||||
|
println!("Renamed repo {} ({id}) to {}.", self.repo, self.name);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,8 +13,8 @@ pub use crate::repo::VERSION as REPO_VERSION;
|
||||||
pub use self::{
|
pub use self::{
|
||||||
datadir::{LockedDataDir, UnlockedDataDir},
|
datadir::{LockedDataDir, UnlockedDataDir},
|
||||||
v1::{
|
v1::{
|
||||||
State, VERSION, add_repo, load_repo, load_repo_version, load_state, remove_repo, save_repo,
|
State, VERSION, add_repo, load_repo, load_repo_version, load_state, remove_repo,
|
||||||
select_repo, tidy,
|
rename_repo, save_repo, select_repo, tidy,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ pub fn remove_repo(dir: &LockedDataDir, id: RepoId) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_repo_name(dir: &LockedDataDir, id: RepoId, name: String) -> anyhow::Result<()> {
|
pub fn rename_repo(dir: &LockedDataDir, id: RepoId, name: String) -> anyhow::Result<()> {
|
||||||
let mut state = load_state(dir)?;
|
let mut state = load_state(dir)?;
|
||||||
*state
|
*state
|
||||||
.repos
|
.repos
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue