Skip to content

Commit

Permalink
refactor cli entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
xoudini committed Oct 21, 2024
1 parent f8eb470 commit 3a25c30
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/postcar/__main__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
import asyncio
from postcar.__about__ import __version__
from postcar.cli import handlers, parser
import sys
from postcar.cli import main


args = parser.parse_args()


if args.version:
print(__version__)
exit(0)

if args.command is None:
parser.print_help()
exit(1)

if (handler := handlers.get(args.command)) is None:
print(f"handler for '{args.command}' not found")
exit(1)

asyncio.run(handler(args=args))
sys.exit(main())
20 changes: 20 additions & 0 deletions src/postcar/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import asyncio
import typing as t
from postcar.__about__ import __version__
from postcar.cli import migrate
from postcar.cli._parser import parser, subparsers

Expand All @@ -15,7 +17,25 @@
)


def main() -> t.Optional[int]:
args = parser.parse_args()

if args.version:
return print(__version__)

if args.command is None:
parser.print_help()
return 1

if (handler := handlers.get(args.command)) is None:
print(f"handler for '{args.command}' not found")
return 2

return asyncio.run(handler(args=args))


__all__ = (
"main",
"parser",
"handlers",
)

0 comments on commit 3a25c30

Please sign in to comment.