Fixed several special cases of handling multiple same-named commands gracefully. Should resolve issue94.
This commit is contained in:
parent
03cc4970d0
commit
900f6da80f
9 changed files with 204 additions and 79 deletions
|
|
@ -711,11 +711,24 @@ class CmdOpen(ObjManipCommand):
|
|||
"""
|
||||
caller = self.caller
|
||||
string = ""
|
||||
# check if this exit object already exists here
|
||||
exit_obj = [obj for obj in location.contents
|
||||
if (obj.key.lower() == exit_name.lower() and obj.db._destination)]
|
||||
if exit_obj:
|
||||
exit_obj = exit_obj[0]
|
||||
# check if this exit object already exists. We need to
|
||||
# know what the result is before we can decide what to do;
|
||||
# so we deactivate the automatic error handling. This
|
||||
# always returns a list.
|
||||
exit_obj = caller.search(exit_name, ignore_errors=True)
|
||||
if len(exit_obj) > 1:
|
||||
# give error message and return
|
||||
caller.search(exit_name)
|
||||
return
|
||||
exit_obj = exit_obj[0]
|
||||
if exit_obj:
|
||||
if not exit_obj.db._destination:
|
||||
# we are trying to link a non-exit
|
||||
string = "'%s' already exists and is not an exit!\nIf you want to convert it "
|
||||
string += "to an exit, you must assign it an attribute '_destination' first."
|
||||
caller.msg(string % exit_name)
|
||||
return None
|
||||
# we are re-linking an old exit.
|
||||
old_destination = exit_obj.db._destination
|
||||
if old_destination:
|
||||
string = "Exit %s already exists." % exit_name
|
||||
|
|
|
|||
|
|
@ -67,16 +67,62 @@ class SystemNoMatch(MuxCommand):
|
|||
#
|
||||
class SystemMultimatch(MuxCommand):
|
||||
"""
|
||||
Multiple command matches
|
||||
Multiple command matches.
|
||||
|
||||
The cmdhandler adds a special attribute 'matches' to this
|
||||
system command.
|
||||
|
||||
matches = [(candidate, cmd) , (candidate, cmd), ...],
|
||||
|
||||
where candidate is an instance of src.commands.cmdparser.CommandCandidate
|
||||
and cmd is an an instantiated Command object matching the candidate.
|
||||
"""
|
||||
key = CMD_MULTIMATCH
|
||||
|
||||
def format_multimatches(self, caller, matches):
|
||||
"""
|
||||
Format multiple command matches to a useful error.
|
||||
|
||||
This is copied directly from the default method in
|
||||
src.commands.cmdhandler.
|
||||
|
||||
"""
|
||||
string = "There where multiple matches:"
|
||||
for num, match in enumerate(matches):
|
||||
# each match is a tuple (candidate, cmd)
|
||||
candidate, cmd = match
|
||||
|
||||
is_channel = hasattr(cmd, "is_channel") and cmd.is_channel
|
||||
if is_channel:
|
||||
is_channel = " (channel)"
|
||||
else:
|
||||
is_channel = ""
|
||||
is_exit = hasattr(cmd, "is_exit") and cmd.is_exit
|
||||
if is_exit and cmd.destination:
|
||||
is_exit = " (exit to %s)" % cmd.destination
|
||||
else:
|
||||
is_exit = ""
|
||||
|
||||
id1 = ""
|
||||
id2 = ""
|
||||
if not (is_channel or is_exit) and (hasattr(cmd, 'obj') and cmd.obj != caller):
|
||||
# the command is defined on some other object
|
||||
id1 = "%s-" % cmd.obj.name
|
||||
id2 = " (%s-%s)" % (num + 1, candidate.cmdname)
|
||||
else:
|
||||
id1 = "%s-" % (num + 1)
|
||||
id2 = ""
|
||||
string += "\n %s%s%s%s%s" % (id1, candidate.cmdname, id2, is_channel, is_exit)
|
||||
return string
|
||||
|
||||
def func(self):
|
||||
"""
|
||||
argument to cmd is a comma-separated string of
|
||||
all the clashing matches.
|
||||
"""
|
||||
self.caller.msg("Multiple matches found:\n %s" % self.args)
|
||||
string = self.format_multimatches(self.caller, self.matches)
|
||||
self.caller.msg(string)
|
||||
|
||||
|
||||
class SystemNoPerm(MuxCommand):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue