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) -> Result<()> {
12 let repo_dir = std::env::current_dir().map_err(|e| crate::error::ChronicleError::Io {
13 source: e,
14 location: snafu::Location::default(),
15 })?;
16 let git_ops = CliOps::new(repo_dir);
17
18 let query = DepsQuery {
19 file: path,
20 anchor,
21 max_results,
22 scan_limit,
23 };
24
25 let result =
26 find_dependents(&git_ops, &query).map_err(|e| crate::error::ChronicleError::Git {
27 source: e,
28 location: snafu::Location::default(),
29 })?;
30
31 let json = if format == "pretty" {
32 serde_json::to_string_pretty(&result)
33 } else {
34 serde_json::to_string(&result)
35 }
36 .map_err(|e| crate::error::ChronicleError::Json {
37 source: e,
38 location: snafu::Location::default(),
39 })?;
40
41 println!("{json}");
42 Ok(())
43}