diff --git a/schala-repl/src/repl/directive_actions.rs b/schala-repl/src/repl/directive_actions.rs index 19054a1..bbfc0dd 100644 --- a/schala-repl/src/repl/directive_actions.rs +++ b/schala-repl/src/repl/directive_actions.rs @@ -1,4 +1,5 @@ use super::{Repl, InterpreterDirectiveOutput}; +use crate::repl::command_tree::CommandTree; use crate::language::{LangMetaRequest, LangMetaResponse, DebugAsk, DebugResponse}; use itertools::Itertools; use std::fmt::Write as FmtWrite; @@ -24,7 +25,7 @@ impl DirectiveAction { use DirectiveAction::*; match self { Null => None, - Help => Some(repl.print_help_message(arguments)), + Help => help(repl, arguments), QuitProgram => { repl.save_before_exit(); ::std::process::exit(0) @@ -122,3 +123,32 @@ 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/mod.rs b/schala-repl/src/repl/mod.rs index 9efeb83..f3eb809 100644 --- a/schala-repl/src/repl/mod.rs +++ b/schala-repl/src/repl/mod.rs @@ -1,4 +1,3 @@ -use std::fmt::Write as FmtWrite; use std::sync::Arc; use std::collections::HashSet; @@ -120,35 +119,6 @@ impl Repl { directives.perform(self, &arguments) } - fn print_help_message(&mut self, commands_passed_to_help: &[&str] ) -> String { - let mut buf = String::new(); - let directives = match self.get_directives() { - CommandTree::Top(children) => children, - _ => panic!("Top-level CommandTree not Top") - }; - - match commands_passed_to_help { - [] => { - 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 = self.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(); - } - }; - buf - } - fn get_cur_language_state(&mut self) -> &mut Box { //TODO this is obviously not complete &mut self.language_states[0]