Implement standalone help command
This commit is contained in:
parent
7c313ae307
commit
20f33f45e1
2 changed files with 33 additions and 6 deletions
|
|
@ -274,3 +274,31 @@ register(
|
||||||
help="list combat skills",
|
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",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
"""Tests for the standalone help command."""
|
"""Tests for the standalone help command."""
|
||||||
|
|
||||||
import pytest
|
|
||||||
from unittest.mock import AsyncMock, MagicMock
|
from unittest.mock import AsyncMock, MagicMock
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from mudlib import commands
|
from mudlib import commands
|
||||||
|
|
||||||
# Import command modules to register their commands
|
# Import command modules to register their commands
|
||||||
|
|
@ -30,9 +31,7 @@ def mock_reader():
|
||||||
def player(mock_reader, mock_writer):
|
def player(mock_reader, mock_writer):
|
||||||
from mudlib.player import Player
|
from mudlib.player import Player
|
||||||
|
|
||||||
return Player(
|
return Player(name="TestPlayer", x=5, y=5, reader=mock_reader, writer=mock_writer)
|
||||||
name="TestPlayer", x=5, y=5, reader=mock_reader, writer=mock_writer
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|
@ -73,7 +72,7 @@ async def test_help_unknown_command_shows_error(player):
|
||||||
await commands.dispatch(player, "help nonexistent")
|
await commands.dispatch(player, "help nonexistent")
|
||||||
output = "".join([call[0][0] for call in player.writer.write.call_args_list])
|
output = "".join([call[0][0] for call in player.writer.write.call_args_list])
|
||||||
assert "nonexistent" in output.lower()
|
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
|
@pytest.mark.asyncio
|
||||||
|
|
@ -82,4 +81,4 @@ async def test_help_and_commands_both_exist():
|
||||||
assert "help" in commands._registry
|
assert "help" in commands._registry
|
||||||
assert "commands" in commands._registry
|
assert "commands" in commands._registry
|
||||||
# They should be different functions
|
# They should be different functions
|
||||||
assert commands._registry["help"].func != commands._registry["commands"].func
|
assert commands._registry["help"].handler != commands._registry["commands"].handler
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue