diff --git a/src/init.rs b/src/init.rs index 3202017..7648202 100644 --- a/src/init.rs +++ b/src/init.rs @@ -59,6 +59,8 @@ pub fn init(exercise_infos: &[ExerciseInfo]) -> Result<()> { fs::write(".vscode/extensions.json", VS_CODE_EXTENSIONS_JSON) .context("Failed to create the file `rustlings/.vscode/extensions.json`")?; + println!("{POST_INIT_MSG}"); + Ok(()) } @@ -87,3 +89,8 @@ const RUSTLINGS_DIR_ALREADY_EXISTS_ERR: &str = You probably already initialized Rustlings. Run `cd rustlings` Then run `rustlings` again"; + +const POST_INIT_MSG: &str = "Done initialization! + +Run `cd rustlings` to go into the generated directory. +Then run `rustlings` to get started."; diff --git a/src/main.rs b/src/main.rs index 7d4d8a5..5188ee1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,10 +72,12 @@ fn main() -> Result<()> { bail!(FORMAT_VERSION_HIGHER_ERR); } - if matches!(args.command, Some(Subcommands::Init)) { - init::init(&info_file.exercises).context("Initialization failed")?; - println!("{POST_INIT_MSG}"); - return Ok(()); + match args.command { + Some(Subcommands::Init) => { + return init::init(&info_file.exercises).context("Initialization failed"); + } + Some(Subcommands::Dev(dev_command)) => return dev_command.run(), + _ => (), } if !Path::new("exercises").is_dir() { @@ -133,8 +135,6 @@ fn main() -> Result<()> { } } } - // `Init` is handled above. - Some(Subcommands::Init) => (), Some(Subcommands::Run { name }) => { if let Some(name) = name { app_state.set_current_exercise_by_name(&name)?; @@ -152,7 +152,8 @@ fn main() -> Result<()> { app_state.set_current_exercise_by_name(&name)?; println!("{}", app_state.current_exercise().hint); } - Some(Subcommands::Dev(dev_command)) => dev_command.run()?, + // Handled in an earlier match. + Some(Subcommands::Init | Subcommands::Dev(_)) => (), } Ok(()) @@ -167,11 +168,6 @@ const FORMAT_VERSION_HIGHER_ERR: &str = It is possible that you have an outdated version of Rustlings. Try to install the latest Rustlings version first."; -const POST_INIT_MSG: &str = "Done initialization! - -Run `cd rustlings` to go into the generated directory. -Then run `rustlings` to get started."; - const PRE_INIT_MSG: &str = r" Welcome to... _ _ _