Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/holger

holger-build-thing/src/main.rs

//! `holger-build-thing` — the emission doors.
//!
//! ```text
//! holger-build-thing emit [root]   REGENERATE .nornir/build-variants.toml from the code
//! holger-build-thing toml          the emission, on stdout
//! holger-build-thing --list        every declared variant and what it builds
//! ```
//!
//! No build knowledge lives here: every answer is `HolgerBuildThing`'s.

use std::path::PathBuf;
use std::process::ExitCode;

fn main() -> ExitCode {
    let args: Vec<String> = std::env::args().skip(1).collect();
    match args.first().map(String::as_str) {
        Some("emit") => {
            let root = args
                .get(1)
                .map(PathBuf::from)
                .unwrap_or_else(holger_build_thing::repo_root);
            match holger_build_thing::write_emitted(&root) {
                Ok(p) => {
                    println!("emitted {}", p.display());
                    ExitCode::SUCCESS
                }
                Err(e) => fail(e),
            }
        }
        Some("toml") => match holger_build_thing::emitted_toml() {
            Ok(t) => {
                print!("{t}");
                ExitCode::SUCCESS
            }
            Err(e) => fail(e),
        },
        Some("--list") => {
            for v in holger_build_thing::declared().variants {
                let what = match (&v.package, &v.bin) {
                    (Some(_), Some(_)) => v.command_line(),
                    _ => format!(
                        "({} — composes other rows; runs no cargo)",
                        String::from(v.kind)
                    ),
                };
                println!("{:<22} {what}", v.name);
            }
            ExitCode::SUCCESS
        }
        _ => {
            eprintln!(
                "usage: holger-build-thing emit [root]   regenerate .nornir/build-variants.toml from the code
       holger-build-thing toml          the emission, on stdout
       holger-build-thing --list        every declared variant

The declaration is `HolgerBuildThing::variants` (holger-build-thing/src); the toml is
EMITTED from it (code -> toml, one-directional) and never read back as authority."
            );
            ExitCode::FAILURE
        }
    }
}

fn fail(e: anyhow::Error) -> ExitCode {
    eprintln!("holger-build-thing: {e:#}");
    ExitCode::FAILURE
}