dev_scope/report/
cli.rs

1use crate::shared::prelude::{
2    CaptureOpts, FoundConfig, OutputCapture, OutputDestination, ReportBuilder,
3};
4use anyhow::Result;
5use clap::Args;
6use tracing::warn;
7
8#[derive(Debug, Args)]
9pub struct ReportArgs {
10    /// Where the report will be generated, if not set a location will be determined at runtime.
11    #[arg(long, short = 'o')]
12    report_location: Option<String>,
13
14    /// The command that should be run and reported on
15    #[arg(last = true, required = true)]
16    command: Vec<String>,
17}
18
19pub async fn report_root(found_config: &FoundConfig, args: &ReportArgs) -> Result<i32> {
20    let capture = OutputCapture::capture_output(CaptureOpts {
21        working_dir: &found_config.working_dir,
22        args: &args.command,
23        output_dest: OutputDestination::Logging,
24        path: &found_config.bin_path,
25        env_vars: Default::default(),
26    })
27    .await?;
28    let exit_code = capture.exit_code.unwrap_or(-1);
29    let report_builder = ReportBuilder::new(&capture, found_config).await?;
30
31    if found_config.report_upload.is_empty() {
32        report_builder.write_local_report()?;
33        return Ok(exit_code);
34    }
35
36    if let Err(e) = report_builder.distribute_report().await {
37        warn!(target: "user", "Unable to upload report: {}", e);
38    }
39
40    Ok(exit_code)
41}