Handle '@spawn/edit ' (no prototype key given) brings OLC menu. Handle '@spawn/edit testball' brings OLC menu. Handle '@spawn/edit NO_EXISTS' that returns error

This commit is contained in:
Henddher Pedroza 2018-10-20 20:11:41 -05:00
parent 414f72c3b0
commit 931290a7a0
2 changed files with 20 additions and 13 deletions

View file

@ -2913,7 +2913,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
prototype = None prototype = None
if self.lhs: if self.lhs:
key = self.lhs key = self.lhs
prototype = spawner.search_prototype(key=key, return_meta=True) prototype = protlib.search_prototype(key=key)
if len(prototype) > 1: if len(prototype) > 1:
caller.msg("More than one match for {}:\n{}".format( caller.msg("More than one match for {}:\n{}".format(
key, "\n".join(proto.get('prototype_key', '') for proto in prototype))) key, "\n".join(proto.get('prototype_key', '') for proto in prototype)))
@ -2921,6 +2921,10 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
elif prototype: elif prototype:
# one match # one match
prototype = prototype[0] prototype = prototype[0]
else:
# no match
caller.msg("No prototype '{}' was found.".format(key))
return
olc_menus.start_olc(caller, session=self.session, prototype=prototype) olc_menus.start_olc(caller, session=self.session, prototype=prototype)
return return

View file

@ -479,25 +479,28 @@ class TestBuilding(CommandTest):
self.call(building.CmdSpawn(), "/list", "Key ") self.call(building.CmdSpawn(), "/list", "Key ")
# @span/edit (missing prototype) # @span/edit (missing prototype)
# brings up olc menu
msg = self.call( msg = self.call(
building.CmdSpawn(), building.CmdSpawn(),
'/edit') '/edit')
# '@spawn: Extra switch "/edit" ignored.|Usage: @spawn <prototype-key> or {key: value, ...}\n (2 existing prototypes. Use /list to inspect)') assert msg.startswith('______________________________________________________________________________\n\n --- Prototype wizard --- \n\n')
assert 'Prototype wizard' in msg
# @spawn/edit with valid prototype # @spawn/edit with valid prototype
with self.assertRaises(AttributeError): self.call(
self.call( building.CmdSpawn(),
building.CmdSpawn(), '/edit testball')
'/edit BALL', # TODO: OLC menu comes up but it gives no
'@spawn: Extra switch "/edit" ignored.|Spawned Ball(#13).') # indication of testball prototype being
# edited ... Is this correct?
# On top of OCL being shown, msg is preceded
# by Room(#1)...
assert 'Prototype wizard' in msg
# @spawn/edit with invalid prototype # @spawn/edit with invalid prototype
with self.assertRaises(AttributeError): msg = self.call(
self.call( building.CmdSpawn(),
building.CmdSpawn(), '/edit NO_EXISTS',
'/edit NO_EXISTS', "No prototype 'NO_EXISTS' was found.")
'@spawn: Extra switch "/edit" ignored.|No prototype named \'NO_EXISTS\'.')
# @spawn/examine (missing prototype) # @spawn/examine (missing prototype)
self.call( self.call(