

def func(self):
    'Implement the @tag functionality'
    if (not self.args):
        self.caller.msg('Usage: @tag[/switches] <obj> [= <tag>[:<category>]]')
        return
    if ('search' in self.switches):
        tag = self.args
        category = None
        if (':' in tag):
            (tag, category) = [part.strip() for part in tag.split(':', 1)]
        objs = search.search_tag(tag, category=category)
        nobjs = len(objs)
        if (nobjs > 0):
            catstr = ((" (category: '{w%s{n')" % category) if category else ('' if (nobjs == 1) else ' (may have different tag categories)'))
            matchstr = ', '.join((o.get_display_name(self.caller) for o in objs))
            string = ("Found {w%i{n object%s with tag '{w%s{n'%s:\n %s" % (nobjs, ('s' if (nobjs > 1) else ''), tag, catstr, matchstr))
        else:
            string = ("No objects found with tag '%s%s'." % (tag, ((' (category: %s)' % category) if category else '')))
        self.caller.msg(string)
        return
    if ('del' in self.switches):
        obj = self.caller.search(self.lhs, global_search=True)
        if (not obj):
            return
        if self.rhs:
            tag = self.rhs
            category = None
            if (':' in tag):
                (tag, category) = [part.strip() for part in tag.split(':', 1)]
            obj.tags.remove(tag, category=category)
            string = ("Removed tag '%s'%s from %s (if it existed)" % (tag, ((' (category: %s)' % category) if category else ''), obj))
        else:
            obj.tags.clear()
            string = ('Cleared all tags from from %s.' % obj)
        self.caller.msg(string)
        return
    if self.rhs:
        obj = self.caller.search(self.lhs, global_search=True)
        if (not i):
            return
        tag = self.rhs
        category = None
        if (':' in tag):
            (tag, category) = [part.strip() for part in tag.split(':', 1)]
        obj.tags.add(tag, category=category)
        string = ("Added tag '%s'%s to %s." % (tag, ((' (category: %s)' % category) if category else ''), obj))
        self.caller.msg(string)
    else:
        obj = self.caller.search(self.args, global_search=True)
        if (not obj):
            return
        tagtuples = obj.tags.all(return_key_and_category=True)
        ntags = len(tagtuples)
        tags = [tup[0] for tup in tagtuples]
        categories = [((' (category: %s)' % tup[1]) if tup[1] else '') for tup in tagtuples]
        if ntags:
            string = ('Tag%s on %s: %s' % (('s' if (ntags > 1) else ''), obj, ', '.join((("'%s'%s" % (tags[i], categories[i])) for i in range(ntags)))))
        else:
            string = ('No tags attached to %s.' % obj)
        self.caller.msg(string)

dataset/ETHPy150Open evennia/evennia/evennia/commands/default/building.py CmdTag.func/VarMisuse@422/611 `obj`->`i`