diff options
| author | sigoden <sigoden@gmail.com> | 2023-03-09 07:02:28 +0800 |
|---|---|---|
| committer | sigoden <sigoden@gmail.com> | 2023-03-09 07:02:28 +0800 |
| commit | 00ba8b51086112754247da4d3b603f3f83b02bc5 (patch) | |
| tree | 85a871c3a572087268ae15b1034e497786c9fcc3 /src/repl | |
| parent | ed905e3bd1b2497f29a8d1be671c30870104d76a (diff) | |
| download | aichat-00ba8b51086112754247da4d3b603f3f83b02bc5.tar.gz | |
refactor: extra spaces are allowed around repl command
Diffstat (limited to 'src/repl')
| -rw-r--r-- | src/repl/mod.rs | 10 |
1 files 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<ReplCmdHandler>, line: String) -> Result<bool> { - 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" => { |
