use std::path::Path;
use sokf_core::CacheMode;
use crate::{cli::LocateArgs, output};
pub fn locate(
repo_root: Option<&Path>,
cache: CacheMode,
args: &LocateArgs,
) -> sokf_core::Result<u8> {
let (_, root) = output::root(repo_root)?;
let located = sokf_core::locate(&root, &args.ids, args.asset, cache)?;
let mut buf = Vec::new();
if args.json {
buf = output::json_line(&sokf_core::LocateReport::from(located.as_slice()))?;
} else {
for l in &located {
let path = if args.asset {
l.asset.as_ref().unwrap_or(&l.path)
} else {
&l.path
};
buf.extend_from_slice(path.display().to_string().as_bytes());
buf.push(b'\n');
}
}
output::write_stdout(&buf)?;
Ok(output::EXIT_OK)
}