workspacer_cli/
check_publish_ready_crate.rs

1// ---------------- [ File: workspacer-cli/src/check_publish_ready_crate.rs ]
2crate::ix!();
3
4/// For checking a single crate, we use the typical pattern of:
5///   - `--crate <name>` to identify the crate
6///   - optional `--workspace <path>` to specify the workspace root
7///   - `--skip-git-check` to skip ensuring a clean Git state
8#[derive(Debug, StructOpt, Getters, Setters)]
9#[getset(get = "pub")]
10pub struct CheckPublishReadyCrateCommand {
11    /// The name of the crate to check
12    #[structopt(long = "crate")]
13    crate_name: String,
14
15    /// If provided, we use this path as the workspace root instead of the current directory
16    #[structopt(long = "workspace")]
17    workspace_path: Option<PathBuf>,
18
19    /// If true, we skip the Git clean check
20    #[structopt(long = "skip-git-check")]
21    skip_git_check: bool,
22}
23
24impl CheckPublishReadyCrateCommand {
25    #[tracing::instrument(level = "trace", skip(self))]
26    pub async fn run(&self) -> Result<(), WorkspaceError> {
27        let crate_name_owned = self.crate_name().clone();
28
29        // We do our usual pattern: load the workspace, optionally check Git, validate integrity, etc.
30        run_with_workspace_and_crate_name(
31            self.workspace_path().clone(),
32            *self.skip_git_check(),
33            crate_name_owned,
34            |ws, name| {
35                Box::pin(async move {
36                    // 1) find the crate by name
37                    let arc_crate = ws.find_crate_by_name(name).await.ok_or_else(|| {
38                        error!("No crate named '{}' found in workspace", name);
39                        CrateError::CrateNotFoundInWorkspace {
40                            crate_name: name.to_owned(),
41                        }
42                    })?;
43
44                    // 2) lock the crate handle
45                    let handle = arc_crate.lock().await.clone();
46
47                    // 3) call `handle.ready_for_cargo_publish().await`
48                    handle.ready_for_cargo_publish().await.map_err(|cr_err| {
49                        error!("Crate '{}' not ready for publish: {:?}", name, cr_err);
50                        WorkspaceError::CrateError(cr_err)
51                    })?;
52
53                    info!("Crate '{}' is READY for publishing!", name);
54                    Ok(())
55                })
56            },
57        )
58        .await
59    }
60}