GithubHelp home page GithubHelp logo

Decorators for commands about flask-script HOT 4 CLOSED

smurfix avatar smurfix commented on June 14, 2024
Decorators for commands

from flask-script.

Comments (4)

rduplain avatar rduplain commented on June 14, 2024

The "decorators" branch has support for command decorators. This will be merged for the 0.2 release. Will mark resolved on that release.


Original Comment By: Dan Jacob

from flask-script.

rduplain avatar rduplain commented on June 14, 2024

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

{{{
#!python

manager = Manager(app)

@manager.command()
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):

{{{
#!python

manager = Manager(app)

@manager.command(options=[Option('-n', '--name', dest='name')])
def hello(app, name):
print "hello", name
}}}


Original Comment By: Dan Jacob

from flask-script.

rduplain avatar rduplain commented on June 14, 2024

(Reply via [email protected]):

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():
# return your Flask app

@manager.command("createdb", create_app)
def create_db(app):
# do something with app

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


Original Comment By: Dan Jacob

from flask-script.

rduplain avatar rduplain commented on June 14, 2024

Original Comment By: Nicholas Riley

from flask-script.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.