techniq/flask-script — pull request #80 by mehcode (2013-11-06 17:23:48+00:00)
Title: Add a few features to allow for command auto detection

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

```python
from flask.ext.script import Command
class Some(Command):
name = 'some'
namespace = 'something'
def run(self):
print('Hello')

manager.add_command(Some)
```

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

```sh
$ python manage.py something some
Hello
```

The end-result of all this is that the following works somewhat cleanly:

```python
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))):
self.add_command(command)
```

If anyone is interested the above loop was implemented in alchemist: https://github.com/concordusapps/alchemist/blob/master/alchemist/management.py#L21-L26