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 <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2017-05-25 18:38:00 -04:00 committed by Rajath Agasthya
parent 790a26ed00
commit decac4318e
1 changed files with 9 additions and 2 deletions

View File

@ -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])