From af91ddcda9c7a6b33cd8328eb455fc1624202c8c Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 15 Nov 2023 09:41:26 +0100 Subject: [PATCH] CLI: Do not execute a command if help is printed Previously, for example `hf 14a raw -b 7 -d 26 -h` was printing help but it was also executing the command. --- software/script/chameleon_cli_main.py | 2 ++ software/script/chameleon_utils.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/software/script/chameleon_cli_main.py b/software/script/chameleon_cli_main.py index c0d5d82..0699927 100755 --- a/software/script/chameleon_cli_main.py +++ b/software/script/chameleon_cli_main.py @@ -119,6 +119,8 @@ class ChameleonCLI: args.prog = tree_node.fullname try: args_parse_result = args.parse_args(arg_list) + if args.help_requested: + return except chameleon_utils.ArgsParserError as e: args.print_help() print(f'{CY}'+str(e).strip()+f'{C0}', end="\n\n") diff --git a/software/script/chameleon_utils.py b/software/script/chameleon_utils.py index f10c4a6..3ace362 100644 --- a/software/script/chameleon_utils.py +++ b/software/script/chameleon_utils.py @@ -43,6 +43,7 @@ class ArgumentParserNoExit(argparse.ArgumentParser): super().__init__(*args, **kwargs) self.add_help = False self.description = "Please enter correct parameters" + self.help_requested = False def exit(self, status: int = 0, message: Union[str, None] = None): if message: @@ -98,6 +99,8 @@ class ArgumentParserNoExit(argparse.ArgumentParser): if len(lines) > 0: lines[0] = f'{CG}{lines[0]}{C0}' print('\n'.join(lines)) + print('') + self.help_requested = True def expect_response(accepted_responses: Union[int, list[int]]) -> Callable[..., Any]: