haz-cli 0.1.0

Command-line task runner: tracks task DAGs across a workspace of projects, executes them with caching.
Documentation
//! `haz` workspace task runner: library surface for the `haz`
//! binary.
//!
//! Exposes the runtime modules wired together by the `haz`
//! command-line tool (`src/main.rs`). Integration tests under
//! `tests/` drive these modules directly against fixture
//! workspaces; the binary itself is a thin adapter over
//! [`dispatch`].

pub mod cli;
pub mod commands;
pub mod output;

mod workspace_load;

use std::path::Path;

use cli::Cmd;
use miette::Result;

/// Exit code reserved for workspace-load failures, target-
/// resolution failures, and other internal / configuration errors
/// per `EXEC-021`'s fourth class. Distinct from
/// `haz_exec::exit_code`'s task-failure code (`1`) and the POSIX
/// signal codes (`130` / `143`).
pub const EXIT_INTERNAL_OR_CONFIG_ERROR: i32 = 2;

/// Dispatch a parsed [`Cmd`] against `cwd` and return the per-
/// command exit code.
///
/// `cwd` is a parameter rather than read from
/// [`std::env::current_dir`] so callers (the binary, integration
/// tests, embedders) drive the dispatch deterministically. The
/// binary's `main` reads cwd from the environment once and passes
/// it here.
///
/// # Errors
///
/// Returns a [`miette::Report`] on workspace-load, target-
/// resolution, or scheduler failure. The binary maps any report
/// to [`EXIT_INTERNAL_OR_CONFIG_ERROR`].
pub fn dispatch(cmd: &Cmd, cwd: &Path) -> Result<i32> {
    match cmd {
        Cmd::Run(args) => commands::run::execute(args, cwd),
        Cmd::Check(args) => commands::check::execute(args, cwd),
        Cmd::Why(args) => commands::why::execute(args, cwd),
        Cmd::CacheClear => commands::cache::clear(cwd),
        Cmd::CacheClean(args) => commands::cache::clean(cwd, args),
        Cmd::CacheInfo => commands::cache::info(cwd),
        Cmd::Query(args) => commands::query::execute(args, cwd),
        Cmd::Init(args) => commands::init::execute(args, cwd),
    }
}