mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-05 11:02:14 +01:00
Fixed for options error
This commit is contained in:
parent
afc6833512
commit
410264bcf6
2 changed files with 21 additions and 1 deletions
|
@ -274,11 +274,15 @@ class Argparse(Configs):
|
||||||
Result: ['-i', '-y', '-j', '-R']
|
Result: ['-i', '-y', '-j', '-R']
|
||||||
"""
|
"""
|
||||||
invalid_options: list = []
|
invalid_options: list = []
|
||||||
|
commands: list = []
|
||||||
for args in self.args:
|
for args in self.args:
|
||||||
if args[0] == '-' and args[:2] != '--' and len(args) >= 3 and '=' not in args:
|
if args[0] == '-' and args[:2] != '--' and len(args) >= 3 and '=' not in args:
|
||||||
self.args.remove(args)
|
self.args.remove(args)
|
||||||
|
|
||||||
for opt in list(map(lambda item: f'-{item}', [arg for arg in list(args[1:])])):
|
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():
|
if opt in self.commands.keys():
|
||||||
self.args.insert(0, opt)
|
self.args.insert(0, opt)
|
||||||
continue
|
continue
|
||||||
|
@ -287,8 +291,14 @@ class Argparse(Configs):
|
||||||
|
|
||||||
self.args.append(opt)
|
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:
|
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:
|
def split_options_from_args(self) -> None:
|
||||||
""" Split options from arguments.
|
""" Split options from arguments.
|
||||||
|
|
|
@ -17,6 +17,16 @@ class Usage(Configs):
|
||||||
self.yellow: str = color['yellow']
|
self.yellow: str = color['yellow']
|
||||||
self.endc: str = color['endc']
|
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:
|
def help_short(self) -> NoReturn:
|
||||||
""" Prints the short menu. """
|
""" Prints the short menu. """
|
||||||
args = (
|
args = (
|
||||||
|
|
Loading…
Reference in a new issue