From 24b41b555670ac0c8796d0c31a1b051a6073d2f7 Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman <4752801+elizabethengelman@users.noreply.github.com> Date: Mon, 4 Nov 2024 14:41:47 -0500 Subject: [PATCH] Add a comment to get_matches_from for --help --- cmd/soroban-cli/src/commands/contract/arg_parsing.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/cmd/soroban-cli/src/commands/contract/arg_parsing.rs b/cmd/soroban-cli/src/commands/contract/arg_parsing.rs index ab61df1c15..332ec36f59 100644 --- a/cmd/soroban-cli/src/commands/contract/arg_parsing.rs +++ b/cmd/soroban-cli/src/commands/contract/arg_parsing.rs @@ -63,15 +63,10 @@ pub fn build_host_function_parameters( cmd.build(); let long_help = cmd.render_long_help(); - match cmd.clone().try_get_matches_from(slop) { - Ok(m) => m, - Err(e) => { - println!("Failed to match subcommand: {}", e); - std::process::exit(1); - } - }; - + // get_matches_from exits if `help`, `--help` or `-h`are passed in the slop + // see clap documentation for more info: https://github.com/clap-rs/clap/blob/v4.1.8/src/builder/command.rs#L631 let mut matches_ = cmd.get_matches_from(slop); + let Some((function, matches_)) = &matches_.remove_subcommand() else { println!("{long_help}"); std::process::exit(1);