From 2b691daf6fd5601181ba60651a388d915162415c Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 30 Nov 2019 14:56:31 +0100 Subject: [PATCH] src/cli.rs: add insert_help() method --- src/bin/completion.rs | 8 +++----- src/cli.rs | 5 +++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/bin/completion.rs b/src/bin/completion.rs index 62fb0e5e..15bd309b 100644 --- a/src/bin/completion.rs +++ b/src/bin/completion.rs @@ -32,7 +32,7 @@ fn command_map() -> CliCommandMap { let cmd_def = CliCommandMap::new() .insert("ls", CliCommand::new(&API_METHOD_TEST_COMMAND).into()) .insert("test", CliCommand::new(&API_METHOD_TEST_COMMAND).into()) - .insert("help", help_command_def().into()); + .insert_help(); cmd_def } @@ -53,12 +53,10 @@ fn main() -> Result<(), Error> { while let Ok(line) = rl.readline("# prompt: ") { let helper = rl.helper().unwrap(); - // readline already handles tabs, so here we only split on spaces + let args = shellword_split(&line)?; - let def = helper.cmd_def(); - - handle_command(def, "", args); + handle_command(helper.cmd_def(), "", args); } Ok(()) diff --git a/src/cli.rs b/src/cli.rs index 9a5ccd9b..d927d456 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -73,6 +73,11 @@ impl CliCommandMap { self } + pub fn insert_help(mut self) -> Self { + self.commands.insert(String::from("help"), help_command_def().into()); + self + } + fn find_command(&self, name: &str) -> Option<&CommandLineInterface> { if let Some(sub_cmd) = self.commands.get(name) {