Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

passing all the cli arguments to the command #136

Open
asldevi opened this issue May 4, 2015 · 1 comment
Open

passing all the cli arguments to the command #136

asldevi opened this issue May 4, 2015 · 1 comment

Comments

@asldevi
Copy link

asldevi commented May 4, 2015

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?

@jlumpe
Copy link

jlumpe commented Jan 22, 2016

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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants