workspacer_cli/
add_crate.rs

1// ---------------- [ File: workspacer-cli/src/add_crate.rs ]
2crate::ix!();
3
4#[derive(Getters,Setters,Debug,StructOpt)]
5#[getset(get="pub")]
6pub struct AddCrateCommand {
7    /// The name of the new crate to add
8    #[structopt(long = "crate")]
9    crate_name: String,
10
11    /// If provided, we use this path as the workspace root instead of the current directory
12    #[structopt(long = "workspace")]
13    workspace_path: Option<PathBuf>,
14
15    /// If true, we skip the Git clean check (i.e., do not require a clean repo)
16    #[structopt(long = "skip-git-check")]
17    skip_git_check: bool,
18}
19
20impl AddCrateCommand {
21
22    pub async fn run(&self) -> Result<(), WorkspaceError> {
23        trace!(
24            "AddSubcommand::Crate invoked with crate_name='{}', workspace_path='{:?}', skip_git_check={}",
25            self.crate_name(),
26            self.workspace_path(),
27            self.skip_git_check(),
28        );
29
30        // We create an owned String from the crate_name field
31        let crate_name_owned = self.crate_name().clone();
32
33        // Now we pass that owned string into our helper
34        run_with_workspace_and_crate_name(
35            self.workspace_path().clone(),
36            *self.skip_git_check(),
37            crate_name_owned, // <-- pass the owned String
38            |ws, new_crate_name| {
39                Box::pin(async move {
40                    info!("Now performing 'add new crate to workspace' for '{}'", new_crate_name);
41                    ws.add_new_crate_to_workspace(new_crate_name).await?;
42                    debug!("Successfully added crate='{}' via subcommand logic", new_crate_name);
43                    Ok(())
44                })
45            },
46        ).await?;
47
48        Ok(())
49    }
50}