1use crate::error::MarsError;
4use crate::sync::{ResolutionMode, SyncOptions, SyncRequest};
5
6use super::output;
7
8#[derive(Debug, clap::Args)]
10pub struct SyncArgs {
11 #[arg(long)]
13 pub force: bool,
14
15 #[arg(long)]
17 pub diff: bool,
18
19 #[arg(long)]
21 pub frozen: bool,
22
23 #[arg(long)]
25 pub no_refresh_models: bool,
26}
27
28pub fn run(args: &SyncArgs, ctx: &super::MarsContext, json: bool) -> Result<i32, MarsError> {
30 let request = SyncRequest {
31 resolution: ResolutionMode::Normal,
32 mutation: None,
33 options: SyncOptions {
34 force: args.force,
35 dry_run: args.diff,
36 frozen: args.frozen,
37 no_refresh_models: args.no_refresh_models,
38 },
39 };
40
41 let report = crate::sync::execute(ctx, &request)?;
42
43 output::print_sync_report(&report, json);
44
45 if report.has_conflicts() { Ok(1) } else { Ok(0) }
46}
47
48#[cfg(test)]
49mod tests {
50 use crate::cli::{Cli, Command};
51 use clap::Parser;
52
53 #[test]
54 fn parses_no_refresh_models() {
55 let cli = Cli::try_parse_from(["mars", "sync", "--no-refresh-models"]).unwrap();
56 let Command::Sync(args) = cli.command else {
57 panic!("expected sync command");
58 };
59 assert!(args.no_refresh_models);
60 }
61}