Merge pull request #3487 from InspectorCaracal/patch-moveobjcmd

Fix traceback in new NumberedTargetCommand
This commit is contained in:
Griatch 2024-04-05 22:41:21 +02:00 committed by GitHub
commit ccd6b365e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View file

@ -397,7 +397,7 @@ class NumberedTargetCommand(COMMAND_DEFAULT_CLASS):
"""
super().parse()
self.number = 0
if hasattr(self, "lhs"):
if getattr(self, "lhs", None):
# handle self.lhs but don't require it
count, *args = self.lhs.split(maxsplit=1)
# we only use the first word as a count if it's a number and

View file

@ -134,6 +134,17 @@ class TestGeneral(BaseEvenniaCommandTest):
self.obj2.location = self.char1
self.call(general.CmdGive(), "2 Obj = Char2", "You give two Objs")
def test_numbered_target_command(self):
class CmdTest(general.NumberedTargetCommand):
key = "test"
def func(self):
self.msg(f"Number: {self.number} Args: {self.args}")
self.call(CmdTest(), "", "Number: 0 Args: ")
self.call(CmdTest(), "obj", "Number: 0 Args: obj")
self.call(CmdTest(), "1 obj", "Number: 1 Args: obj")
def test_mux_command(self):
class CmdTest(MuxCommand):
key = "test"