From 3941348420056d8ddef4c3dba43a810ff3ba9fd4 Mon Sep 17 00:00:00 2001 From: raj_mathe Date: Sun, 24 Oct 2021 13:46:57 +0200 Subject: [PATCH] master > master: code - argparsing repariert --- code/main.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/code/main.py b/code/main.py index d1efbd6..55843f3 100644 --- a/code/main.py +++ b/code/main.py @@ -26,11 +26,11 @@ PATH_TO_CONFIG: str = 'code/config.yml'; # MAIN PROCESS # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def enter(quiet: bool, debug: bool, mode_all: Any, path: Any, **_): +def enter(quiet: bool, debug: bool, mode: str, path: Any, **_): SetQuietMode(quiet); SetDebugMode(debug); configpath = path if isinstance(path, str) else PATH_TO_CONFIG; - if mode_all is not None: + if mode == 'all': LoopThroughCases(path=configpath); else: parser.print_help(); @@ -77,14 +77,19 @@ if __name__ == '__main__': cli_args = sys.argv[1:]; parser = argparse.ArgumentParser( prog='code/main.py', - description=''' - \033[2;1mBeschreibung:\033[0m - \033[2mEin Programm, das verschiedene Algorithmen aus dem Kurs AlgoDat I testet.\033[0m - ''', + description=dedent(''' + \033[93;1mBeschreibung:\033[0m + \033[93;2mEin Programm, das verschiedene Algorithmen aus dem Kurs AlgoDat I testet.\033[0m + '''), + formatter_class=argparse.RawTextHelpFormatter, ); - parser.add_argument('all', nargs='?', help='Führt alle Testfälle in der config.yml Datei durch.'); + parser.add_argument('mode', nargs=1, choices=['all'], help='all = Führt alle Testfälle in der config.yml Datei durch.'); parser.add_argument('--path', nargs=1, type=str, help='Pfad zur alternativen Configdatei.'); parser.add_argument('--debug', action='store_true', help='Debugging Messages stummschalten.') parser.add_argument('-q', '--quiet', action='store_true', help='Alle console-messages bis auf Errors stummschalten.') - args = parser.parse_args(cli_args); - enter(quiet=args.quiet, debug=args.debug, mode_all=args.all, path=args.path); + try: + args = parser.parse_args(cli_args); + except: + parser.print_help(); + exit(1); + enter(quiet=args.quiet, debug=args.debug, mode=args.mode[0], path=args.path);