Help function work
This commit is contained in:
parent
bb39c59db2
commit
8dc0ad2348
@ -1,4 +1,5 @@
|
|||||||
use super::{Repl, InterpreterDirectiveOutput};
|
use super::{Repl, InterpreterDirectiveOutput};
|
||||||
|
use crate::repl::command_tree::CommandTree;
|
||||||
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;
|
||||||
@ -24,7 +25,7 @@ impl DirectiveAction {
|
|||||||
use DirectiveAction::*;
|
use DirectiveAction::*;
|
||||||
match self {
|
match self {
|
||||||
Null => None,
|
Null => None,
|
||||||
Help => Some(repl.print_help_message(arguments)),
|
Help => help(repl, arguments),
|
||||||
QuitProgram => {
|
QuitProgram => {
|
||||||
repl.save_before_exit();
|
repl.save_before_exit();
|
||||||
::std::process::exit(0)
|
::std::process::exit(0)
|
||||||
@ -122,3 +123,32 @@ 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)
|
||||||
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use std::fmt::Write as FmtWrite;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
@ -120,35 +119,6 @@ impl Repl {
|
|||||||
directives.perform(self, &arguments)
|
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<ProgrammingLanguageInterface> {
|
fn get_cur_language_state(&mut self) -> &mut Box<ProgrammingLanguageInterface> {
|
||||||
//TODO this is obviously not complete
|
//TODO this is obviously not complete
|
||||||
&mut self.language_states[0]
|
&mut self.language_states[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user