Fixed for options error

This commit is contained in:
Dimitris Zlatanidis 2023-03-16 11:10:58 +02:00
parent afc6833512
commit 410264bcf6
2 changed files with 21 additions and 1 deletions

View file

@ -274,11 +274,15 @@ class Argparse(Configs):
Result: ['-i', '-y', '-j', '-R']
"""
invalid_options: list = []
commands: list = []
for args in self.args:
if args[0] == '-' and args[:2] != '--' and len(args) >= 3 and '=' not in args:
self.args.remove(args)
for opt in list(map(lambda item: f'-{item}', [arg for arg in list(args[1:])])):
if opt in self.commands.keys():
commands.append(opt)
if opt in self.commands.keys():
self.args.insert(0, opt)
continue
@ -287,8 +291,14 @@ class Argparse(Configs):
self.args.append(opt)
if len(commands) > 1:
print(f"slpkg: You can't combine {', '.join(commands)} commands.")
self.usage.help_minimal()
if invalid_options:
self.usage.help_short()
for opt in invalid_options:
print(f"slpkg: invalid option '{opt}'")
self.usage.help_minimal()
def split_options_from_args(self) -> None:
""" Split options from arguments.

View file

@ -17,6 +17,16 @@ class Usage(Configs):
self.yellow: str = color['yellow']
self.endc: str = color['endc']
def help_minimal(self):
""" Prints the minimal help menu. """
args = (
f'\nUsage: {self.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] '
f'[FILELIST|PACKAGES...]\n'
f"\nTry '{self.prog_name} --help' for more options.\n")
print(args)
raise SystemExit(1)
def help_short(self) -> NoReturn:
""" Prints the short menu. """
args = (