72 lines
1.6 KiB
Python
72 lines
1.6 KiB
Python
import click
|
|
from flask.cli import FlaskGroup, with_appcontext
|
|
from flaschengeist.app import create_app
|
|
from flaschengeist.config import configure_logger
|
|
|
|
|
|
def get_version(ctx, param, value):
|
|
if not value or ctx.resilient_parsing:
|
|
return
|
|
|
|
import platform
|
|
from werkzeug import __version__ as werkzeug_version
|
|
from flask import __version__ as flask_version
|
|
from flaschengeist import __version__
|
|
|
|
click.echo(
|
|
f"Python {platform.python_version()}\n"
|
|
f"Flask {flask_version}\n"
|
|
f"Werkzeug {werkzeug_version}\n"
|
|
f"Flaschengeist {__version__}",
|
|
color=ctx.color,
|
|
)
|
|
ctx.exit()
|
|
|
|
|
|
@with_appcontext
|
|
def verbosity(ctx, param, value):
|
|
"""Toggle verbosity between WARNING <-> DEBUG"""
|
|
if not value or ctx.resilient_parsing:
|
|
return
|
|
configure_logger(cli=30 - max(0, min(value * 10, 20)))
|
|
|
|
|
|
@click.group(
|
|
cls=FlaskGroup,
|
|
add_version_option=False,
|
|
add_default_commands=False,
|
|
create_app=lambda: create_app(cli=30),
|
|
)
|
|
@click.option(
|
|
"--version",
|
|
help="Show the flask version",
|
|
expose_value=False,
|
|
callback=get_version,
|
|
is_flag=True,
|
|
is_eager=True,
|
|
)
|
|
@click.option(
|
|
"--verbose",
|
|
"-v",
|
|
help="Increase logging level",
|
|
callback=verbosity,
|
|
count=True,
|
|
expose_value=False,
|
|
)
|
|
def cli():
|
|
"""Management script for the Flaschengeist application."""
|
|
pass
|
|
|
|
|
|
def main(*args, **kwargs):
|
|
from .plugin_cmd import plugin
|
|
from .export_cmd import export
|
|
from .docs_cmd import docs
|
|
from .run_cmd import run
|
|
|
|
cli.add_command(plugin)
|
|
cli.add_command(export)
|
|
cli.add_command(docs)
|
|
cli.add_command(run)
|
|
cli(*args, **kwargs)
|