US01-02: Establish Application and Database Foundation (#47)
This commit was merged in pull request #47.
This commit is contained in:
35
photo_pipeline/__main__.py
Normal file
35
photo_pipeline/__main__.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""Application management CLI: ``python -m photo_pipeline {serve,migrate}``."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from typing import Sequence
|
||||
|
||||
from photo_pipeline.config import Config
|
||||
from photo_pipeline.db import run_migrations
|
||||
|
||||
|
||||
def main(argv: Sequence[str] | None = None) -> int:
|
||||
parser = argparse.ArgumentParser(prog="photo_pipeline")
|
||||
commands = parser.add_subparsers(dest="command", required=True)
|
||||
commands.add_parser("serve", help="Run the API server")
|
||||
commands.add_parser("migrate", help="Upgrade the database to the latest revision")
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
config = Config.from_env()
|
||||
config.database_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if args.command == "migrate":
|
||||
run_migrations(config.database_url)
|
||||
return 0
|
||||
|
||||
import uvicorn
|
||||
|
||||
from photo_pipeline.api.app import create_app
|
||||
|
||||
uvicorn.run(create_app(config), host=config.host, port=config.port)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user