flask-script icon indicating copy to clipboard operation
flask-script copied to clipboard

Early application access is broken

Open noirbizarre opened this issue 11 years ago • 4 comments

The commit 44c1c1a5eded61bd5ecb985c20e758f209bbe33f broke the early app access provided by #34

As a consequence, it's not possible anymore to dynamically add commands depending on an application setting.

noirbizarre avatar Feb 10 '14 12:02 noirbizarre

Here what I want to be able to write:

manager = Manager(create_app)

def register_commands(manager):
    manager.add_command('clean', Clean())
    manager.add_command('urls', ShowUrls())

    for module in manager.app.config['PLUGINS']:
        try:
            __import__('myapp.plugins.{0}.commands'.format(module))
        except:
            pass

if __name__ == '__main__':
    register_commands(manager)
    manager.run()

and in a plugin (ex: myapp.plugins.sample.commands):

from myapp.commands import manager

@manager.command
def do_something():
    '''Do smething'''
    pass

noirbizarre avatar Feb 10 '14 14:02 noirbizarre

Any news on this issue ?

Not being able to register commands late or to access config early is really blocking me right now :/

noirbizarre avatar Apr 02 '14 17:04 noirbizarre

That is still possible, you just need to go about it differently. From my own code:

class AppCommand(Command):
    """Runs app-specific commands"""
    capture_all_args = True
    add_help = False

    def __init__(self):
            super(AppCommand,self).__init__()
            self.add_option(Option("-h","--help", dest="help",action="store_true"))

    def __call__(self,app,args, help=False, **kwargs):
            mgr = Manager(app)
            app.init_manager(mgr) ## this adds a bunch of subcommands
            mgr.handle("manage.py app",args)

Handling new "top-level" commands incrementally would be a major redesign of flask-script's interpreter loop. Pull requests gladly accepted.

smurfix avatar Apr 28 '14 17:04 smurfix

Thanks, I will try your approach.

If I find the time and a good design, I will submit a pull-request !

noirbizarre avatar May 05 '14 14:05 noirbizarre