smurfix/flask-script

passing all the cli arguments to the command

asldevi opened this issue · 1 comments

I want to achieve the following

@manager.command
def hello(*args):
    print "hello", ', '.join(args)

and that throws manage.py: error: too many arguments

Now I go through code and understand that it has to do with capture_all_args (which is not documented anywhere) and make it

class HelloCommand(Command):
    def __init__(self):
        self.capture_all_args=True

    def run(self, *args, **kwargs):
        print "hello", ', '.join(*args)

which works fine.

Can this be added to documentation, please?

I had this problem as well. Since argparse is used behind the scenes, I expected Option(..., nargs=argparse.REMAINDER) to do the trick. It looks fine in python manage.py mycommand -? but I still get the manage.py: error: too many arguments as well. Good to know the capture_all_args attribute works as well, but it's still a bit annoying.

By the way, it seems to work as:

class HelloCommand(Command):
    capture_all_args = True

    def run(self, allargs):
        print 'Hello, the argument list was: ' + repr(allargs)