Add a few features to allow for command auto detection #80

merged 3 commits into from Nov 6, 2013


None yet
2 participants

mehcode commented Nov 6, 2013

First off; great project here. I wanted to take it and use it for command auto-detection (eg. django and its INSTALLED_APPS). There were a couple of things missing to make that go cleanly.

  • Commands can no declare their own name via a class attribute
  • Commands can namespace themselves into automatic sub-managers
  • add_command can accept a command class in which case it just constructs it with no args
from flask.ext.script import Command
class Some(Command):
   name = 'some'
   namespace = 'something'
   def run(self):


Adding the above command will result in a sub manager something having the some command.

$ python something some

The end-result of all this is that the following works somewhat cleanly (to automatically add all commands from every module or package listed in the COMPONENTS key in app.config):

from flask.ext import components
for component in components.find('commands', app):
    for command in component.values():
        if (command and isinstance(command, type) and
                issubclass(command, (script.Command, script.Manager))):

If anyone is interested the above loop was implemented in alchemist:

techniq added a commit that referenced this pull request Nov 6, 2013

Merge pull request #80 from concordusapps/topics/instance
Add a few features to allow for command auto detection

@techniq techniq merged commit e7a48b0 into smurfix:master Nov 6, 2013

1 check passed

default The Travis CI build passed

techniq commented Nov 6, 2013

Looks great. Thanks. I'll try to tag a new release and push to PyPI in the next day or two.

@mehcode mehcode deleted the concordusapps:topics/instance branch Dec 16, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment