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