workspacer_cli/
check_publish_ready_workspace.rs

1// ---------------- [ File: workspacer-cli/src/check_publish_ready_workspace.rs ]
2crate::ix!();
3
4/// For checking the entire workspace, we do a simpler approach:
5///   - optional `--path` for the workspace root
6///   - `--skip-git-check` if desired
7#[derive(Debug, StructOpt, Getters, Setters)]
8#[getset(get = "pub")]
9pub struct CheckPublishReadyWorkspaceCommand {
10    /// If provided, use this as the workspace root
11    #[structopt(long = "path")]
12    workspace_path: Option<PathBuf>,
13
14    /// Skip Git clean check
15    #[structopt(long = "skip-git-check")]
16    skip_git_check: bool,
17}
18
19impl CheckPublishReadyWorkspaceCommand {
20    #[tracing::instrument(level = "trace", skip(self))]
21    pub async fn run(&self) -> Result<(), WorkspaceError> {
22        // We do `run_with_workspace` => obtains &mut Workspace => call `ws.ready_for_cargo_publish().await`
23        run_with_workspace(
24            self.workspace_path().clone(),
25            *self.skip_git_check(),
26            |ws| {
27                Box::pin(async move {
28                    // This calls the library trait on the entire workspace
29                    ws.ready_for_cargo_publish().await.map_err(|err| {
30                        error!("Workspace is NOT ready for publish: {:?}", err);
31                        err
32                    })?;
33
34                    info!("All crates in workspace are READY for publish!");
35                    Ok(())
36                })
37            },
38        ).await
39    }
40}