From 00ba8b51086112754247da4d3b603f3f83b02bc5 Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 9 Mar 2023 07:02:28 +0800 Subject: refactor: extra spaces are allowed around repl command --- src/repl/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 69056ac..4825b93 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -84,10 +84,12 @@ impl Repl { } fn handle_line(&mut self, handler: Arc, line: String) -> Result { - if line.starts_with('.') { - let (cmd, args) = match line.split_once(' ') { - Some((head, tail)) => (head, Some(tail.trim())), - None => (line.as_str(), None), + let mut trimed_line = line.trim_start(); + if trimed_line.starts_with('.') { + trimed_line = trimed_line.trim_end(); + let (cmd, args) = match trimed_line.split_once(' ') { + Some((head, tail)) => (head, Some(tail)), + None => (trimed_line, None), }; match cmd { ".exit" => { -- cgit v1.2.3