From edd020e801ca95296f30a4670497752800828a9f Mon Sep 17 00:00:00 2001 From: Carl Oscar Aaro Date: Sun, 8 Oct 2017 23:25:27 +0200 Subject: [PATCH] Added logging args and help text --- tomodachi/cli/__init__.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tomodachi/cli/__init__.py b/tomodachi/cli/__init__.py index 04c04a42a..7f204b339 100644 --- a/tomodachi/cli/__init__.py +++ b/tomodachi/cli/__init__.py @@ -21,7 +21,8 @@ def help_command_usage(self) -> str: '\n' 'Available subcommands:\n' ' run [-c ] [--production]\n' - ' -c, --config use json configuration files\n' + ' -c, --config use json configuration files\n' + ' -l, --log specify log level\n' ' --production disable restart on file changes\n' ) @@ -48,7 +49,6 @@ def run_command_usage(self) -> str: return 'Usage: tomodachi.py run [-c ] [--production]' def run_command(self, args: List[str]) -> None: - if len(args) == 0: print(self.run_command_usage()) else: @@ -93,9 +93,10 @@ def run_command(self, args: List[str]) -> None: index = args.index('-l') if '-l' in args else args.index('--log') args.pop(index) if len(args) > index: - logging_level = logging.getLevelName(args.pop(index).upper()) - if isinstance(logging_level, int): - log_level = logging_level + try: + log_level = getattr(logging, args.pop(index).upper()) + except AttributeError: + pass logging.basicConfig(format='%(asctime)s (%(name)s): %(message)s', level=log_level) logging.Formatter(fmt='%(asctime)s.%(msecs).03d', datefmt='%Y-%m-%d %H:%M:%S') @@ -104,7 +105,7 @@ def run_command(self, args: List[str]) -> None: def main(self, argv: List[str]) -> None: try: - opts, args = getopt.getopt(argv, "hvV ", ['help', 'version', 'version', 'dependency-versions']) + opts, args = getopt.getopt(argv, "hlvV ", ['help', 'log', 'version', 'version', 'dependency-versions']) except getopt.GetoptError: self.help_command() for opt, arg in opts: