summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2025-07-04 23:23:08 +0200
committermo8it <mo8it@proton.me>2025-07-04 23:35:13 +0200
commitf24861957a0c669060473a1fe7c6180eb43df9e2 (patch)
treed7f83a4a7bca912ef48d7b77339b6720fb498620 /src
parent1a633e275761604c8225839e79c139c90d59bfea (diff)
Check for Clippy on init
Diffstat (limited to 'src')
-rw-r--r--src/init.rs26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/init.rs b/src/init.rs
index 8cb6ac5..68011ed 100644
--- a/src/init.rs
+++ b/src/init.rs
@@ -35,7 +35,27 @@ pub fn init() -> Result<()> {
.stdin(Stdio::null())
.stderr(Stdio::null())
.output()
- .context(CARGO_LOCATE_PROJECT_ERR)?;
+ .context(
+ "Failed to run the command `cargo locate-project …`\n\
+ Did you already install Rust?\n\
+ Try running `cargo --version` to diagnose the problem.",
+ )?;
+
+ if !Command::new("cargo")
+ .arg("clippy")
+ .arg("--version")
+ .stdin(Stdio::null())
+ .stdout(Stdio::null())
+ .stderr(Stdio::null())
+ .status()
+ .context("Failed to run the command `cargo clippy --version`")?
+ .success()
+ {
+ bail!(
+ "Clippy, the official Rust linter, is missing.\n\
+ Please install it first before initializing Rustlings."
+ )
+ }
let mut stdout = io::stdout().lock();
let mut init_git = true;
@@ -170,10 +190,6 @@ pub fn init() -> Result<()> {
Ok(())
}
-const CARGO_LOCATE_PROJECT_ERR: &str = "Failed to run the command `cargo locate-project …`
-Did you already install Rust?
-Try running `cargo --version` to diagnose the problem.";
-
const INIT_SOLUTION_FILE: &[u8] = b"fn main() {
// DON'T EDIT THIS SOLUTION FILE!
// It will be automatically filled after you finish the exercise.