0

Lets say i have a command like:

class Command(object):
    help = 'roll over and die'

    def add_arguments(self, parser):
        parser.add_argument(
            '--foo',
            help='see command help',
            choices=['die','die_painfully'],
            required=True
        )
        parser.add_agument( ... )          x 9001

and now i want to have an almost identical class but i dont want the argument '--foo' to required anymore. Can u modify that parser somehow if i super the hole add_arguments in the inhering method or something?

1 Answer 1

1

You could use a class attribute:

class Command(object):
    help = 'roll over and die'
    foo_required = True

    def add_arguments(self, parser):
        parser.add_argument(
            '--foo',
            # ...
            required=self.foo_required
        )

and then in inheriting Command:

class Command(foo.bar.Command):
    foo_required = False

and you wouldn't have to override add_arguments.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.