haz-cli 0.2.0

Command-line task runner: tracks task DAGs across a workspace of projects, executes them with caching.
Documentation
//! Parser for the `haz init` subcommand.
//!
//! Owns [`InitArgs`] and the [`init_command`] parser builder.
//! `AUX-001` admits the bare interactive form and the `--yes`
//! minimal-scaffold form; both parse here and the executor selects
//! the branch.

use bpaf::{Parser, construct, long};

/// Arguments parsed for the `haz init` subcommand.
///
/// `AUX-001` admits exactly two invocation shapes: the bare form
/// (which would run the interactive scaffold flow,
/// `AUX-003`..`AUX-005`) and `--yes` (which writes the minimal
/// `projects: []` workspace per `AUX-007`). Both forms parse;
/// the executor selects the branch.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct InitArgs {
    /// `--yes`: skip the interactive flow per `AUX-007`.
    pub yes: bool,
}

pub(super) fn init_command() -> impl Parser<InitArgs> {
    let yes = long("yes")
        .help("Skip the interactive flow and write a minimal workspace (AUX-007)")
        .switch();
    construct!(InitArgs { yes })
}

#[cfg(test)]
mod tests {
    use super::InitArgs;
    use crate::cli::{Cmd, parse};

    #[test]
    fn aux_001_init_bare_parses_with_yes_false() {
        assert_eq!(
            parse(&["init"]).unwrap(),
            Cmd::Init(InitArgs { yes: false }),
        );
    }

    #[test]
    fn aux_001_init_with_yes_flag_parses() {
        assert_eq!(
            parse(&["init", "--yes"]).unwrap(),
            Cmd::Init(InitArgs { yes: true }),
        );
    }

    #[test]
    fn aux_001_init_rejects_positional_argument() {
        let err = parse(&["init", "extra"]).unwrap_err();
        assert!(
            !err.is_empty(),
            "positional argument must produce a diagnostic: {err}",
        );
    }

    #[test]
    fn aux_001_init_rejects_unknown_flag() {
        let err = parse(&["init", "--no-such-flag"]).unwrap_err();
        assert!(
            !err.is_empty(),
            "unknown flag must produce a diagnostic: {err}",
        );
    }
}