workspacer_cli/
coverage_workspace.rs

1// ---------------- [ File: workspacer-cli/src/coverage_workspace.rs ]
2crate::ix!();
3
4/// Subcommand for `ws coverage workspace [--path ...] [--skip-git-check]`
5#[derive(Debug,StructOpt,Getters,Setters)]
6#[getset(get="pub")]
7pub struct CoverageWorkspaceCommand {
8    /// optional workspace path
9    #[structopt(long = "path")]
10    workspace_path: Option<PathBuf>,
11
12    /// skip git check
13    #[structopt(long = "skip-git-check")]
14    skip_git_check: bool,
15}
16
17impl CoverageWorkspaceCommand {
18    pub async fn run(&self) -> Result<(), WorkspaceError> {
19        // We'll do `run_with_workspace(...)` => load => call `ws.run_tests_with_coverage()`.
20        run_with_workspace(
21            self.workspace_path().clone(),
22            *self.skip_git_check(),
23            |ws| {
24                Box::pin(async move {
25                    let coverage_report = ws.run_tests_with_coverage().await?;
26                    info!("Workspace coverage: {coverage_report:?}");
27
28                    println!(
29                        "Workspace coverage => {:.2}% (covered: {}, missed: {}, total: {})",
30                        coverage_report.total_coverage(),
31                        coverage_report.covered_lines(),
32                        coverage_report.missed_lines(),
33                        coverage_report.total_lines()
34                    );
35
36                    Ok(())
37                })
38            },
39        )
40        .await
41    }
42}