From d075f613f947b02c331469389e93fdb3747f3eea Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 2 Jul 2018 17:37:24 -0700 Subject: [PATCH] Hook help messages into command data structure --- schala-repl/src/lib.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/schala-repl/src/lib.rs b/schala-repl/src/lib.rs index cc61f0f..cca2333 100644 --- a/schala-repl/src/lib.rs +++ b/schala-repl/src/lib.rs @@ -289,7 +289,7 @@ impl Repl { loop { let language_name = self.languages[self.current_language_index].get_language_name(); - let directives = self.get_directives(&self.get_cur_language().get_passes()); + let directives = self.get_directives(); let tab_complete_handler = TabCompleteHandler::new(self.interpreter_directive_sigil, directives); self.line_reader.set_completer(std::sync::Arc::new(tab_complete_handler)); @@ -326,20 +326,22 @@ impl Repl { interpreter_output.to_repl() } - fn get_directives(&self, passes: &Vec) -> CommandTree { + fn get_directives(&self) -> CommandTree { + let ref passes = self.get_cur_language().get_passes(); CommandTree::Top(vec![ CommandTree::term("exit", Some("exit the REPL")), CommandTree::term("quit", Some("exit the REPL")), + CommandTree::term("help", Some("Print this help message")), CommandTree::NonTerminal(format!("debug"), vec![ CommandTree::term("passes", None), CommandTree::NonTerminal(format!("show"), passes.iter().map(|p| CommandTree::term(p, None)).collect(), None), CommandTree::NonTerminal(format!("hide"), passes.iter().map(|p| CommandTree::term(p, None)).collect(), None), - ], None), + ], Some(format!("show or hide pass info for a given pass, or display the names of all passes"))), CommandTree::NonTerminal(format!("lang"), vec![ CommandTree::term("next", None), CommandTree::term("prev", None), CommandTree::NonTerminal(format!("go"), vec![], None)//TODO - ], None), + ], Some(format!("switch between languages, or go directly to a langauge by name"))), ]) } @@ -396,9 +398,21 @@ impl Repl { "help" => { let mut buf = String::new(); let ref lang = self.languages[self.current_language_index]; + let directives = match self.get_directives() { + CommandTree::Top(children) => children, + _ => panic!("Top-level CommandTree not Top") + }; writeln!(buf, "MetaInterpreter options").unwrap(); writeln!(buf, "-----------------------").unwrap(); + + for directive in directives { + let trailer = " "; + writeln!(buf, "{}{}- {}", directive.get_cmd(), trailer, directive.get_help()).unwrap(); + } + + writeln!(buf, "").unwrap(); + /* writeln!(buf, "exit | quit - exit the REPL").unwrap(); writeln!(buf, "debug [show|hide] - show or hide debug info for a given pass").unwrap();