Skip to content

Commit

Permalink
Return error codes correctly (see #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rec committed Jul 2, 2024
1 parent e9954ca commit 4190934
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion def_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 14 additions & 2 deletions test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4190934

Please sign in to comment.