//! `omne` — CLI entrypoint.
//!
//! Parses the clap `Cli` struct, dispatches via an exhaustive match on
//! `cli::Command`, maps `CliError` variants to exit codes (0 success,
//! 1 logical error; clap parse failures exit 2 via clap itself), and
//! prints errors to stderr with a red `error:` prefix.

mod claude_proc;
mod claude_skills;
mod cli;
mod clock;
mod commands;
mod dag;
mod defaults;
mod distro;
mod error;
mod event_log;
mod events;
mod executor;
mod fetch;
mod github;
mod manifest;
mod pipe;
mod python;
mod run_state;
mod scaffold;
mod sentinel;
mod tarball;
mod ulid;
mod volume;
mod worktree;

use clap::Parser;

use crate::cli::{Cli, Command};

fn main() {
    let parsed = Cli::parse();

    let result = match parsed.command {
        Command::Init(args) => commands::init::run(&args),
        Command::Upgrade(args) => commands::upgrade::run(&args),
        Command::Validate(args) => commands::validate::run(&args),
        Command::Run(args) => commands::run::run(&args),
        Command::Status(args) => commands::status::run(&args),
    };

    if let Err(err) = result {
        // Red "error:" prefix. ANSI escapes work on modern Windows
        // terminals (Windows 10+ with VT enabled) and all Unix TTYs.
        // Proper TTY-aware coloring via `anstream` / `indicatif` lands
        // in Phase 2 when the progress bar needs it.
        eprintln!("\x1b[31merror:\x1b[0m {err}");
        if let error::CliError::ValidationFailed { issues } = &err {
            for issue in issues {
                eprintln!("  - {issue}");
            }
        }
        std::process::exit(err.exit_code());
    }
}
