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.
-
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 thetype
argument inparser.add_argument
I 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
type
callable requires there to be one argument, but if using a method,self
must be provided?Beta Was this translation helpful? Give feedback.
All reactions