Skip to content

Instantly share code, notes, and snippets.

@rshk
Last active January 1, 2016 08:19
Show Gist options
  • Save rshk/8117133 to your computer and use it in GitHub Desktop.
Save rshk/8117133 to your computer and use it in GitHub Desktop.
CliTools with Flask
% 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
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