1use std::path::PathBuf;
6
7use anyhow::Result;
8
9use crate::parsers::parse_sbom;
10use crate::pipeline::exit_codes;
11use crate::serialization::{TailorConfig, tailor_sbom_json};
12
13pub fn run_tailor(
15 file: &PathBuf,
16 output_file: Option<&PathBuf>,
17 config: TailorConfig,
18 quiet: bool,
19) -> Result<i32> {
20 let raw_json = std::fs::read_to_string(file)?;
21 let sbom = parse_sbom(file)?;
22 let tailored = tailor_sbom_json(&raw_json, &sbom, &config)?;
23
24 match output_file {
25 Some(path) => {
26 std::fs::write(path, &tailored)?;
27 if !quiet {
28 eprintln!("Tailored SBOM written to {}", path.display());
29 }
30 }
31 None => {
32 println!("{tailored}");
33 }
34 }
35
36 Ok(exit_codes::SUCCESS)
37}