1. Dan Jacob
  2. Flask-Script
  3. Issues
Issue #4 on hold

Decorators for commands

Nicholas Riley
created an issue

Something like @manager.command("...") equivalent to manager.add_command("...", CommandClass()) would make sense (on Python 2.6+, of course) and be analogous to how Flask does URL routing.

Comments (4)

  1. Dan Jacob repo owner

    (Reply via dan...@gmail.com):

    I've been thinking the same thing. The only issue is how to pass the Flask app instance (or app factory) to command functions.

    For example:

    def create_app():

    1. return your Flask app

    @manager.command("createdb", create_app) def create_db(app):

    1. do something with app

    so should the function expect an app instance as first argument ?

  2. Dan Jacob repo owner

    I've added a command decorator to tip. Works like this:

    manager = Manager(app)
    def hello(app):
        print "hello"

    You can pass in a list of options, which then get passed as arguments to the function ("app" is always the first argument):

    manager = Manager(app)
    @manager.command(options=[Option('-n', '--name', dest='name')])
    def hello(app, name):
        print "hello", name
  3. Log in to comment