Moving help code around
This commit is contained in:
parent
8dc0ad2348
commit
207f73d607
@ -1,5 +1,6 @@
|
|||||||
use super::{Repl, InterpreterDirectiveOutput};
|
use super::{Repl, InterpreterDirectiveOutput};
|
||||||
use crate::repl::command_tree::CommandTree;
|
use crate::repl::command_tree::CommandTree;
|
||||||
|
use crate::repl::help::help;
|
||||||
use crate::language::{LangMetaRequest, LangMetaResponse, DebugAsk, DebugResponse};
|
use crate::language::{LangMetaRequest, LangMetaResponse, DebugAsk, DebugResponse};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::fmt::Write as FmtWrite;
|
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")))
|
}).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)
|
|
||||||
}
|
|
||||||
|
42
schala-repl/src/repl/help.rs
Normal file
42
schala-repl/src/repl/help.rs
Normal 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)
|
||||||
|
}
|
@ -13,6 +13,7 @@ use repl_options::ReplOptions;
|
|||||||
mod directive_actions;
|
mod directive_actions;
|
||||||
mod directives;
|
mod directives;
|
||||||
use directives::directives_from_pass_names;
|
use directives::directives_from_pass_names;
|
||||||
|
mod help;
|
||||||
|
|
||||||
const HISTORY_SAVE_FILE: &'static str = ".schala_history";
|
const HISTORY_SAVE_FILE: &'static str = ".schala_history";
|
||||||
const OPTIONS_SAVE_FILE: &'static str = ".schala_repl";
|
const OPTIONS_SAVE_FILE: &'static str = ".schala_repl";
|
||||||
|
Loading…
Reference in New Issue
Block a user