pets_tools 0.2.0

MusKitty multi-repo source management CLI — one command to clone, build, test, push, and publish 9 independent crate repositories
//! `pets list <project>` — list user-defined commands from repos.toml.

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));
    }
}