From 207f73d607bb855cd49dddcabd7c1ce8a66cf259 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 4 Jun 2019 22:02:51 +0000 Subject: [PATCH] Moving help code around --- schala-repl/src/repl/directive_actions.rs | 29 +--------------- schala-repl/src/repl/help.rs | 42 +++++++++++++++++++++++ schala-repl/src/repl/mod.rs | 1 + 3 files changed, 44 insertions(+), 28 deletions(-) create mode 100644 schala-repl/src/repl/help.rs diff --git a/schala-repl/src/repl/directive_actions.rs b/schala-repl/src/repl/directive_actions.rs index bbfc0dd..87269a6 100644 --- a/schala-repl/src/repl/directive_actions.rs +++ b/schala-repl/src/repl/directive_actions.rs @@ -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) -} diff --git a/schala-repl/src/repl/help.rs b/schala-repl/src/repl/help.rs new file mode 100644 index 0000000..ec08741 --- /dev/null +++ b/schala-repl/src/repl/help.rs @@ -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) +} diff --git a/schala-repl/src/repl/mod.rs b/schala-repl/src/repl/mod.rs index f3eb809..1070d7a 100644 --- a/schala-repl/src/repl/mod.rs +++ b/schala-repl/src/repl/mod.rs @@ -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";