# This file is part of the Open Parts Database software # Copyright (C) 2022 Valentin Lorentz # # This program is free software: you can redistribute it and/or modify it under the # terms of the GNU Affero General Public License version 3, as published by the # Free Software Foundation. # # This program is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License along with # this program. If not, see . """ CLI entrypoint. """ import sys import typing def error(msg: str) -> typing.NoReturn: """Prints the message on stderr and exits with code 1.""" print(msg, file=sys.stderr) sys.exit(1) def main() -> None: """CLI entrypoint""" try: (executable, subcommand, *args) = sys.argv except ValueError: error(f"Syntax: {sys.argv[0]} [ [ [...]]]") if subcommand == "initdb": from opdb.db import Db # pylint: disable=import-outside-toplevel try: (dsn,) = args except ValueError: error(f"Syntax: {executable} initdb ") with Db.open(dsn) as db: db.init() else: error(f"Unknown subcommand: {subcommand}") if __name__ == "__main__": main()