1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2024-11-08 09:09:17 +01:00

Fix running dev commands

This commit is contained in:
mo8it 2024-04-16 03:15:14 +02:00
parent 25e7696565
commit df448c069c
2 changed files with 15 additions and 12 deletions

@ -59,6 +59,8 @@ pub fn init(exercise_infos: &[ExerciseInfo]) -> Result<()> {
fs::write(".vscode/extensions.json", VS_CODE_EXTENSIONS_JSON) fs::write(".vscode/extensions.json", VS_CODE_EXTENSIONS_JSON)
.context("Failed to create the file `rustlings/.vscode/extensions.json`")?; .context("Failed to create the file `rustlings/.vscode/extensions.json`")?;
println!("{POST_INIT_MSG}");
Ok(()) Ok(())
} }
@ -87,3 +89,8 @@ const RUSTLINGS_DIR_ALREADY_EXISTS_ERR: &str =
You probably already initialized Rustlings. You probably already initialized Rustlings.
Run `cd rustlings` Run `cd rustlings`
Then run `rustlings` again"; 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.";

@ -72,10 +72,12 @@ fn main() -> Result<()> {
bail!(FORMAT_VERSION_HIGHER_ERR); bail!(FORMAT_VERSION_HIGHER_ERR);
} }
if matches!(args.command, Some(Subcommands::Init)) { match args.command {
init::init(&info_file.exercises).context("Initialization failed")?; Some(Subcommands::Init) => {
println!("{POST_INIT_MSG}"); return init::init(&info_file.exercises).context("Initialization failed");
return Ok(()); }
Some(Subcommands::Dev(dev_command)) => return dev_command.run(),
_ => (),
} }
if !Path::new("exercises").is_dir() { if !Path::new("exercises").is_dir() {
@ -133,8 +135,6 @@ fn main() -> Result<()> {
} }
} }
} }
// `Init` is handled above.
Some(Subcommands::Init) => (),
Some(Subcommands::Run { name }) => { Some(Subcommands::Run { name }) => {
if let Some(name) = name { if let Some(name) = name {
app_state.set_current_exercise_by_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)?; app_state.set_current_exercise_by_name(&name)?;
println!("{}", app_state.current_exercise().hint); 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(()) Ok(())
@ -167,11 +168,6 @@ const FORMAT_VERSION_HIGHER_ERR: &str =
It is possible that you have an outdated version of Rustlings. It is possible that you have an outdated version of Rustlings.
Try to install the latest Rustlings version first."; 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" const PRE_INIT_MSG: &str = r"
Welcome to... Welcome to...
_ _ _ _ _ _