Help message

This commit is contained in:
greg 2019-03-16 11:34:52 -07:00
parent 712da62d35
commit d06cf90fce

View File

@ -138,6 +138,31 @@ impl Repl {
} }
} }
fn print_help_message(&mut self) -> 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();
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, "{}", "<not implemented>").unwrap();
buf
}
fn get_cur_language_state(&mut self) -> &mut Box<ProgrammingLanguageInterface> { fn get_cur_language_state(&mut self) -> &mut Box<ProgrammingLanguageInterface> {
//TODO this is obviously not complete //TODO this is obviously not complete
&mut self.language_states[0] &mut self.language_states[0]
@ -191,7 +216,9 @@ impl Repl {
repl.save_before_exit(); repl.save_before_exit();
::std::process::exit(0) ::std::process::exit(0)
})), })),
CommandTree::term("help", Some("Print this help message")), CommandTree::term_with_function("help", Some("Print this help message"), Box::new(|repl: &mut Repl, _cmds: Vec<&str>| {
Some(repl.print_help_message())
})),
CommandTree::nonterm("debug", 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"), Some("show or hide pass debug info for a given pass, or display the names of all passes, or turn timing on/off"),
vec![ vec![