Add repo select command
This commit is contained in:
parent
c9a7b6fa91
commit
11d03aac57
3 changed files with 41 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ mod add;
|
||||||
mod info;
|
mod info;
|
||||||
mod list;
|
mod list;
|
||||||
mod remove;
|
mod remove;
|
||||||
|
mod select;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
|
|
@ -18,6 +19,9 @@ pub enum Command {
|
||||||
#[command(visible_alias = "i")]
|
#[command(visible_alias = "i")]
|
||||||
Info(info::Command),
|
Info(info::Command),
|
||||||
|
|
||||||
|
#[command(visible_alias = "s")]
|
||||||
|
Select(select::Command),
|
||||||
|
|
||||||
#[command(visible_alias = "a")]
|
#[command(visible_alias = "a")]
|
||||||
Add(add::Command),
|
Add(add::Command),
|
||||||
|
|
||||||
|
|
@ -30,6 +34,7 @@ impl Command {
|
||||||
match self {
|
match self {
|
||||||
Self::List(command) => command.run(env),
|
Self::List(command) => command.run(env),
|
||||||
Self::Info(command) => command.run(env),
|
Self::Info(command) => command.run(env),
|
||||||
|
Self::Select(command) => command.run(env),
|
||||||
Self::Add(command) => command.run(env),
|
Self::Add(command) => command.run(env),
|
||||||
Self::Remove(command) => command.run(env),
|
Self::Remove(command) => command.run(env),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
gdn-cli/src/commands/repo/select.rs
Normal file
32
gdn-cli/src/commands/repo/select.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
use crate::Environment;
|
||||||
|
|
||||||
|
/// Select a 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)?;
|
||||||
|
|
||||||
|
if self.repo.is_empty() {
|
||||||
|
println!("Deselecting repo");
|
||||||
|
gdn::data::select_repo(&data, None)?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let Some(id) = state.resolve_repo_identifier(&self.repo) else {
|
||||||
|
println!("No repo found for identifier {}.", self.repo);
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("Selecting repo {id}");
|
||||||
|
gdn::data::select_repo(&data, Some(id))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,10 @@ 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, remove_repo, tidy},
|
v1::{
|
||||||
|
State, VERSION, add_repo, load_repo, load_repo_version, load_state, remove_repo,
|
||||||
|
select_repo, tidy,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn migrate(dir: &LockedDataDir) -> anyhow::Result<()> {
|
fn migrate(dir: &LockedDataDir) -> anyhow::Result<()> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue