Skip to main content

callisto_cli/commands/
validate.rs

1use std::process::ExitCode;
2
3use callisto_graph::commands::ValidateOptions;
4
5use crate::cli::{GlobalArgs, OutputFormat, ValidateArgs};
6use crate::error::CliError;
7use crate::output::write_json;
8use crate::render;
9use crate::runner::CliCommandRunner;
10use crate::workspace::load_workspace;
11
12pub fn handle(args: ValidateArgs, global: &GlobalArgs) -> Result<ExitCode, CliError> {
13    let runner = CliCommandRunner;
14    let ws = load_workspace(global, &runner)?;
15
16    let opts = ValidateOptions {
17        staged: args.staged,
18        since: args.since,
19        strict: args.strict,
20        strict_graph: args.strict_graph,
21    };
22
23    let report = callisto_graph::commands::validate(&ws, &opts)?;
24
25    match global.format {
26        OutputFormat::Json => write_json(&mut std::io::stdout(), &report)?,
27        OutputFormat::Text => render::render_validate(&report, &mut std::io::stdout())?,
28    }
29
30    if report.valid {
31        Ok(ExitCode::SUCCESS)
32    } else {
33        Ok(ExitCode::FAILURE)
34    }
35}