diff --git a/def_main.py b/def_main.py index 4238c19..7198744 100644 --- a/def_main.py +++ b/def_main.py @@ -10,7 +10,9 @@ def def_main(f: Callable) -> Callable: MAINS.append((f, s.filename, s.lineno)) if f.__module__ == '__main__': - f(*sys.argv[1:]) + result = f(*sys.argv[1:]) + if result: + sys.exit(result) return f diff --git a/test_main.py b/test_main.py index d9e82c3..f94dccb 100644 --- a/test_main.py +++ b/test_main.py @@ -2,5 +2,17 @@ @def_main -def main(*argv): - print('test_main says hello!, to', *argv) +def main(message='you!', *rest): + print('test_main says hello!, to', message, *rest) + + +@def_main +def error(*argv): + print('error!') + return 1 + + +@def_main +def never_reached(*argv): + print('This is never reached') + return 0