1crate::ix!();
3
4#[derive(Debug, StructOpt)]
6pub enum LintSubcommand {
7 Crate {
8 #[structopt(long = "crate")]
9 crate_name: PathBuf,
10 },
11 Workspace {
12 #[structopt(long = "path")]
13 path: PathBuf,
14 },
15}
16
17impl LintSubcommand {
18 pub async fn run(&self) -> Result<(), WorkspaceError> {
19 trace!("Entering LintSubcommand::run with {:?}", self);
20
21 match self {
22 LintSubcommand::Crate { crate_name } => {
23 info!("Linting single crate at path='{}'", crate_name.display());
24
25 run_with_crate(crate_name.clone(), false, move |handle| {
27 Box::pin(async move {
28 let report = handle.run_linting().await.map_err(|lint_err| {
30 error!(
31 "Linting error for crate='{}': {:?}",
32 handle.name(),
33 lint_err
34 );
35 WorkspaceError::LintingError(lint_err)
36 })?;
37
38 info!(
39 "Lint successful for crate='{}': success={}",
40 handle.name(),
41 report.success()
42 );
43 println!("stdout:\n{}", report.stdout());
44 println!("stderr:\n{}", report.stderr());
45 Ok(())
46 })
47 })
48 .await
49 }
50
51 LintSubcommand::Workspace { path } => {
52 info!("Linting entire workspace at '{}'", path.display());
53
54 run_with_workspace(Some(path.clone()), false, move |ws| {
57 Box::pin(async move {
58 let report = ws.run_linting().await.map_err(|lint_err| {
59 error!("Workspace linting failed: {:?}", lint_err);
60 WorkspaceError::LintingError(lint_err)
61 })?;
62
63 info!(
64 "Workspace lint success?={}, stdout len={}, stderr len={}",
65 report.success(),
66 report.stdout().len(),
67 report.stderr().len()
68 );
69 println!("Lint STDOUT:\n{}", report.stdout());
70 println!("Lint STDERR:\n{}", report.stderr());
71
72 Ok(())
73 })
74 })
75 .await
76 }
77 }
78 }
79}