Updated for logging

This commit is contained in:
Dimitris Zlatanidis 2023-04-27 11:36:40 +03:00
parent 5ca4f8e6e8
commit 0daa4a9d87

View file

@ -342,6 +342,9 @@ class Argparse(Configs):
if opt not in options: if opt not in options:
invalid.append(opt) invalid.append(opt)
except (KeyError, IndexError): except (KeyError, IndexError):
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.invalid_options.__name__)
self.usage.help_short(1) self.usage.help_short(1)
# Prints error for invalid options. # Prints error for invalid options.
@ -383,6 +386,9 @@ class Argparse(Configs):
try: try:
self.directory: str = self.args[self.args.index(arg) + 1] self.directory: str = self.args[self.args.index(arg) + 1]
except IndexError: except IndexError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.split_options_from_args.__name__)
self.directory: Path = self.tmp_slpkg self.directory: Path = self.tmp_slpkg
else: else:
self.args.remove(self.directory) self.args.remove(self.directory)
@ -395,6 +401,9 @@ class Argparse(Configs):
try: try:
self.binary_repo: str = self.args[self.args.index(arg) + 1] self.binary_repo: str = self.args[self.args.index(arg) + 1]
except IndexError: except IndexError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.split_options_from_args.__name__)
self.binary_repo = '' self.binary_repo = ''
else: else:
self.args.remove(self.binary_repo) self.args.remove(self.binary_repo)
@ -769,6 +778,9 @@ class Argparse(Configs):
flags = self.commands[self.args[1]] flags = self.commands[self.args[1]]
Help(self.args[1], flags).view() Help(self.args[1], flags).view()
except KeyError: except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.help_for_commands.__name__)
self.usage.help_minimal(f"{self.prog_name}: invalid argument '{''.join(self.args[1])}'") self.usage.help_minimal(f"{self.prog_name}: invalid argument '{''.join(self.args[1])}'")
else: else:
self.usage.help_short(1) self.usage.help_short(1)