schala/schala-repl/src/repl/help.rs

39 lines
1.2 KiB
Rust

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 {
[] => return global_help(repl, &directives),
_ => {
writeln!(buf, "Command-specific help not available yet").unwrap();
}
};
Some(buf)
}
fn global_help(repl: &mut Repl, directives: &Vec<CommandTree>) -> InterpreterDirectiveOutput {
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)
}