Use repo list logic in status command
This commit is contained in:
parent
05477ee64f
commit
c9a7b6fa91
3 changed files with 28 additions and 34 deletions
|
|
@ -7,6 +7,8 @@ use clap::Parser;
|
||||||
|
|
||||||
use crate::Environment;
|
use crate::Environment;
|
||||||
|
|
||||||
|
pub use self::list::print_repo_list;
|
||||||
|
|
||||||
/// Perform repo operations.
|
/// Perform repo operations.
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use gdn::data::State;
|
||||||
|
|
||||||
use crate::Environment;
|
use crate::Environment;
|
||||||
|
|
||||||
|
|
@ -10,27 +11,29 @@ impl Command {
|
||||||
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
||||||
let data = gdn::data::open(env.data_dir.clone())?;
|
let data = gdn::data::open(env.data_dir.clone())?;
|
||||||
let state = gdn::data::load_state(&data)?;
|
let state = gdn::data::load_state(&data)?;
|
||||||
|
print_repo_list(&state);
|
||||||
let mut repos = state
|
|
||||||
.repos
|
|
||||||
.into_iter()
|
|
||||||
.map(|(id, name)| (name, id))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
repos.sort_unstable();
|
|
||||||
|
|
||||||
if repos.is_empty() {
|
|
||||||
println!("No repos");
|
|
||||||
} else {
|
|
||||||
println!("Repos: {}", repos.len());
|
|
||||||
for (name, id) in repos {
|
|
||||||
if state.selected_repo == Some(id) {
|
|
||||||
println!("- {name} ({id }, selected)");
|
|
||||||
} else {
|
|
||||||
println!("- {name} ({id })");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn print_repo_list(state: &State) {
|
||||||
|
let mut repos = state
|
||||||
|
.repos
|
||||||
|
.iter()
|
||||||
|
.map(|(id, name)| (name, *id))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
repos.sort_unstable();
|
||||||
|
|
||||||
|
if repos.is_empty() {
|
||||||
|
println!("No repos");
|
||||||
|
} else {
|
||||||
|
println!("Repos: {}", repos.len());
|
||||||
|
for (name, id) in repos {
|
||||||
|
if state.selected_repo == Some(id) {
|
||||||
|
println!("- {name} ({id}, selected)");
|
||||||
|
} else {
|
||||||
|
println!("- {name} ({id})");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
use crate::Environment;
|
use crate::{Environment, commands::repo};
|
||||||
|
|
||||||
/// Display current status.
|
/// Display current status.
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
|
|
@ -24,18 +24,7 @@ impl Command {
|
||||||
let state = gdn::data::load_state(&data)?;
|
let state = gdn::data::load_state(&data)?;
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
if state.repos.is_empty() {
|
repo::print_repo_list(&state);
|
||||||
println!("No repos");
|
|
||||||
} else {
|
|
||||||
println!("Repos ({}):", state.repos.len());
|
|
||||||
for (id, name) in &state.repos {
|
|
||||||
if state.selected_repo == Some(*id) {
|
|
||||||
println!("- {name} ({id}, selected)");
|
|
||||||
} else {
|
|
||||||
println!("- {name} ({id})");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue