From 4b8573da65eec517391c8f2d2a83f7251b879fd8 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 30 Nov 2019 15:08:00 +0100 Subject: [PATCH] src/cli/command.rs - handle_command: return Result instead of exit() --- src/cli/command.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cli/command.rs b/src/cli/command.rs index cea760cc..4d57ccb2 100644 --- a/src/cli/command.rs +++ b/src/cli/command.rs @@ -388,24 +388,22 @@ pub fn handle_command( def: Arc, prefix: &str, args: Vec, -) { +) -> Result<(), Error> { set_help_context(Some(def.clone())); - match &*def { + let result = match &*def { CommandLineInterface::Simple(ref cli_cmd) => { - if let Err(_) = handle_simple_command(&def, &prefix, &cli_cmd, args) { - std::process::exit(-1); - } + handle_simple_command(&def, &prefix, &cli_cmd, args) } CommandLineInterface::Nested(ref map) => { - if let Err(_) = handle_nested_command(&def, &prefix, &map, args) { - std::process::exit(-1); - } + handle_nested_command(&def, &prefix, &map, args) } }; set_help_context(None); + + result } pub fn run_cli_command(def: CommandLineInterface) { @@ -443,5 +441,7 @@ pub fn run_cli_command(def: CommandLineInterface) { } } - handle_command(Arc::new(def), &prefix, args); + if let Err(_) = handle_command(Arc::new(def), &prefix, args) { + std::process::exit(-1); + } }