workspacer_cli/
bump_single_crate.rs

1// ---------------- [ File: workspacer-cli/src/bump_single_crate.rs ]
2crate::ix!();
3
4/// Bump just a single crate (no downstream references updated).
5/// We use the `Bump` trait on the crate handle itself.
6#[derive(Debug, StructOpt, Getters, Setters)]
7#[getset(get = "pub")]
8pub struct BumpSingleCrateCommand {
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 BumpSingleCrateCommand {
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` => load workspace => find crate => apply Bump
32        run_with_workspace_and_crate_name(
33            self.workspace_path().clone(),
34            *self.skip_git_check(),
35            crate_name_owned,
36            move |ws, found_crate_name| {
37                Box::pin(async move {
38                    let arc_crate = ws.find_crate_by_name(found_crate_name).await.ok_or_else(|| {
39                        error!("No crate named '{}' found in workspace", found_crate_name);
40                        CrateError::CrateNotFoundInWorkspace {
41                            crate_name: found_crate_name.to_owned(),
42                        }
43                    })?;
44
45                    // Lock the crate to get a mutable handle
46                    let mut handle = arc_crate.lock().await.clone();
47                    handle.bump(release_type.clone()).await.map_err(|err| {
48                        error!(
49                            "Failed to bump crate='{}' with release={:?}: {:?}",
50                            found_crate_name, release_type, err
51                        );
52                        WorkspaceError::BumpError {
53                            crate_path: handle.as_ref().join("Cargo.toml"),
54                            source: Box::new(err),
55                        }
56                    })?;
57
58                    info!(
59                        "Successfully bumped single crate='{}' => release={:?}",
60                        found_crate_name, release_type
61                    );
62                    Ok(())
63                })
64            },
65        )
66        .await
67    }
68}