Skip to content

Commit b38fd03

Browse files
fix: filter other commands by name instead of type
Previously, a command like craft_appplication.command.TestCommand, which inherits from PackCommand, would omit the parent command in the "see also" section.
1 parent f4f339d commit b38fd03

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

craft_cli/helptexts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def get_command_help(
475475
else:
476476
raise RuntimeError("Internal inconsistency in commands groups")
477477
other_command_names = [
478-
c.name for c in command_group.commands if not isinstance(command, c)
478+
c.name for c in command_group.commands if c.name != command.name
479479
]
480480

481481
if output_format == OutputFormat.markdown:

tests/factory.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def create_command(
2525
hidden: bool = False,
2626
overview: str = "",
2727
class_name: str = "MyCommand",
28-
) -> type["BaseCommand"]:
28+
base_class: type[BaseCommand] = BaseCommand,
29+
) -> type[BaseCommand]:
2930
"""Helper to create commands."""
3031
attribs = {
3132
"name": name,
@@ -36,4 +37,4 @@ def create_command(
3637
"needs_config": False,
3738
"run": lambda parsed_args: None,
3839
}
39-
return type(class_name, (BaseCommand,), attribs)
40+
return type(class_name, (base_class,), attribs)

tests/unit/test_help.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,11 @@ def test_command_help_text_no_parameters(docs_url, output_format):
443443
Multiline!
444444
"""
445445
)
446-
cmd1 = create_command("somecommand", "Command one line help.", overview=overview)
447446
cmd2 = create_command("other-cmd-2", "Some help.")
447+
# Inherit from cmd2 to check that superclasses are treated as different commands.
448+
cmd1 = create_command(
449+
"somecommand", "Command one line help.", overview=overview, base_class=cmd2
450+
)
448451
cmd3 = create_command("other-cmd-3", "Some help.")
449452
cmd4 = create_command("other-cmd-4", "Some help.")
450453
command_groups = [

0 commit comments

Comments
 (0)