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

passing all the cli arguments to the command #136

Open

Description

@asldevi

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?

Activity

  1. jlumpe commented on Jan 22, 2016

    @jlumpe

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions