workspacer_cli/
bump_crate_downstreams.rs

1// ---------------- [ File: workspacer-cli/src/bump_crate_downstreams.rs ]
2crate::ix!();
3
4/// Bump a single crate and all crates that depend on it (recursively),
5/// using `BumpCrateAndDownstreams::bump_crate_and_downstreams`.
6#[derive(Debug, StructOpt, Getters, Setters)]
7#[getset(get="pub")]
8pub struct BumpCrateDownstreamsCommand {
9    /// The name of the crate to bump
10    #[structopt(long = "crate")]
11    crate_name: String,
12
13    /// If provided, we use this path as the workspace root
14    #[structopt(long = "workspace")]
15    workspace_path: Option<PathBuf>,
16
17    /// Skip Git clean check
18    #[structopt(long = "skip-git-check")]
19    skip_git_check: bool,
20
21    /// The release type to apply (major, minor, patch, alpha[=N])
22    #[structopt(long = "release", default_value = "patch")]
23    release_arg: ReleaseArg,
24}
25
26impl BumpCrateDownstreamsCommand {
27    pub async fn run(&self) -> Result<(), WorkspaceError> {
28        let crate_name_owned = self.crate_name().clone();
29        let ReleaseArg(release_type) = self.release_arg().clone();
30
31        // We'll do `run_with_workspace_and_crate_name`, find the crate,
32        // but *then* we call `bump_crate_and_downstreams` on the workspace.
33        run_with_workspace_and_crate_name(
34            self.workspace_path().clone(),
35            *self.skip_git_check(),
36            crate_name_owned,
37            move |ws, found_crate_name| {
38                Box::pin(async move {
39                    // find the crate
40                    let arc_crate = ws.find_crate_by_name(found_crate_name).await.ok_or_else(|| {
41                        error!("No crate named '{}' found in workspace", found_crate_name);
42                        CrateError::CrateNotFoundInWorkspace {
43                            crate_name: found_crate_name.to_owned(),
44                        }
45                    })?;
46
47                    // Lock crate to get a local handle
48                    let mut handle = arc_crate.lock().await.clone();
49
50                    ws.bump_crate_and_downstreams(&mut handle, release_type.clone())
51                        .await
52                        .map_err(|err| {
53                            error!(
54                                "Failed to bump crate='{}' + downstreams with release={:?}: {:?}",
55                                found_crate_name, release_type, err
56                            );
57                            err
58                        })?;
59
60                    info!(
61                        "Successfully bumped crate='{}' + downstreams => release={:?}",
62                        found_crate_name, release_type
63                    );
64                    Ok(())
65                })
66            },
67        )
68        .await
69    }
70}