You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
In v2.5.0 if you override do_help() and don't use the @with_argparser decorator you get an error #1383
I have an app which uses cmd2 called tomcatmanager. This app creates and uses it's own argument parsers, and does not use the with_argparser decorator provided by cmd2. tomcatmanager does not use CommandSets. In 2.5.0, there is an undocumented breaking change which changes the way cmd2 finds and displays help messages. The result: cmd2 can not find or display any of the help messages from commands defined in my app.
I'll have to continue to dig, but it appears that the new code which creates and populates self._command_parsers behaves quite differently that the code in v2.4.3.
Initial research shows that self._command_parsers doesn't contain any of my command functions or argument parsers
@kmvanbrunt You have the most insight into the changes made in 2.5.0. Would you have any insight into what changed in terms of finding help text to display?
This is the error I get when testing tomcatmanager.
ifarg_parserisNone:
# This shouldn't be possible to reachraiseValueError(f'No argument parser found for {command_name}') # pragma: no cover
Since kotfu is overriding do_help() as a non-argparse decorated method, Cmd._register_command_parser() never creates a parser for cmd2'sdo_help(). Therefore, when kotfu calls super().do_help(), the decorator runs and finds no parser.
We need to make sure Cmd._register_command_parser() creates a parser for each of the base class do_xxx methods.
changed the title [-]v2.5.0 introduces an undocumented breaking change for custom arg parsers[/-][+]In v2.5.0 if you override `do_help()` and don't use the `@with_argparser` decorator you get an error[/+]on Nov 19, 2024
@kotfu You don't need to change anything. It's a bug in cmd2.
The same problem will occur if you override do_help(), decorate it using with_argparser, and supply a parser with different arguments than what super().do_help() is expecting. The moment you call super().do_help(), it will look up the parser by command name and get the parser for your do_help().
A major improvement to cmd2 2.5.0 is making parsers instance variables instead of class variables. The concept is backward compatible, but unfortunately the implementation needs a fix. The problem is the parser dictionary is keyed by command name. To handle overriding functions, it needs to be keyed by the function the parser belongs to.
Give us a few days and the fix will be in cmd2 2.5.7.
Activity
tleonhardt commentedon Nov 19, 2024
@kmvanbrunt You have the most insight into the changes made in 2.5.0. Would you have any insight into what changed in terms of finding help text to display?
kmvanbrunt commentedon Nov 19, 2024
This is the error I get when testing
tomcatmanager.Since kotfu is overriding
do_help()as a non-argparse decorated method,Cmd._register_command_parser()never creates a parser forcmd2'sdo_help(). Therefore, when kotfu callssuper().do_help(), the decorator runs and finds no parser.We need to make sure
Cmd._register_command_parser()creates a parser for each of the base classdo_xxxmethods.kotfu commentedon Nov 19, 2024
Other options I could consider include:
a) using the
@with_argparserdecorator on my overriddendo_help()methodb) completely reimiplementing
do_help(), ie don't ever callsuper().do_help()Also, with this new information, I'm rewriting the issue description....
[-]v2.5.0 introduces an undocumented breaking change for custom arg parsers[/-][+]In v2.5.0 if you override `do_help()` and don't use the `@with_argparser` decorator you get an error[/+]kmvanbrunt commentedon Nov 19, 2024
@kotfu You don't need to change anything. It's a bug in
cmd2.The same problem will occur if you override
do_help(), decorate it usingwith_argparser, and supply a parser with different arguments than whatsuper().do_help()is expecting. The moment you callsuper().do_help(), it will look up the parser by command name and get the parser for yourdo_help().A major improvement to
cmd2 2.5.0is making parsers instance variables instead of class variables. The concept is backward compatible, but unfortunately the implementation needs a fix. The problem is the parser dictionary is keyed by command name. To handle overriding functions, it needs to be keyed by the function the parser belongs to.Give us a few days and the fix will be in
cmd2 2.5.7.Sorry for breaking
tomcatmanager.kmvanbrunt commentedon Nov 23, 2024
@kotfu
cmd2 2.5.7is out.I tested it with
tomcatmanagerand the help commands worked.