haz_cli/lib.rs
1//! `haz` workspace task runner: library surface for the `haz`
2//! binary.
3//!
4//! Exposes the runtime modules wired together by the `haz`
5//! command-line tool (`src/main.rs`). Integration tests under
6//! `tests/` drive these modules directly against fixture
7//! workspaces; the binary itself is a thin adapter over
8//! [`dispatch`].
9
10pub mod cli;
11pub mod commands;
12pub mod output;
13
14mod workspace_load;
15
16use std::path::Path;
17
18use cli::Cmd;
19use miette::Result;
20
21/// Exit code reserved for workspace-load failures, target-
22/// resolution failures, and other internal / configuration errors
23/// per `EXEC-021`'s fourth class. Distinct from
24/// `haz_exec::exit_code`'s task-failure code (`1`) and the POSIX
25/// signal codes (`130` / `143`).
26pub const EXIT_INTERNAL_OR_CONFIG_ERROR: i32 = 2;
27
28/// Dispatch a parsed [`Cmd`] against `cwd` and return the per-
29/// command exit code.
30///
31/// `cwd` is a parameter rather than read from
32/// [`std::env::current_dir`] so callers (the binary, integration
33/// tests, embedders) drive the dispatch deterministically. The
34/// binary's `main` reads cwd from the environment once and passes
35/// it here.
36///
37/// # Errors
38///
39/// Returns a [`miette::Report`] on workspace-load, target-
40/// resolution, or scheduler failure. The binary maps any report
41/// to [`EXIT_INTERNAL_OR_CONFIG_ERROR`].
42pub fn dispatch(cmd: &Cmd, cwd: &Path) -> Result<i32> {
43 match cmd {
44 Cmd::Run(args) => commands::run::execute(args, cwd),
45 Cmd::Check(args) => commands::check::execute(args, cwd),
46 Cmd::Why(args) => commands::why::execute(args, cwd),
47 Cmd::CacheClear => commands::cache::clear(cwd),
48 Cmd::CacheClean(args) => commands::cache::clean(cwd, args),
49 Cmd::CacheInfo => commands::cache::info(cwd),
50 Cmd::Query(args) => commands::query::execute(args, cwd),
51 Cmd::Init(args) => commands::init::execute(args, cwd),
52 }
53}