starmap-cli 0.4.4

The starmap command, which checks, explains, compares and runs an application's declared environment
Documentation
//! The `starmap` binary, which runs the command that the starmap-cli
//! library holds.

use std::process::ExitCode;

/// Reads the process's environment once (BASE-6), starts the usage log and
/// runs the command. Returning the exit code lets destructors run before the
/// process ends (BASE-7).
fn main() -> ExitCode {
    // A shell's completion request ends the run here, before the usage log
    // starts, so a Tab press writes no line. starmap parses against
    // `Cli::command()`, so completion offers what parsing accepts.
    if let Some(code) = crumbkit::complete(<starmap_cli::Cli as clap::CommandFactory>::command) {
        return code;
    }
    // The guard writes this run's line to the usage log when `main`
    // returns, after the output is flushed (CLI-7).
    let _log = start_log();
    #[expect(
        clippy::disallowed_methods,
        reason = "BASE-6: main reads the environment once, and check and explain read the declared variables from this snapshot"
    )]
    let vars = std::env::vars_os().collect();
    starmap_cli::run(std::env::args_os(), vars)
}

/// Starts the usage log and, on Unix, the thread that stops each running
/// child's process group when starmap receives SIGINT, SIGTERM or SIGHUP,
/// such as `op` during a secret lookup or git during `starmap diff`. The
/// forwarder then writes the usage line, as the log's first clean-up, and
/// ends starmap as the signal would have.
#[cfg(unix)]
fn start_log() -> crumbkit_usage::Log {
    let log = crumbkit_usage::start_under(crumbkit_process::forward::clean_up);
    // A forwarder that cannot start leaves each signal its default action:
    // starmap ends at once, writes no usage line, and a running child's
    // group keeps running, as before the forwarder existed. starmap has
    // no output yet to report this on.
    let _ = crumbkit_process::forward::install();
    log
}

/// Starts the usage log, which ends starmap on Ctrl-C after it writes the
/// line. Only Unix has the signal forwarder.
#[cfg(not(unix))]
fn start_log() -> crumbkit_usage::Log {
    crumbkit_usage::start()
}