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;
|
||||
|
||||
pub use self::list::print_repo_list;
|
||||
|
||||
/// Perform repo operations.
|
||||
#[derive(Debug, Parser)]
|
||||
pub enum Command {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use clap::Parser;
|
||||
use gdn::data::State;
|
||||
|
||||
use crate::Environment;
|
||||
|
||||
|
|
@ -10,11 +11,16 @@ impl Command {
|
|||
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
||||
let data = gdn::data::open(env.data_dir.clone())?;
|
||||
let state = gdn::data::load_state(&data)?;
|
||||
print_repo_list(&state);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_repo_list(state: &State) {
|
||||
let mut repos = state
|
||||
.repos
|
||||
.into_iter()
|
||||
.map(|(id, name)| (name, id))
|
||||
.iter()
|
||||
.map(|(id, name)| (name, *id))
|
||||
.collect::<Vec<_>>();
|
||||
repos.sort_unstable();
|
||||
|
||||
|
|
@ -24,13 +30,10 @@ impl Command {
|
|||
println!("Repos: {}", repos.len());
|
||||
for (name, id) in repos {
|
||||
if state.selected_repo == Some(id) {
|
||||
println!("- {name} ({id }, selected)");
|
||||
println!("- {name} ({id}, selected)");
|
||||
} else {
|
||||
println!("- {name} ({id })");
|
||||
println!("- {name} ({id})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use clap::Parser;
|
||||
|
||||
use crate::Environment;
|
||||
use crate::{Environment, commands::repo};
|
||||
|
||||
/// Display current status.
|
||||
#[derive(Debug, Parser)]
|
||||
|
|
@ -24,18 +24,7 @@ impl Command {
|
|||
let state = gdn::data::load_state(&data)?;
|
||||
|
||||
println!();
|
||||
if state.repos.is_empty() {
|
||||
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})");
|
||||
}
|
||||
}
|
||||
}
|
||||
repo::print_repo_list(&state);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue