1use crate::error::Result;
2use crate::git::CliOps;
3use crate::read::deps::{find_dependents, DepsQuery};
4
5pub fn run(
6 path: String,
7 anchor: Option<String>,
8 max_results: u32,
9 scan_limit: u32,
10 format: String,
11 compact: bool,
12) -> Result<()> {
13 let repo_dir = std::env::current_dir().map_err(|e| crate::error::ChronicleError::Io {
14 source: e,
15 location: snafu::Location::default(),
16 })?;
17 let git_ops = CliOps::new(repo_dir);
18
19 let query = DepsQuery {
20 file: path,
21 anchor,
22 max_results,
23 scan_limit,
24 };
25
26 let result =
27 find_dependents(&git_ops, &query).map_err(|e| crate::error::ChronicleError::Git {
28 source: e,
29 location: snafu::Location::default(),
30 })?;
31
32 let json = if compact {
33 let compact_out = serde_json::json!({
34 "dependents": result.dependents,
35 });
36 serde_json::to_string_pretty(&compact_out)
37 } else if format == "pretty" {
38 serde_json::to_string_pretty(&result)
39 } else {
40 serde_json::to_string(&result)
41 }
42 .map_err(|e| crate::error::ChronicleError::Json {
43 source: e,
44 location: snafu::Location::default(),
45 })?;
46
47 println!("{json}");
48 Ok(())
49}