So you can do this as follows with a decorator that Flask provides:
from flask import Flask
app = Flask(__name__)
@app.cli.command()
def initdb():
"""Initialize the database."""
print 'Init the db'
Then on the command like call that function like so:
$ flask -a hello.py initdb
Flask uses the Click package to pass through command line args, so anything available there should be available from Flask as well.
app.cli
is an instance of click.Group
(docs here) meaning things like @click.option()
should translate over to be @app.cli.option()
pretty nicely.
If you wanted to actually pass an option it might look something like this:
@app.cli.command()
@app.cli.option('--test', help='test')
def takearg(test):
print test
And then call it as follows:
$ flask -a hello.py --test=teststring