use crate::config::Config;
use crate::ui;
use crate::ListArgs;
use std::collections::BTreeMap;
pub fn list(config: Config, args: &ListArgs) {
if let Some(name) = &args.repo {
let repo = config.repo_by_name(name).unwrap_or_else(|| {
ui::error(&format!("unknown repo '{}'", name));
std::process::exit(1);
});
print_map(&format!("Repo \"{}\" commands", repo.name), &repo.commands);
return;
}
ui::heading(&format!("Project \"{}\" commands", config.project_name));
print_map("project", &config.commands);
for repo in config.repos.iter().filter(|r| !r.commands.is_empty()) {
print_map(&format!("repo \"{}\"", repo.name), &repo.commands);
}
}
fn print_map(title: &str, m: &BTreeMap<String, String>) {
if m.is_empty() {
ui::info(&format!(" {} — (none)", title));
return;
}
for (k, v) in m {
ui::info(&format!(" {} {}", k, v));
}
}