Replies: 3 comments
-
|
Since the parser is created before the
If you want Here is 1 option. class MyCommandSet(CommandSet):
def __init__(self) -> None:
super().__init__()
# Set the argument's type using the bounded method
MyCommandSet.saved_arg.type = self.custom_type
parser = Cmd2ArgumentParser("Example")
# Save this argument so we can edit it later in __init__()
saved_arg = parser.add_argument(..., choices_method=my_choices)
@with_argparser(parser)
def do_blah(self, args: argparse.Namespace):
... |
Beta Was this translation helpful? Give feedback.
-
|
Just to clarify, you've got |
Beta Was this translation helpful? Give feedback.
-
|
@ddejohn Yes, that is a typo. I've corrected the code now. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to run some type conversion on a few arguments inside a command set, but it needs access to
self. If I simply add the methods as thetypeargument inparser.add_argumentI always get an invalid value warning from the parser without that callable having even been called.I assume this is caused by the fact that the
typecallable requires there to be one argument, but if using a method,selfmust be provided?Beta Was this translation helpful? Give feedback.
All reactions