master > master: code - argparsing repariert
This commit is contained in:
parent
f4b2ca6c90
commit
3941348420
23
code/main.py
23
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user