diff options
Diffstat (limited to 'tvix/cli/src')
-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 { |