Add loc switch to CmdFind and docstring

This commit is contained in:
BlauFeuer 2018-02-15 17:25:01 -05:00 committed by GitHub
parent a9648cf2bb
commit f2e5e70d9b

View file

@ -2238,12 +2238,14 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
Usage: Usage:
@find[/switches] <name or dbref or *account> [= dbrefmin[-dbrefmax]] @find[/switches] <name or dbref or *account> [= dbrefmin[-dbrefmax]]
@locate - this is a shorthand for using the /loc switch.
Switches: Switches:
room - only look for rooms (location=None) room - only look for rooms (location=None)
exit - only look for exits (destination!=None) exit - only look for exits (destination!=None)
char - only look for characters (BASE_CHARACTER_TYPECLASS) char - only look for characters (BASE_CHARACTER_TYPECLASS)
exact- only exact matches are returned. exact- only exact matches are returned.
loc - display object location if exists and match has one result
Searches the database for an object of a particular name or exact #dbref. Searches the database for an object of a particular name or exact #dbref.
Use *accountname to search for an account. The switches allows for Use *accountname to search for an account. The switches allows for
@ -2266,6 +2268,9 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
caller.msg("Usage: @find <string> [= low [-high]]") caller.msg("Usage: @find <string> [= low [-high]]")
return return
if "locate" in self.cmdstring: # Use option /loc as a default for @locate command alias
switches.append('loc')
searchstring = self.lhs searchstring = self.lhs
low, high = 1, ObjectDB.objects.all().order_by("-id")[0].id low, high = 1, ObjectDB.objects.all().order_by("-id")[0].id
if self.rhs: if self.rhs:
@ -2315,8 +2320,8 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
else: else:
result = result[0] result = result[0]
string += "\n|g %s - %s|n" % (result.get_display_name(caller), result.path) string += "\n|g %s - %s|n" % (result.get_display_name(caller), result.path)
if "locate" in self.cmdstring and not is_account and result.location: if "loc" in self.switches and not is_account and result.location:
string += " Location: {}".format(result.location.get_display_name(caller)) string += " (|wlocation|n: |g{}|n)".format(result.location.get_display_name(caller))
else: else:
# Not an account/dbref search but a wider search; build a queryset. # Not an account/dbref search but a wider search; build a queryset.
# Searchs for key and aliases # Searchs for key and aliases
@ -2352,8 +2357,8 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
else: else:
string = "|wOne Match|n(#%i-#%i%s):" % (low, high, restrictions) string = "|wOne Match|n(#%i-#%i%s):" % (low, high, restrictions)
string += "\n |g%s - %s|n" % (results[0].get_display_name(caller), results[0].path) string += "\n |g%s - %s|n" % (results[0].get_display_name(caller), results[0].path)
if "locate" in self.cmdstring and nresults == 1 and results[0].location: if "loc" in self.switches and nresults == 1 and results[0].location:
string += " Location: {}".format(results[0].location.get_display_name(caller)) string += " (|wlocation|n: |g{}|n)".format(results[0].location.get_display_name(caller))
else: else:
string = "|wMatch|n(#%i-#%i%s):" % (low, high, restrictions) string = "|wMatch|n(#%i-#%i%s):" % (low, high, restrictions)
string += "\n |RNo matches found for '%s'|n" % searchstring string += "\n |RNo matches found for '%s'|n" % searchstring