Skip to content

Commit f248619

Browse files
committed
Check for Clippy on init
1 parent 1a633e2 commit f248619

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/init.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,27 @@ pub fn init() -> Result<()> {
3535
.stdin(Stdio::null())
3636
.stderr(Stdio::null())
3737
.output()
38-
.context(CARGO_LOCATE_PROJECT_ERR)?;
38+
.context(
39+
"Failed to run the command `cargo locate-project …`\n\
40+
Did you already install Rust?\n\
41+
Try running `cargo --version` to diagnose the problem.",
42+
)?;
43+
44+
if !Command::new("cargo")
45+
.arg("clippy")
46+
.arg("--version")
47+
.stdin(Stdio::null())
48+
.stdout(Stdio::null())
49+
.stderr(Stdio::null())
50+
.status()
51+
.context("Failed to run the command `cargo clippy --version`")?
52+
.success()
53+
{
54+
bail!(
55+
"Clippy, the official Rust linter, is missing.\n\
56+
Please install it first before initializing Rustlings."
57+
)
58+
}
3959

4060
let mut stdout = io::stdout().lock();
4161
let mut init_git = true;
@@ -170,10 +190,6 @@ pub fn init() -> Result<()> {
170190
Ok(())
171191
}
172192

173-
const CARGO_LOCATE_PROJECT_ERR: &str = "Failed to run the command `cargo locate-project …`
174-
Did you already install Rust?
175-
Try running `cargo --version` to diagnose the problem.";
176-
177193
const INIT_SOLUTION_FILE: &[u8] = b"fn main() {
178194
// DON'T EDIT THIS SOLUTION FILE!
179195
// It will be automatically filled after you finish the exercise.

0 commit comments

Comments
 (0)