use bpaf::{OptionParser, Parser, construct};
pub use haz_domain::scope::Scope;
pub use haz_domain::settings::output::OutputMode;
pub use haz_domain::task_ref::TaskRef;
pub use haz_vcs::GitFilter;
pub(super) mod cache;
pub(super) mod check;
pub(super) mod init;
pub(super) mod query;
pub(super) mod run;
pub(super) mod why;
use crate::cli::cache::cache_command;
use crate::cli::check::check_command;
use crate::cli::init::init_command;
use crate::cli::query::query_command;
use crate::cli::run::run_command;
use crate::cli::why::why_command;
pub use crate::cli::cache::CacheCleanArgs;
pub use crate::cli::check::CheckArgs;
pub use crate::cli::init::InitArgs;
pub use crate::cli::query::{FieldPresence, OutputFormat, QueryArgs};
pub use crate::cli::run::RunArgs;
pub use crate::cli::why::WhyArgs;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Cmd {
Run(RunArgs),
Check(CheckArgs),
Why(WhyArgs),
CacheClear,
CacheClean(CacheCleanArgs),
CacheInfo,
Query(QueryArgs),
Init(InitArgs),
}
pub fn cli() -> OptionParser<Cmd> {
let run = run_command().map(Cmd::Run).to_options();
let check = check_command().map(Cmd::Check).to_options();
let why = why_command().map(Cmd::Why).to_options();
let cache = cache_command().to_options();
let query = query_command().map(Cmd::Query).to_options();
let init = init_command().map(Cmd::Init).to_options();
let run_subcommand = run.command("run").help("Run one or more tasks");
let check_subcommand = check
.command("check")
.help("Validate the workspace without running (AUX-009..AUX-012)");
let why_subcommand = why
.command("why")
.help("Introspect a single task (AUX-013..AUX-016)");
let cache_subcommand = cache
.command("cache")
.help("Cache management commands (CACHE-021, CACHE-022)");
let query_subcommand = query
.command("query")
.help("Enumerate tasks under a filter expression (QRY-001..QRY-009)");
let init_subcommand = init
.command("init")
.help("Scaffold a workspace (AUX-001..AUX-008)");
construct!([
run_subcommand,
check_subcommand,
why_subcommand,
cache_subcommand,
query_subcommand,
init_subcommand,
])
.to_options()
.version(env!("CARGO_PKG_VERSION"))
.descr("haz: task dependency graph runner")
}
#[cfg(test)]
fn parse(args: &[&str]) -> Result<Cmd, String> {
cli().run_inner(args).map_err(|err| err.unwrap_stderr())
}
#[cfg(test)]
mod tests {
use super::parse;
#[test]
fn no_subcommand_rejects() {
let err = parse(&[]).unwrap_err();
assert!(
!err.is_empty(),
"missing subcommand must produce a diagnostic",
);
}
}