Skip to content

Fixed subcommand help. #846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions lib/pavilion/commands/base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,23 @@ def _inventory_sub_commands(self):
def setup_arguments(self, sub_parser):
"""Add arguments for this command to the give argparse sub_parser."""

# Add the short help, or not. A quirk of argparse is that if 'help'
# is set, the subcommand is listed regardless of whether the
# help is None. If we don't want that, we have to init without 'help'.
kwargs = {
'aliases': self.aliases,
'description': self.description,
'add_help': not self.is_dummy,
}
if self.short_help is not None:
cmd_parser = sub_parser.add_parser(self.name,
aliases=self.aliases,
description=self.description,
help=self.short_help,
formatter_class=WrappedFormatter)
else:
cmd_parser = sub_parser.add_parser(self.name,
aliases=self.aliases,
description=self.description)
kwargs['help'] = self.short_help
kwargs['formatter_class'] = WrappedFormatter


# Save the argument parser, as it can come in handy.
self._parser = cmd_parser
self._parser = sub_parser.add_parser(self.name, **kwargs)

if self.is_dummy:
self._parser.add_argument('--help', '-h', action='store_true')

self._setup_arguments(cmd_parser)
self._setup_arguments(self._parser)

def _setup_arguments(self, parser):
"""Setup the commands arguments in the Pavilion argument parser. This
Expand Down