From d6019e6f9a04a8db330515f405782afbdabaff95 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 23 Oct 2019 20:54:55 -0700 Subject: [PATCH] Improve REPL help message Show help strings for children of a directive --- schala-repl/src/repl/command_tree.rs | 4 ++-- schala-repl/src/repl/help.rs | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/schala-repl/src/repl/command_tree.rs b/schala-repl/src/repl/command_tree.rs index 30c612b..9c4ee89 100644 --- a/schala-repl/src/repl/command_tree.rs +++ b/schala-repl/src/repl/command_tree.rs @@ -49,8 +49,8 @@ impl CommandTree { } pub fn get_help(&self) -> &str { match self { - CommandTree::Terminal { help_msg, ..} => help_msg.as_ref().map(|s| s.as_str()).unwrap_or(""), - CommandTree::NonTerminal { help_msg, .. } => help_msg.as_ref().map(|s| s.as_str()).unwrap_or(""), + CommandTree::Terminal { help_msg, ..} => help_msg.as_ref().map(|s| s.as_str()).unwrap_or(""), + CommandTree::NonTerminal { help_msg, .. } => help_msg.as_ref().map(|s| s.as_str()).unwrap_or(""), CommandTree::Top(_) => "" } } diff --git a/schala-repl/src/repl/help.rs b/schala-repl/src/repl/help.rs index ebf8b29..0ac07a2 100644 --- a/schala-repl/src/repl/help.rs +++ b/schala-repl/src/repl/help.rs @@ -13,7 +13,12 @@ pub fn help(repl: &mut Repl, arguments: &[&str]) -> InterpreterDirectiveOutput { None => format!("Directive `{}` not found", commands.last().unwrap()), Some(dir) => { let mut buf = String::new(); - writeln!(buf, "`{}` - {}", dir.get_cmd(), dir.get_help()).unwrap(); + let cmd = dir.get_cmd(); + let children = dir.get_children(); + writeln!(buf, "`{}` - {}", cmd, dir.get_help()).unwrap(); + for sub in children.iter() { + writeln!(buf, "\t`{} {}` - {}", cmd, sub.get_cmd(), sub.get_help()).unwrap(); + } buf } })