Implement standalone help command

This commit is contained in:
Jared Miller 2026-02-08 13:33:46 -05:00
parent 7c313ae307
commit 20f33f45e1
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 33 additions and 6 deletions

View file

@ -274,3 +274,31 @@ register(
help="list combat skills",
)
)
async def cmd_help(player: Player, args: str) -> None:
"""Show help for a command or skill.
Args:
player: The player executing the command
args: Command name to get help for
"""
args = args.strip()
if not args:
await player.send(
"type help <command> for details. see also: commands, skills\r\n"
)
return
await _show_command_detail(player, args)
# Register the help command
register(
CommandDefinition(
"help",
cmd_help,
aliases=[],
mode="*",
help="show help for a command",
)
)

View file

@ -1,8 +1,9 @@
"""Tests for the standalone help command."""
import pytest
from unittest.mock import AsyncMock, MagicMock
import pytest
from mudlib import commands
# Import command modules to register their commands
@ -30,9 +31,7 @@ def mock_reader():
def player(mock_reader, mock_writer):
from mudlib.player import Player
return Player(
name="TestPlayer", x=5, y=5, reader=mock_reader, writer=mock_writer
)
return Player(name="TestPlayer", x=5, y=5, reader=mock_reader, writer=mock_writer)
@pytest.mark.asyncio
@ -73,7 +72,7 @@ async def test_help_unknown_command_shows_error(player):
await commands.dispatch(player, "help nonexistent")
output = "".join([call[0][0] for call in player.writer.write.call_args_list])
assert "nonexistent" in output.lower()
assert ("unknown" in output.lower() or "not found" in output.lower())
assert "unknown" in output.lower() or "not found" in output.lower()
@pytest.mark.asyncio
@ -82,4 +81,4 @@ async def test_help_and_commands_both_exist():
assert "help" in commands._registry
assert "commands" in commands._registry
# They should be different functions
assert commands._registry["help"].func != commands._registry["commands"].func
assert commands._registry["help"].handler != commands._registry["commands"].handler