Moving help code around

This commit is contained in:
greg 2019-06-04 22:02:51 +00:00
parent 8dc0ad2348
commit 207f73d607
3 changed files with 44 additions and 28 deletions

View File

@ -1,5 +1,6 @@
use super::{Repl, InterpreterDirectiveOutput};
use crate::repl::command_tree::CommandTree;
use crate::repl::help::help;
use crate::language::{LangMetaRequest, LangMetaResponse, DebugAsk, DebugResponse};
use itertools::Itertools;
use std::fmt::Write as FmtWrite;
@ -124,31 +125,3 @@ fn doc(repl: &mut Repl, arguments: &[&str]) -> InterpreterDirectiveOutput {
}).unwrap_or(Some(format!(":docs needs an argument")))
}
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 {
[] => {
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();
},
_ => {
writeln!(buf, "Command-specific help not available yet").unwrap();
}
};
Some(buf)
}

View File

@ -0,0 +1,42 @@
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),
_ => {
writeln!(buf, "Command-specific help not available yet").unwrap();
}
};
Some(buf)
}
fn global_help(repl: &mut Repl) -> InterpreterDirectiveOutput {
let mut buf = String::new();
let directives = match repl.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 = repl.get_cur_language_state();
writeln!(buf, "").unwrap();
writeln!(buf, "Language-specific help for {}", lang.get_language_name()).unwrap();
writeln!(buf, "-----------------------").unwrap();
Some(buf)
}

View File

@ -13,6 +13,7 @@ use repl_options::ReplOptions;
mod directive_actions;
mod directives;
use directives::directives_from_pass_names;
mod help;
const HISTORY_SAVE_FILE: &'static str = ".schala_history";
const OPTIONS_SAVE_FILE: &'static str = ".schala_repl";