about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAspen Smith <root@gws.fyi>2024-05-27T20·21-0400
committerclbot <clbot@tvl.fyi>2024-06-01T09·04+0000
commit4a489d930cbe727c869b3074b45e1346bf28e64c (patch)
treec83e959fdbd4d35c230295453b64f674edb80557
parent55ec06b26b3919c30751c67b0c40c5840aa1ca38 (diff)
feat(tvix/repl): Add a help command r/8190
Add a command to display help for the REPL, which can be either :? or
:h.

Change-Id: Ifdfd8c31130ca5afcde05a4c4276b768eb54c06f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11737
Autosubmit: aspen <root@gws.fyi>
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
-rw-r--r--tvix/cli/src/repl.rs35
1 files changed, 29 insertions, 6 deletions
diff --git a/tvix/cli/src/repl.rs b/tvix/cli/src/repl.rs
index 50c1779b0b..a970aa1ba7 100644
--- a/tvix/cli/src/repl.rs
+++ b/tvix/cli/src/repl.rs
@@ -19,17 +19,36 @@ pub enum ReplCommand<'a> {
     Expr(&'a str),
     Explain(&'a str),
     Quit,
+    Help,
 }
 
 impl<'a> ReplCommand<'a> {
+    const HELP: &'static str = "
+Welcome to the Tvix REPL!
+
+The following commands are supported:
+
+  <expr>    Evaluate a Nix language expression and print the result, along with its inferred type
+  :d <expr> Evaluate a Nix language expression and print a detailed description of the result
+  :q        Exit the REPL
+  :?, :h    Display this help text
+";
+
     pub fn parse(input: &'a str) -> Self {
-        if let Some(without_prefix) = input.strip_prefix(":d ") {
-            Self::Explain(without_prefix)
-        } else if input.trim_end() == ":q" {
-            Self::Quit
-        } else {
-            Self::Expr(input)
+        if input.starts_with(':') {
+            if let Some(without_prefix) = input.strip_prefix(":d ") {
+                return Self::Explain(without_prefix);
+            }
+
+            let input = input.trim_end();
+            match input {
+                ":q" => return Self::Quit,
+                ":h" | ":?" => return Self::Help,
+                _ => {}
+            }
         }
+
+        Self::Expr(input)
     }
 }
 
@@ -91,6 +110,10 @@ impl Repl {
 
                     let res = match ReplCommand::parse(input) {
                         ReplCommand::Quit => break,
+                        ReplCommand::Help => {
+                            println!("{}", ReplCommand::HELP);
+                            Ok(false)
+                        }
                         ReplCommand::Expr(input) => interpret(
                             Rc::clone(&io_handle),
                             input,