Skip to content

Commit 53dfc4f

Browse files
committed
Add build and test subcommands
1 parent 3e218d1 commit 53dfc4f

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/main.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,22 @@ impl ClippyCmd {
6767

6868
for arg in old_args.by_ref() {
6969
match arg.as_str() {
70+
"build" => {
71+
cargo_subcommand = "build";
72+
continue;
73+
},
74+
"test" => {
75+
cargo_subcommand = "test";
76+
continue;
77+
},
7078
"--fix" => {
79+
if cargo_subcommand != "check" {
80+
eprintln!(
81+
"Running `cargo clippy {}` is not available with the --fix flag",
82+
cargo_subcommand
83+
);
84+
process::exit(1) // Same code as `--explain` encountering an unknown lint
85+
}
7186
cargo_subcommand = "fix";
7287
continue;
7388
},
@@ -154,15 +169,17 @@ pub fn help_message() -> &'static str {
154169
155170
<green,bold>Usage</>:
156171
<cyan,bold>cargo clippy</> <cyan>[OPTIONS] [--] [<<ARGS>>...]</>
172+
<cyan,bold>cargo clippy test</> <cyan>[OPTIONS] [--] [<<ARGS>>...]</> for running `test` with Clippy as add-on
173+
<cyan,bold>cargo clippy build</> <cyan>[OPTIONS] [--] [<<ARGS>>...]</> for running `build` with Clippy as add-on
157174
158175
<green,bold>Common options:</>
159176
<cyan,bold>--no-deps</> Run Clippy only on the given crate, without linting the dependencies
160-
<cyan,bold>--fix</> Automatically apply lint suggestions. This flag implies <cyan>--no-deps</> and <cyan>--all-targets</>
177+
<cyan,bold>--fix</> Automatically apply lint suggestions. This flag implies <cyan>--no-deps</> and <cyan>--all-targets</> (not available on test/build)
161178
<cyan,bold>-h</>, <cyan,bold>--help</> Print this message
162179
<cyan,bold>-V</>, <cyan,bold>--version</> Print version info and exit
163180
<cyan,bold>--explain [LINT]</> Print the documentation for a given lint
164181
165-
See all options with <cyan,bold>cargo check --help</>.
182+
See all options with <cyan,bold>cargo check --help</> or <cyan,bold>cargo build/test --help</> for the build or test subcommands
166183
167184
<green,bold>Allowing / Denying lints</>
168185
@@ -213,9 +230,17 @@ mod tests {
213230
}
214231

215232
#[test]
216-
fn check() {
233+
fn cargo_subcommand() {
217234
let args = "cargo clippy".split_whitespace().map(ToString::to_string);
218235
let cmd = ClippyCmd::new(args);
219236
assert_eq!("check", cmd.cargo_subcommand);
237+
238+
let args = "cargo clippy build".split_whitespace().map(ToString::to_string);
239+
let cmd = ClippyCmd::new(args);
240+
assert_eq!("build", cmd.cargo_subcommand);
241+
242+
let args = "cargo clippy test".split_whitespace().map(ToString::to_string);
243+
let cmd = ClippyCmd::new(args);
244+
assert_eq!("test", cmd.cargo_subcommand);
220245
}
221246
}

0 commit comments

Comments
 (0)