From 04253543e90a032b99c4160431745dbf9afdf93a Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 19 Mar 2019 21:12:10 -0700 Subject: [PATCH] Move where help is computed --- schala-repl/src/repl/mod.rs | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/schala-repl/src/repl/mod.rs b/schala-repl/src/repl/mod.rs index 38c1c3d..899c2b7 100644 --- a/schala-repl/src/repl/mod.rs +++ b/schala-repl/src/repl/mod.rs @@ -141,31 +141,35 @@ impl Repl { } } - fn print_help_message(&mut self) -> String { + fn print_help_message(&mut self, commands_passed_to_help: &[&str] ) -> String { let mut buf = String::new(); let directives = match self.get_directives() { CommandTree::Top(children) => children, _ => panic!("Top-level CommandTree not Top") }; - writeln!(buf, "MetaInterpreter options").unwrap(); - writeln!(buf, "-----------------------").unwrap(); + match commands_passed_to_help { + [] => { + writeln!(buf, "MetaInterpreter options").unwrap(); + writeln!(buf, "-----------------------").unwrap(); - for directive in directives { - let trailer = " "; - writeln!(buf, "{}{}- {}", directive.get_cmd(), trailer, directive.get_help()).unwrap(); - } + for directive in directives { + let trailer = " "; + writeln!(buf, "{}{}- {}", directive.get_cmd(), trailer, directive.get_help()).unwrap(); + } - let ref lang = self.get_cur_language_state(); - writeln!(buf, "").unwrap(); - writeln!(buf, "Language-specific help for {}", lang.get_language_name()).unwrap(); - writeln!(buf, "-----------------------").unwrap(); - //writeln!(buf, "{}", lang.custom_interpreter_directives_help()).unwrap(); - //writeln!(buf, "{}", "").unwrap(); + let ref lang = self.get_cur_language_state(); + writeln!(buf, "").unwrap(); + writeln!(buf, "Language-specific help for {}", lang.get_language_name()).unwrap(); + writeln!(buf, "-----------------------").unwrap(); + }, + _ => { + writeln!(buf, "Command-specific help not available yet").unwrap(); + } + }; buf } - fn get_cur_language_state(&mut self) -> &mut Box { //TODO this is obviously not complete &mut self.language_states[0] @@ -209,10 +213,7 @@ impl Repl { ::std::process::exit(0) })), CommandTree::term_with_function("help", Some("Print this help message"), Box::new(|repl: &mut Repl, cmds: &[&str]| { - Some(match cmds { - [] => repl.print_help_message(), - _ => format!("ARGS: {:?}", cmds) - }) + Some(repl.print_help_message(cmds)) })), CommandTree::nonterm("debug", Some("show or hide pass debug info for a given pass, or display the names of all passes, or turn timing on/off"),