From d4a6522d072c6c70aaf0d3341fd6a943b464b31a Mon Sep 17 00:00:00 2001 From: Adrien Burgun Date: Tue, 12 Jul 2022 20:29:22 +0200 Subject: [PATCH] :sparkles: stackline-cli: Exit command and condition --- stackline-cli/src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stackline-cli/src/main.rs b/stackline-cli/src/main.rs index 95963c6..5571620 100644 --- a/stackline-cli/src/main.rs +++ b/stackline-cli/src/main.rs @@ -34,12 +34,16 @@ fn main() { loop { let mut line = String::new(); - std::io::stdin().read_line(&mut line).unwrap(); + if let Ok(0) = std::io::stdin().read_line(&mut line) { + break; // EOF + } line = line.trim().to_string(); let mut tokens = line.split(' '); match tokens.next() { None => continue, + Some("exit") => break, + Some("run") => { if let Some(Ok(steps)) = tokens.next().map(|s| s.parse::()) { run(&mut world, steps).unwrap(); @@ -200,6 +204,7 @@ fn main() { } Some("help") => { + println!("- `exit`: exits"); println!("- `print`: prints the current world"); println!("- `get `: prints the JSON-serialized data of the tile at (x, y)"); println!("- `set `: sets the tile at (x, y) to a default tilename");