In the sources of flask_script
you can see that the "too many arguments"
error is prevented when the executed Command
has the attribute capture_all_args
set to True
which isn't documented anywhere.
You can set that attribute on the class just before you run the manager
if __name__ == "__main__":
from flask.ext.script import Command
Command.capture_all_args = True
manager.run()
Like this additional arguments to the manager are always accepted.
The downside of this quick fix is that you cannot register options or arguments to the commands the normal way anymore.
If you still need that feature you could subclass the Manager
and override the command
decorator like this
class MyManager(Manager):
def command(self, capture_all=False):
def decorator(func):
command = Command(func)
command.capture_all_args = capture_all
self.add_command(func.__name__, command)
return func
return decorator
Then you can use the command
decorator like this
@manager.command(True) # capture all arguments
def use_all(*args):
print("args:", args[0])
@manager.command() # normal way of registering arguments
def normal(name):
print("name", name)
Note that for some reason flask_script
requires use_all
to accept a varargs but will store the list of arguments in args[0]
which is a bit strange. def use_all(args):
does not work and fails with TypeError "got multiple values for argument 'args'"