diff options
| author | Sebastian LaVine <mail@smlavine.com> | 2023-04-16 21:44:08 -0400 |
|---|---|---|
| committer | Sebastian LaVine <mail@smlavine.com> | 2023-04-16 21:44:08 -0400 |
| commit | a4a5691a7b3fac8201cf2965d94267da12bae47f (patch) | |
| tree | 54de3dcbdd26a490175701009460b64baad1bfd6 /src | |
| parent | 9fc336c7f7a9644b51f37b0a2dcfe0640bca8d40 (diff) | |
feat: Add "!" command to `rustlings watch`
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index 704398e..793b826 100644 --- a/src/main.rs +++ b/src/main.rs @@ -298,13 +298,21 @@ fn spawn_watch_shell( println!("Bye!"); } else if input.eq("help") { println!("Commands available to you in watch mode:"); - println!(" hint - prints the current exercise's hint"); - println!(" clear - clears the screen"); - println!(" quit - quits watch mode"); - println!(" help - displays this help message"); + 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}"); } |
