use crate::shared::prelude::{
CaptureOpts, FoundConfig, OutputCapture, OutputDestination, ReportBuilder,
};
use anyhow::Result;
use clap::Args;
use tracing::warn;
#[derive(Debug, Args)]
pub struct ReportArgs {
#[arg(long, short = 'o')]
report_location: Option<String>,
#[arg(last = true, required = true)]
command: Vec<String>,
}
pub async fn report_root(found_config: &FoundConfig, args: &ReportArgs) -> Result<i32> {
let capture = OutputCapture::capture_output(CaptureOpts {
working_dir: &found_config.working_dir,
args: &args.command,
output_dest: OutputDestination::Logging,
path: &found_config.bin_path,
env_vars: Default::default(),
})
.await?;
let exit_code = capture.exit_code.unwrap_or(-1);
let report_builder = ReportBuilder::new(&capture, found_config).await?;
if found_config.report_upload.is_empty() {
report_builder.write_local_report()?;
return Ok(exit_code);
}
if let Err(e) = report_builder.distribute_report().await {
warn!(target: "user", "Unable to upload report: {}", e);
}
Ok(exit_code)
}