diff --git a/schala-repl/src/repl/command_tree.rs b/schala-repl/src/repl/command_tree.rs index 4ba5167..dcf19ac 100644 --- a/schala-repl/src/repl/command_tree.rs +++ b/schala-repl/src/repl/command_tree.rs @@ -1,16 +1,18 @@ +use super::Repl; + +type BoxedCommandFunction = Box<(fn(&mut Repl, Vec) -> Option)>; #[derive(Clone)] pub enum CommandTree { Terminal { name: String, help_msg: Option, - function: Option Option)>>, + function: Option, }, NonTerminal { name: String, children: Vec, help_msg: Option, - function: Option Option)>>, }, Top(Vec), } @@ -20,12 +22,15 @@ impl CommandTree { CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), function: None } } + pub fn term_with_function(s: &str, help: Option<&str>, func: BoxedCommandFunction) -> CommandTree { + CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), function: Some(func) } + } + pub fn nonterm(s: &str, help: Option<&str>, children: Vec) -> CommandTree { CommandTree::NonTerminal { name: s.to_string(), help_msg: help.map(|x| x.to_string()), children, - function: None, } }