'Implements command'

def func(self):

    caller = self.caller
    if (not self.args):
        caller.msg(('Usage:    %s    <object>    [=    typeclass]' % self.cmdstring))
        return
    obj = caller.search(self.lhs)
    if (not obj):
        return
    if (not hasattr(obj, '__dbclass__')):
        string = ('%s    is    not    a    typed    object.' % obj.name)
        caller.msg(string)
        return
    new_typeclass = (self.rhs or obj.path)
    if ('show' in self.switches):
        string = ("%s's    current    typeclass    is    %s." % (obj.name, obj.__class__))
        caller.msg(string)
        return
    if (self.cmdstring == '@swap'):
        self.switches.append('force')
        self.switches.append('reset')
    elif (self.cmdstring == '@update'):
        self.switches.append('force')
        self.switches.append('update')
    if (not (obj.access(caller, 'control') or obj.access(caller, 'edit'))):
        caller.msg('You    are    not    allowed    to    do    that.')
        return
    if (not hasattr(obj, 'swap_typeclass')):
        caller.msg('This    object    cannot    have    a    type    at    all!')
        return
    is_same = obj.is_typeclass(new_typeclass, exact=True)
    if (is_same and (not ('force' in self.switches))):
        string = ("%s    already    has    the    typeclass    '%s'.    Use    /force    to    override." % (obj.name, new_typeclass))
    else:
        update = ('update' in self.switches)
        reset = ('reset' in self.switches)
        hooks = ('at_object_creation' if update else 'all')
        old_typeclass_path = obj.typeclass_path
        obj.swap_typeclass(new_typeclass, clean_attributes=reset, clean_cmdsets=reset, run_start_hooks=hooks)
        if is_same:
            string = ('%s    updated    its    existing    typeclass    (%s).\n' % (obj.name, obj.path))
        else:
            string = ('%s    changed    typeclass    from    %s    to    %s.\n' % (obj.name, old_typeclass_path, obj.typeclass_path))
        if update:
            string += 'Only    the    at_object_creation    hook    was    run    (update    mode).'
        else:
            string += 'All    object    creation    hooks    were    run.'
        if reset:
            string += '    All    old    attributes    where    deleted    before    the    swap.'
        else:
            string += '    Attributes    set    before    swap    were    not    removed.'
    caller.msg(string)
