<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _do_exit(self, cmd, args):
 """\ Exit shell. exit | C-D Exit to the parent shell. exit root | end Exit to the root shell. exit all Exit to the command line. """

        if cmd == 'end':
            if not args:
                return 'root'
            else:
                self.stderr.write(textwrap.dedent('''\
                        end: unrecognized arguments: {}
                        ''')).format(args)

        # Hereafter, cmd == 'exit'.
        if not args:
            return True
        if len(args) > 1:
            self.stderr.write(textwrap.dedent('''\
                    exit: too many arguments: {}
                    ''')).format(args)
        exit_directive = args[0]
        if exit_directive == 'root':
            return 'root'
        if exit_directive == 'all':
            return 'all'
        self.stderr.write(textwrap.dedent('''\
                exit: unrecognized arguments: {}
                ''')).format(args)