From 6b501edf489851b45eeff1200602f9d490c7f8ea Mon Sep 17 00:00:00 2001 From: Adam McKellar Date: Sun, 19 May 2024 19:41:05 +0200 Subject: [PATCH] Refactor the callback method in the ConfigReadCommand class to simplify the code and improve readability. --- installation_instruction/__main__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/installation_instruction/__main__.py b/installation_instruction/__main__.py index d0b8cb4..094b790 100644 --- a/installation_instruction/__main__.py +++ b/installation_instruction/__main__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from sys import argv, exit +from sys import exit from os.path import isfile import click @@ -22,6 +22,10 @@ class ConfigReadCommand(click.MultiCommand): + """ + Custom click command class to read config file and show installation instructions with parameters. + """ + def __init__(self, *args, **kwargs): super().__init__( *args, @@ -40,12 +44,8 @@ def get_command(self, ctx, config_file: str) -> click.Command|None: def callback(**kwargs): inst = instruction.validate_and_render(kwargs) - if not inst[1]: - print(inst[0]) - exit(0) - else: - print(inst[0]) - exit(1) + print(inst[0]) + exit(0 if not inst[1] else 1) return click.Command( name=config_file,