From decac4318e719276443a5619da96bce0661129c6 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 25 May 2017 18:38:00 -0400 Subject: [PATCH] pass the command name from HelpCommand When the help command instantiates another command class to get its help text, it needs to pass the command's name if the class supports it. Change-Id: I3507f723dc8b4e68db80d6da053be61026823457 Signed-off-by: Doug Hellmann --- cliff/help.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cliff/help.py b/cliff/help.py index 3974124f..40c48746 100644 --- a/cliff/help.py +++ b/cliff/help.py @@ -11,6 +11,7 @@ # under the License. import argparse +import inspect import sys import traceback @@ -38,7 +39,10 @@ class HelpAction(argparse.Action): traceback.print_exc(file=app.stdout) continue try: - cmd = factory(app, None) + kwargs = {} + if 'cmd_name' in inspect.getargspec(factory.__init__).args: + kwargs['cmd_name'] = name + cmd = factory(app, None, **kwargs) if cmd.deprecated: continue except Exception as err: @@ -83,7 +87,10 @@ class HelpCommand(command.Command): self.app.stdout.write(' %s\n' % fm) return self.app_args.cmd = search_args - cmd = cmd_factory(self.app, self.app_args) + kwargs = {} + if 'cmd_name' in inspect.getargspec(cmd_factory.__init__).args: + kwargs['cmd_name'] = cmd_name + cmd = cmd_factory(self.app, self.app_args, **kwargs) full_name = (cmd_name if self.app.interactive_mode else ' '.join([self.app.NAME, cmd_name])