Last active
January 1, 2016 08:19
-
-
Save rshk/8117133 to your computer and use it in GitHub Desktop.
CliTools with Flask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% pse_admin --help | |
usage: cli-app [-h] {run,db_init} ... | |
positional arguments: | |
{run,db_init} sub-commands | |
run | |
db_init | |
optional arguments: | |
-h, --help show this help message and exit | |
% pse_admin run --help | |
usage: cli-app run [-h] [--debug] [--host HOST] [--port PORT] | |
optional arguments: | |
-h, --help show this help message and exit | |
--debug | |
--host HOST | |
--port PORT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from clitools import CliApp | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
return "Hello World!" | |
cli = CliApp() | |
@cli.command | |
def command_run(host='127.0.0.1', port=5000, debug=False): | |
app.run(host=host, port=port, debug=debug) | |
@cli.command | |
def db_init(): | |
from .models import db_connect, db_init | |
engine = db_connect(app.config['DATABASE_URL']) | |
db_init(engine) | |
print("Database initialized") | |
if __name__ == "__main__": | |
cli.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment