diff options
author | Aspen Smith <root@gws.fyi> | 2024-05-27T19·49-0400 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-06-01T09·04+0000 |
commit | 70c4b512c2ca53f7e592c20bd9e200ac6a0ce853 (patch) | |
tree | cafbf4addfce8e3a439ecef8dcb42e91ec724c19 /tvix | |
parent | 23589a1db34ce81db7ce5ca53e5ba0728a92c4e4 (diff) |
refactor(tvix/repl): Abstract out REPL command handling r/8188
Prepare for introducing additional REPL commands by splitting out the *parsing* of the repl commands, which returns a new ReplCommand type, from the actual *handling* of the commands. Change-Id: If81a53c1e2d90204d26ce3bb2ea9eebf7bb3fd51 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11734 Autosubmit: aspen <root@gws.fyi> Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix')
-rw-r--r-- | tvix/cli/src/repl.rs | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/tvix/cli/src/repl.rs b/tvix/cli/src/repl.rs index 8dde9d9bfdc0..7d29ae3d2c83 100644 --- a/tvix/cli/src/repl.rs +++ b/tvix/cli/src/repl.rs @@ -1,4 +1,5 @@ -use std::{path::PathBuf, rc::Rc}; +use std::path::PathBuf; +use std::rc::Rc; use rustyline::{error::ReadlineError, Editor}; use tvix_glue::tvix_store_io::TvixStoreIO; @@ -13,6 +14,22 @@ fn state_dir() -> Option<PathBuf> { path } +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ReplCommand<'a> { + Expr(&'a str), + Explain(&'a str), +} + +impl<'a> ReplCommand<'a> { + pub fn parse(input: &'a str) -> Self { + if let Some(without_prefix) = input.strip_prefix(":d ") { + Self::Explain(without_prefix) + } else { + Self::Expr(input) + } + } +} + #[derive(Debug)] pub struct Repl { /// In-progress multiline input, when the input so far doesn't parse as a complete expression @@ -69,24 +86,23 @@ impl Repl { &line }; - let res = if let Some(without_prefix) = input.strip_prefix(":d ") { - interpret( + let res = match ReplCommand::parse(input) { + ReplCommand::Expr(input) => interpret( Rc::clone(&io_handle), - without_prefix, + input, None, args, - true, + false, AllowIncomplete::Allow, - ) - } else { - interpret( + ), + ReplCommand::Explain(input) => interpret( Rc::clone(&io_handle), input, None, args, - false, + true, AllowIncomplete::Allow, - ) + ), }; match res { |