Skip to content
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

Handle invocation with no available verbs or env vars #620

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
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
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 ''
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
11 changes: 11 additions & 0 deletions test/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ def test_main():
assert rc == signal.SIGINT


def test_main_no_verbs_or_env():
with ExtensionPointContext():
with patch(
'colcon_core.command.load_extension_points',
return_value={},
):
with pytest.raises(SystemExit) as e:
main(argv=['--help'])
assert e.value.code == 0


def test_create_parser():
with ExtensionPointContext():
parser = create_parser('colcon_core.environment_variable')
Expand Down
Loading