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 list;
|
||||
mod remove;
|
||||
mod rename;
|
||||
mod select;
|
||||
|
||||
use clap::Parser;
|
||||
|
|
@ -25,6 +26,9 @@ pub enum Command {
|
|||
#[command(visible_alias = "a")]
|
||||
Add(add::Command),
|
||||
|
||||
#[command(visible_alias = "rn")]
|
||||
Rename(rename::Command),
|
||||
|
||||
#[command(visible_alias = "r")]
|
||||
Remove(remove::Command),
|
||||
}
|
||||
|
|
@ -36,6 +40,7 @@ impl Command {
|
|||
Self::Info(command) => command.run(env),
|
||||
Self::Select(command) => command.run(env),
|
||||
Self::Add(command) => command.run(env),
|
||||
Self::Rename(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(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue