feat: Add "!" command to `rustlings watch`

This commit is contained in:
Sebastian LaVine 2023-04-16 21:44:08 -04:00
parent 9fc336c7f7
commit a4a5691a7b
No known key found for this signature in database
GPG Key ID: 819C7D054C7C1465
1 changed files with 12 additions and 4 deletions

View File

@ -301,10 +301,18 @@ fn spawn_watch_shell(
println!(" hint - prints the current exercise's hint");
println!(" clear - clears the screen");
println!(" quit - quits watch mode");
println!(" !<cmd> - executes a command, like `!rustc --explain E0381`");
println!(" help - displays this help message");
println!();
println!("Watch mode automatically re-evaluates the current exercise");
println!("when you edit a file's contents.")
} else if let Some(cmd) = input.strip_prefix('!') {
let parts: Vec<&str> = cmd.split_whitespace().collect();
if parts.is_empty() {
println!("no command provided");
} else if let Err(e) = Command::new(parts[0]).args(&parts[1..]).status() {
println!("failed to execute command `{}`: {}", cmd, e);
}
} else {
println!("unknown command: {input}");
}