Skip to main content

callisto_cli/commands/
version.rs

1use std::process::ExitCode;
2
3use callisto_graph::apply::{apply_version_plan, ApplyOptions};
4use callisto_graph::commands::VersionOptions;
5use callisto_graph::infer::NoInference;
6
7use crate::cli::{GlobalArgs, OutputFormat, VersionArgs};
8use crate::error::CliError;
9use crate::output::write_json;
10use crate::render;
11use crate::runner::CliCommandRunner;
12use crate::workspace::load_workspace;
13
14pub fn handle(args: VersionArgs, global: &GlobalArgs) -> Result<ExitCode, CliError> {
15    let runner = CliCommandRunner;
16    let ws = load_workspace(global, &runner)?;
17
18    let inference = NoInference;
19    let opts = VersionOptions {
20        strict: args.strict,
21        strict_graph: args.strict_graph,
22        allow_empty_changesets: args.allow_empty_changesets,
23    };
24
25    let plan = callisto_graph::commands::plan_version(&ws, &inference, &opts)?;
26
27    let apply_opts = ApplyOptions {
28        refresh_lockfiles: args.refresh_lockfiles,
29        transient: global.dry_run,
30    };
31
32    let outcome = apply_version_plan(&ws.root, &plan, &runner, &apply_opts)?;
33    let report = plan.to_report(outcome.lockfile_refresh_results);
34
35    if global.dry_run && global.format == OutputFormat::Text {
36        println!("[DRY-RUN] Version Plan Calculated (no files modified):");
37    }
38
39    match global.format {
40        OutputFormat::Json => write_json(&mut std::io::stdout(), &report)?,
41        OutputFormat::Text => render::render_version(&report, &mut std::io::stdout())?,
42    }
43
44    Ok(ExitCode::SUCCESS)
45}