From cdeb8ce2292d5968e3866fd96cc422756f5a0ff4 Mon Sep 17 00:00:00 2001 From: mo8it Date: Sat, 27 Apr 2024 17:31:51 +0200 Subject: Fix initialization --- src/main.rs | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index b03aa52..bb70a75 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,11 +5,10 @@ use crossterm::{ terminal::{Clear, ClearType}, ExecutableCommand, }; -use serde::Deserialize; use std::{ io::{self, BufRead, Write}, - path::{Path, PathBuf}, - process::{exit, Command, Stdio}, + path::Path, + process::exit, }; use self::{app_state::AppState, dev::DevCommands, info_file::InfoFile, watch::WatchExit}; @@ -77,11 +76,6 @@ enum Subcommands { Dev(DevCommands), } -#[derive(Deserialize)] -struct CargoMetadata { - target_directory: PathBuf, -} - fn in_official_repo() -> bool { Path::new("dev/rustlings-repo.txt").exists() } @@ -93,21 +87,6 @@ fn main() -> Result<()> { bail!("{OLD_METHOD_ERR}"); } - let metadata_output = Command::new("cargo") - .arg("metadata") - .arg("-q") - .arg("--format-version") - .arg("1") - .arg("--no-deps") - .stdin(Stdio::null()) - .stderr(Stdio::inherit()) - .output() - .context(CARGO_METADATA_ERR)? - .stdout; - let target_dir = serde_json::de::from_slice::(&metadata_output) - .context("Failed to read the field `target_directory` from the `cargo metadata` output")? - .target_directory; - match args.command { Some(Subcommands::Init) => { if DEBUG_PROFILE { @@ -142,8 +121,7 @@ fn main() -> Result<()> { let (mut app_state, state_file_status) = AppState::new( info_file.exercises, info_file.final_message.unwrap_or_default(), - target_dir, - ); + )?; if let Some(welcome_message) = info_file.welcome_message { match state_file_status { @@ -219,10 +197,6 @@ The new method doesn't include cloning the Rustlings' repository. Please follow the instructions in the README: https://github.com/rust-lang/rustlings#getting-started"; -const CARGO_METADATA_ERR: &str = "Failed to run the command `cargo metadata …` -Did you already install Rust? -Try running `cargo --version` to diagnose the problem."; - const FORMAT_VERSION_HIGHER_ERR: &str = "The format version specified in the `info.toml` file is higher than the last one supported. It is possible that you have an outdated version of Rustlings. -- cgit v1.2.3