Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ mod tests {
);

assert_eq!(
updated_cargo_toml(&exercise_infos, "abc\nbin = [xxx]\n123", b"../").unwrap(),
updated_cargo_toml(
&exercise_infos,
"abc\n\
bin = [xxx]\n\
123",
b"../"
)
.unwrap(),
br#"abc
bin = [
{ name = "1", path = "../exercises/1.rs" },
Expand Down
17 changes: 12 additions & 5 deletions src/dev/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ fn check_info_file_exercises(info_file: &InfoFile) -> Result<HashSet<PathBuf>> {

if !file_buf.contains("fn main()") {
bail!(
"The `main` function is missing in the file `{path}`.\nCreate at least an empty `main` function to avoid language server errors"
"The `main` function is missing in the file `{path}`.\n\
Create at least an empty `main` function to avoid language server errors"
);
}

if !file_buf.contains("// TODO") {
bail!(
"Didn't find any `// TODO` comment in the file `{path}`.\nYou need to have at least one such comment to guide the user."
"Didn't find any `// TODO` comment in the file `{path}`.\n\
You need to have at least one such comment to guide the user."
);
}

Expand Down Expand Up @@ -227,7 +229,10 @@ fn check_exercises_unsolved(

match result {
Ok(true) => {
bail!("The exercise {exercise_name} is already solved.\n{SKIP_CHECK_UNSOLVED_HINT}",)
bail!(
"The exercise {exercise_name} is already solved.\n\
{SKIP_CHECK_UNSOLVED_HINT}",
)
}
Ok(false) => (),
Err(e) => return Err(e),
Expand All @@ -242,10 +247,12 @@ fn check_exercises_unsolved(
fn check_exercises(info_file: &'static InfoFile, cmd_runner: &'static CmdRunner) -> Result<()> {
match info_file.format_version.cmp(&CURRENT_FORMAT_VERSION) {
Ordering::Less => bail!(
"`format_version` < {CURRENT_FORMAT_VERSION} (supported version)\nPlease migrate to the latest format version"
"`format_version` < {CURRENT_FORMAT_VERSION} (supported version)\n\
Please migrate to the latest format version"
),
Ordering::Greater => bail!(
"`format_version` > {CURRENT_FORMAT_VERSION} (supported version)\nTry updating the Rustlings program"
"`format_version` > {CURRENT_FORMAT_VERSION} (supported version)\n\
Try updating the Rustlings program"
),
Ordering::Equal => (),
}
Expand Down
38 changes: 29 additions & 9 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -58,11 +78,13 @@ pub fn init() -> Result<()> {
&& !workspace_manifest_content.contains("workspace.")
{
bail!(
"The current directory is already part of a Cargo project.\nPlease initialize Rustlings in a different directory"
"The current directory is already part of a Cargo project.\n\
Please initialize Rustlings in a different directory"
);
}

stdout.write_all(b"This command will create the directory `rustlings/` as a member of this Cargo workspace.\nPress ENTER to continue ")?;
stdout.write_all(b"This command will create the directory `rustlings/` as a member of this Cargo workspace.\n\
Press ENTER to continue ")?;
press_enter_prompt(&mut stdout)?;

// Make sure "rustlings" is added to `workspace.members` by making
Expand All @@ -78,7 +100,8 @@ pub fn init() -> Result<()> {
.status()?;
if !status.success() {
bail!(
"Failed to initialize a new Cargo workspace member.\nPlease initialize Rustlings in a different directory"
"Failed to initialize a new Cargo workspace member.\n\
Please initialize Rustlings in a different directory"
);
}

Expand All @@ -87,7 +110,8 @@ pub fn init() -> Result<()> {
.context("Failed to remove the temporary directory `rustlings/`")?;
init_git = false;
} else {
stdout.write_all(b"This command will create the directory `rustlings/` which will contain the exercises.\nPress ENTER to continue ")?;
stdout.write_all(b"This command will create the directory `rustlings/` which will contain the exercises.\n\
Press ENTER to continue ")?;
press_enter_prompt(&mut stdout)?;
}

Expand Down Expand Up @@ -166,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.
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ fn main() -> Result<ExitCode> {
clear_terminal(&mut stdout)?;

let welcome_message = welcome_message.trim_ascii();
write!(stdout, "{welcome_message}\n\nPress ENTER to continue ")?;
write!(
stdout,
"{welcome_message}\n\n\
Press ENTER to continue "
)?;
press_enter_prompt(&mut stdout)?;
clear_terminal(&mut stdout)?;
// Flush to be able to show errors occurring before printing a newline to stdout.
Expand Down
Loading