summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-04-16 03:15:14 +0200
committermo8it <mo8it@proton.me>2024-04-16 03:15:14 +0200
commitdf448c069cae593d5eec37aa5b07c8103ae0f9b9 (patch)
tree6e16d28a4533f1c2416be9474e929a5bd6c365c8 /src
parent25e7696565349014c5e2662ddba43dc20391e272 (diff)
Fix running dev commands
Diffstat (limited to 'src')
-rw-r--r--src/init.rs7
-rw-r--r--src/main.rs20
2 files changed, 15 insertions, 12 deletions
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...
_ _ _