workspacer_cli/
pin.rs

1// ---------------- [ File: workspacer-cli/src/pin.rs ]
2crate::ix!();
3
4#[derive(Debug, StructOpt)]
5pub enum PinSubcommand {
6    /// Pin wildcard dependencies in a single crate
7    Crate {
8        #[structopt(long = "crate")]
9        crate_name: PathBuf,
10
11        #[structopt(long = "skip-git-check")]
12        skip_git_check: bool,
13    },
14
15    /// Pin wildcard dependencies in an entire workspace
16    Workspace {
17        #[structopt(long = "path")]
18        path: PathBuf,
19
20        #[structopt(long = "skip-git-check")]
21        skip_git_check: bool,
22    },
23}
24
25impl PinSubcommand {
26    pub async fn run(&self) -> Result<(), WorkspaceError> {
27        match self {
28            // ----------------------------------------------------
29            // 1) Single crate
30            // ----------------------------------------------------
31            PinSubcommand::Crate { crate_name, skip_git_check } => {
32                trace!("Pinning wildcard deps for single crate at '{}'", crate_name.display());
33
34                // We'll use the `run_with_crate` helper so we load the crate,
35                // optionally check Git, etc., then call `pin_all_wildcard_dependencies()`.
36                run_with_crate(crate_name.clone(), *skip_git_check, |handle| {
37                    Box::pin(async move {
38
39                        // The `PinAllWildcardDependencies` trait is implemented for `CrateHandle`
40                        handle.pin_all_wildcard_dependencies().await.map_err(|crate_err| {
41                            error!("Failed to pin wildcard deps in crate='{}': {:?}", handle.name(), crate_err);
42                            WorkspaceError::CrateError(crate_err)
43                        })?;
44
45                        info!("Successfully pinned wildcard dependencies for crate='{}'", handle.name());
46                        Ok(())
47                    })
48                })
49                .await
50            }
51
52            // ----------------------------------------------------
53            // 2) Entire workspace
54            // ----------------------------------------------------
55            PinSubcommand::Workspace { path, skip_git_check } => {
56                trace!("Pinning wildcard deps for workspace at '{}'", path.display());
57
58                // We'll use `run_with_workspace` to load the workspace,
59                // optionally check Git, then call `pin_all_wildcard_dependencies()`.
60                run_with_workspace(Some(path.clone()), *skip_git_check, |ws| {
61                    Box::pin(async move {
62                        // The `PinAllWildcardDependencies` trait is implemented for `Workspace<P,H>`
63                        ws.pin_all_wildcard_dependencies().await.map_err(|we| {
64                            error!(
65                                "Failed to pin wildcard dependencies in workspace at '{}': {:?}",
66                                ws.as_ref().display(),
67                                we
68                            );
69                            we
70                        })?;
71
72                        info!("Successfully pinned wildcard dependencies in workspace at '{}'", ws.as_ref().display());
73                        Ok(())
74                    })
75                })
76                .await
77            }
78        }
79    }
80}