From 0e69f6e505e027d632c99293d3f428c384acbeb4 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 16 Mar 2023 19:31:48 +0200 Subject: [PATCH] Updated for invalid options --- slpkg/main.py | 42 +++--------------------------------------- 1 file changed, 3 insertions(+), 39 deletions(-) diff --git a/slpkg/main.py b/slpkg/main.py index 69850110..9182cbf4 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -263,61 +263,25 @@ class Argparse(Configs): self.split_options() self.split_options_from_args() - self.invalid_options() self.move_options() + self.invalid_options() def invalid_options(self): """ Checks for invalid options. """ - commands: list = [] - options: list = [] invalid: list = [] - doubles: list = [] - cache: list = [] - error: int = 0 for arg in self.args: - if arg in self.options: - options.append(arg) - if arg[0] == '-' and arg in self.commands.keys(): - commands.append(arg) - elif arg in self.commands.keys() and arg != 'help': - commands.append(arg) - + if arg in self.commands.keys(): + pass elif arg[0] == '-' and arg not in self.options: invalid.append(arg) elif arg[0] == '--' and arg not in self.options: invalid.append(arg) - # Avoid to add same options, exp: -P, --parallel. - opt_list = list(zip(self.options[::2], self.options[1::2])) - for i, opt1 in enumerate(opt_list): - - # Reset cache by two items. - if (i % 2) == 0: - cache = [] - - for opt2 in options: - if opt2 in opt1: - cache.append(opt2) - if len(cache) == 2: - doubles = cache - - if doubles: - print(f"{self.prog_name}: you added the same \'{', '.join(doubles)}\' options.") - error: int = 1 - - # Avoid to combine two or more commands. - if len(commands) > 1: - print(f"{self.prog_name}: you can't combine \'{', '.join(commands)}\' commands.") - error: int = 1 - # Prints error for invalid options. if invalid: for opt in invalid: print(f"{self.prog_name}: invalid option '{opt}'") - error: int = 1 - - if error: self.usage.help_minimal() def split_options(self) -> None: