workspacer_cli/
detect_cycles_workspace.rs

1// ---------------- [ File: workspacer-cli/src/detect_cycles_workspace.rs ]
2crate::ix!();
3
4#[derive(Debug, StructOpt, Getters, Setters)]
5#[getset(get="pub")]
6pub struct DetectCyclesWorkspaceCommand {
7    /// If provided, custom workspace path
8    #[structopt(long = "path")]
9    workspace_path: Option<PathBuf>,
10
11    /// If true, we print extra logs
12    #[structopt(long = "verbose")]
13    verbose: bool,
14
15    /// If true, skip the Git clean check
16    #[structopt(long = "skip-git-check")]
17    skip_git_check: bool,
18}
19
20impl DetectCyclesWorkspaceCommand {
21    pub async fn run(&self) -> Result<(), WorkspaceError> {
22        // Again, copy out fields
23        let workspace_path_owned = self.workspace_path.clone();
24        let verbose_flag = self.verbose;
25        let skip_check = self.skip_git_check;
26
27        run_with_workspace(
28            workspace_path_owned,
29            skip_check,
30            move |ws| {
31                Box::pin(async move {
32                    if verbose_flag {
33                        info!("Checking for circular dependencies across the entire workspace ...");
34                    }
35
36                    ws.detect_circular_dependencies().await.map_err(|err| {
37                        error!("Failed detecting cycles in workspace: {:?}", err);
38                        err
39                    })?;
40
41                    if verbose_flag {
42                        info!("No circular dependencies found in this workspace!");
43                    } else {
44                        println!("No circular dependencies found.");
45                    }
46                    Ok(())
47                })
48            },
49        )
50        .await
51    }
52}