workspacer_cli/
validate.rs

1// ---------------- [ File: workspacer-cli/src/validate.rs ]
2crate::ix!();
3
4/// Validate everything (or just one crate)
5#[derive(Debug, StructOpt)]
6pub enum ValidateSubcommand {
7    /// Validate a single crate
8    Crate {
9        /// Path to the crate (must contain a Cargo.toml)
10        #[structopt(long = "crate")]
11        crate_name: PathBuf,
12    },
13    /// Validate an entire workspace
14    Workspace {
15        /// Path to the workspace root (must contain a Cargo.toml with [workspace])
16        #[structopt(long = "path")]
17        workspace_path: PathBuf,
18    },
19}
20
21impl ValidateSubcommand {
22    pub async fn run(&self) -> Result<(), WorkspaceError> {
23        match self {
24            ValidateSubcommand::Crate { crate_name } => {
25                // 1) Build a CrateHandle from the given path
26                let handle = CrateHandle::new(crate_name).await.map_err(|crate_err| {
27                    // Convert CrateError -> WorkspaceError if needed:
28                    WorkspaceError::CrateError(crate_err)
29                })?;
30
31                // 2) Perform the validation
32                handle.validate_integrity().await.map_err(|crate_err| {
33                    WorkspaceError::CrateError(crate_err)
34                })?;
35
36                println!("Crate at '{}' passed integrity checks!", crate_name.display());
37            }
38
39            ValidateSubcommand::Workspace { workspace_path } => {
40                // 1) Build a Workspace from the given path
41                let ws = Workspace::<PathBuf, CrateHandle>::new(workspace_path).await?;
42
43                // 2) Validate all crates in that workspace
44                ws.validate_integrity().await?;
45
46                println!(
47                    "Workspace at '{}' passed integrity checks for all member crates!",
48                    workspace_path.display()
49                );
50            }
51        }
52
53        Ok(())
54    }
55}