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