Updated for invalid options

This commit is contained in:
Dimitris Zlatanidis 2023-03-16 13:34:21 +02:00
parent 545c9ce076
commit 34d8e20726

View file

@ -271,6 +271,7 @@ class Argparse(Configs):
commands: list = []
options: list = []
invalid: list = []
error: int = 0
for arg in self.args:
if arg in self.options:
@ -287,18 +288,21 @@ class Argparse(Configs):
# Avoid to combine two or more options.
if len(options) != len(set(options)):
print(f"{self.prog_name}: you added the same {', '.join(options)} options.")
self.usage.help_minimal()
print(f"{self.prog_name}: you added the same \'{', '.join(options)}\' 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.")
self.usage.help_minimal()
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: