2019-06-04 15:02:51 -07:00
|
|
|
use std::fmt::Write as FmtWrite;
|
|
|
|
|
|
|
|
use super::{Repl, InterpreterDirectiveOutput};
|
|
|
|
use crate::repl::command_tree::CommandTree;
|
|
|
|
|
|
|
|
pub fn help(repl: &mut Repl, arguments: &[&str]) -> InterpreterDirectiveOutput {
|
|
|
|
let mut buf = String::new();
|
|
|
|
let directives = match repl.get_directives() {
|
|
|
|
CommandTree::Top(children) => children,
|
|
|
|
_ => panic!("Top-level CommandTree not Top")
|
|
|
|
};
|
|
|
|
|
|
|
|
match arguments {
|
2019-06-05 02:54:13 -07:00
|
|
|
[] => return global_help(repl, &directives),
|
2019-06-04 15:02:51 -07:00
|
|
|
_ => {
|
|
|
|
writeln!(buf, "Command-specific help not available yet").unwrap();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Some(buf)
|
|
|
|
}
|
|
|
|
|
2019-06-05 02:54:13 -07:00
|
|
|
fn global_help(repl: &mut Repl, directives: &Vec<CommandTree>) -> InterpreterDirectiveOutput {
|
2019-06-04 15:02:51 -07:00
|
|
|
let mut buf = String::new();
|
|
|
|
|
|
|
|
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 = repl.get_cur_language_state();
|
|
|
|
writeln!(buf, "").unwrap();
|
|
|
|
writeln!(buf, "Language-specific help for {}", lang.get_language_name()).unwrap();
|
|
|
|
writeln!(buf, "-----------------------").unwrap();
|
|
|
|
Some(buf)
|
|
|
|
}
|