the_code_graph_cli/commands/
clones.rs1use domain::error::Result;
2use domain::model::CloneConfig;
3use domain::use_cases::clones::CloneUseCase;
4
5use crate::adapters::fs::RealFileSystem;
6use crate::commands::helpers::open_graph;
7use crate::commands::ClonesArgs;
8use crate::output::{print, OutputFormat};
9
10pub fn run_clones(args: &ClonesArgs, output_format: OutputFormat) -> Result<()> {
11 let (store, root) = open_graph()?;
12 let fs = RealFileSystem;
13 let uc = CloneUseCase::new(store, fs, root);
14
15 let config = CloneConfig {
16 threshold: args.threshold,
17 min_lines: args.min_lines,
18 ..CloneConfig::default()
19 };
20
21 let analysis = uc.analyze(&config)?;
22
23 if let Some(cluster_id) = args.cluster {
24 if let Some(cluster) = analysis.clusters.iter().find(|c| c.id == cluster_id) {
25 print(&vec![cluster.clone()], output_format);
26 } else {
27 eprintln!(
28 "cluster {cluster_id} not found ({} clusters total)",
29 analysis.clusters.len()
30 );
31 }
32 } else {
33 print(&analysis, output_format);
34 }
35 Ok(())
36}