src/cli/command.rs - handle_command: return Result instead of exit()
This commit is contained in:
parent
2b691daf6f
commit
4b8573da65
|
@ -388,24 +388,22 @@ pub fn handle_command(
|
||||||
def: Arc<CommandLineInterface>,
|
def: Arc<CommandLineInterface>,
|
||||||
prefix: &str,
|
prefix: &str,
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
) {
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
set_help_context(Some(def.clone()));
|
set_help_context(Some(def.clone()));
|
||||||
|
|
||||||
match &*def {
|
let result = match &*def {
|
||||||
CommandLineInterface::Simple(ref cli_cmd) => {
|
CommandLineInterface::Simple(ref cli_cmd) => {
|
||||||
if let Err(_) = handle_simple_command(&def, &prefix, &cli_cmd, args) {
|
handle_simple_command(&def, &prefix, &cli_cmd, args)
|
||||||
std::process::exit(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
CommandLineInterface::Nested(ref map) => {
|
CommandLineInterface::Nested(ref map) => {
|
||||||
if let Err(_) = handle_nested_command(&def, &prefix, &map, args) {
|
handle_nested_command(&def, &prefix, &map, args)
|
||||||
std::process::exit(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
set_help_context(None);
|
set_help_context(None);
|
||||||
|
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_cli_command(def: CommandLineInterface) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue