Skip to content

Commit 0dc9c33

Browse files
authored
Merge pull request #1480 from smlavine/main
feat: Add "!" command to `rustlings watch`
2 parents 9fc336c + a4a5691 commit 0dc9c33

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,21 @@ fn spawn_watch_shell(
298298
println!("Bye!");
299299
} else if input.eq("help") {
300300
println!("Commands available to you in watch mode:");
301-
println!(" hint - prints the current exercise's hint");
302-
println!(" clear - clears the screen");
303-
println!(" quit - quits watch mode");
304-
println!(" help - displays this help message");
301+
println!(" hint - prints the current exercise's hint");
302+
println!(" clear - clears the screen");
303+
println!(" quit - quits watch mode");
304+
println!(" !<cmd> - executes a command, like `!rustc --explain E0381`");
305+
println!(" help - displays this help message");
305306
println!();
306307
println!("Watch mode automatically re-evaluates the current exercise");
307308
println!("when you edit a file's contents.")
309+
} else if let Some(cmd) = input.strip_prefix('!') {
310+
let parts: Vec<&str> = cmd.split_whitespace().collect();
311+
if parts.is_empty() {
312+
println!("no command provided");
313+
} else if let Err(e) = Command::new(parts[0]).args(&parts[1..]).status() {
314+
println!("failed to execute command `{}`: {}", cmd, e);
315+
}
308316
} else {
309317
println!("unknown command: {input}");
310318
}

0 commit comments

Comments
 (0)