Skip to content

Commit

Permalink
Handle invocation with no available verbs or env vars
Browse files Browse the repository at this point in the history
It might be useful when measuring performance to invoke colcon with an
entire class of extensions blocked. This change "handles" the case where
no verbs are available and minimizes the output when there are no verbs
or environment variables available.
  • Loading branch information
cottsay committed Feb 22, 2024
1 parent ee44262 commit d7e471f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions colcon_core/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,16 @@ def _parse_optional(self, arg_string):
return None
return result

epilog = get_environment_variables_epilog(environment_variables_group_name)
if epilog:
epilog += '\n\n'
epilog += READTHEDOCS_MESSAGE

# top level parser
parser = CustomArgumentParser(
prog=get_prog_name(),
formatter_class=CustomFormatter,
epilog=(
get_environment_variables_epilog(
environment_variables_group_name
) + '\n\n' + READTHEDOCS_MESSAGE))
epilog=epilog)

# enable introspecting and intercepting all command line arguments
parser = decorate_argument_parser(parser)
Expand Down Expand Up @@ -287,6 +289,8 @@ def get_environment_variables_epilog(group_name):
"""
# list environment variables with descriptions
entry_points = load_extension_points(group_name)
if not entry_points:
return ''

Check warning on line 293 in colcon_core/command.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/command.py#L293

Added line #L293 was not covered by tests
env_vars = {
env_var.name: env_var.description for env_var in entry_points.values()}
epilog_lines = []
Expand Down Expand Up @@ -376,7 +380,6 @@ def create_subparser(parser, cmd_name, verb_extensions, *, attribute):
:returns: The special action object
"""
global colcon_logger
assert verb_extensions, 'No verb extensions'

# list of available verbs with their descriptions
verbs = []
Expand All @@ -387,9 +390,9 @@ def create_subparser(parser, cmd_name, verb_extensions, *, attribute):
# add subparser with description of verb extensions
subparser = parser.add_subparsers(
title=f'{cmd_name} verbs',
description='\n'.join(verbs),
description='\n'.join(verbs) or None,
dest=attribute,
help=f'call `{cmd_name} VERB -h` for specific help',
help=f'call `{cmd_name} VERB -h` for specific help' if verbs else None,
)
return subparser

Expand Down

0 comments on commit d7e471f

Please sign in to comment.