From f52bcb899d72e2f69cb90e34032b9c622322f9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Tue, 16 Aug 2016 00:04:49 +0200 Subject: Basic CLI --- archivist/__main__.py | 3 +++ archivist/cli.py | 25 +++++++++++++++++++++++++ archivist/model.py | 5 +++++ 3 files changed, 33 insertions(+) create mode 100644 archivist/cli.py diff --git a/archivist/__main__.py b/archivist/__main__.py index e69de29..5a1e31f 100644 --- a/archivist/__main__.py +++ b/archivist/__main__.py @@ -0,0 +1,3 @@ +if __name__ == '__main__': + from .cli import cli + cli() diff --git a/archivist/cli.py b/archivist/cli.py new file mode 100644 index 0000000..95b19d3 --- /dev/null +++ b/archivist/cli.py @@ -0,0 +1,25 @@ +import click + +CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) + +@click.group(context_settings = CONTEXT_SETTINGS) +def cli(): + pass + +@cli.group() +def db(): + """Database Management""" + pass + +@db.command() +def init(): + """Initialize the database, if not done already.""" + from .model import create_all + create_all() + +@db.command() +@click.confirmation_option(prompt="Are you sure you want to drop the database?") +def drop(force): + """Completely drop all tables.""" + from .model import drop_all + drop_all() diff --git a/archivist/model.py b/archivist/model.py index ce360f3..69765f3 100644 --- a/archivist/model.py +++ b/archivist/model.py @@ -50,6 +50,11 @@ class Model(Base): def get(cls, *args, **kwargs): return cls.query.get(*args, **kwargs) +def create_all(): + Model.metadata.create_all(engine) + +def drop_all(): + Model.metadata.drop_all(engine) class Prefix(Model): prefix = Column(ty.Unicode, index = True, unique = True) -- cgit v1.2.3