use bpaf::{Parser, construct, long};
use crate::cli::Scope;
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct CheckArgs {
pub scope: Scope,
}
pub(super) fn check_command() -> impl Parser<CheckArgs> {
let all = long("all")
.help("Validate every task in the bearing scope (AUX-009, mirrors EXEC-024)")
.switch();
let workspace = long("workspace")
.help("Validate every task in every project, regardless of cwd (AUX-009, mirrors EXEC-025)")
.switch();
construct!(all, workspace)
.parse(|(all, workspace)| {
Scope::from_flags(all, workspace)
.map(|scope| CheckArgs { scope })
.ok_or_else(|| "`--all` and `--workspace` are mutually exclusive".to_owned())
})
}
#[cfg(test)]
mod tests {
use super::CheckArgs;
use crate::cli::{Cmd, Scope, parse};
#[test]
fn aux_009_check_with_no_args_parses() {
assert_eq!(parse(&["check"]).unwrap(), Cmd::Check(CheckArgs::default()),);
}
#[test]
fn aux_009_check_with_all_flag_parses() {
assert_eq!(
parse(&["check", "--all"]).unwrap(),
Cmd::Check(CheckArgs { scope: Scope::All }),
);
}
#[test]
fn aux_009_check_with_workspace_flag_parses() {
assert_eq!(
parse(&["check", "--workspace"]).unwrap(),
Cmd::Check(CheckArgs {
scope: Scope::Workspace,
}),
);
}
#[test]
fn aux_009_check_all_plus_workspace_rejects() {
let err = parse(&["check", "--all", "--workspace"]).unwrap_err();
assert!(
err.contains("mutually exclusive"),
"diagnostic should name the mutex: {err}",
);
}
#[test]
fn aux_009_check_rejects_unknown_flag() {
let err = parse(&["check", "--dry-run"]).unwrap_err();
assert!(
!err.is_empty(),
"unknown flag must produce a diagnostic: {err}",
);
}
#[test]
fn aux_009_check_rejects_positional() {
let err = parse(&["check", "lib:build"]).unwrap_err();
assert!(
!err.is_empty(),
"positional argument must produce a diagnostic: {err}",
);
}
}