-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcli.py
52 lines (43 loc) · 1.61 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import code
import click
from .app import create_app
app = create_app(__name__)
@click.group()
def main():
"""Flask CMS"""
@main.command()
def shell():
"""Abre um shell >>> com o `app` no contexto
Se o ipython estiver instalado irá iniciar um shell Ipython
Caso contrário iniciará um shell Python puro.
"""
click.echo(f'Iniciando o shell do {app.config.SITENAME}')
with app.app_context():
try:
from IPython import start_ipython
start_ipython(argv=[], user_ns={'app': app})
except:
code.interact(banner=app.config.SITENAME, local={'app': app})
@main.command()
@click.option('--debug/--no-debug', default=app.config.DEBUG)
@click.option('--reloader/--no-reloader', default=app.config.RELOADER)
@click.option('--host', default=app.config.HOST)
@click.option('--port', default=app.config.PORT)
def runserver(debug, reloader, host, port):
"""Inicia o servidor em modo dev/debug"""
app.run(debug=debug, use_reloader=reloader, host=host, port=port,
extra_files=[f'{app.root_path}/settings.yml'])
@main.command()
@click.option('--username', prompt=True, required=True)
@click.option('--password', prompt=True, required=True, hide_input=True,
confirmation_prompt=True)
def adduser(username, password):
"""Cria um novo usuário"""
with app.app_context():
try:
app.db.create_user(username, password)
except Exception as e:
click.echo(f'Não foi possivel criar o usuário {username}')
raise
else:
click.echo(f"Usuário {username} criado com sucesso!")