Move where help is computed

This commit is contained in:
greg 2019-03-19 21:12:10 -07:00
parent 3a98096b61
commit 04253543e9
1 changed files with 19 additions and 18 deletions

View File

@ -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, "{}", "<not implemented>").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<ProgrammingLanguageInterface> {
//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"),