'help ?COMMAND?: Shows list of commands and their usage.  If COMMAND
is specified then shows detail about that COMMAND.  (\'.help all\' will
show detailed help about all commands.)'

def command_help(self, cmd):

    if (not self._help_info):
        self._help_info = {}
        for c in dir(self):
            if (not c.startswith('command_')):
                continue
            d = getattr(self, c).__doc__
            assert d, (c + '    command    must    have    documentation')
            c = c[len('command_'):]
            if (c in ('headers', 'color')):
                continue
            while (d[0] == '\n'):
                d = d[1:]
            parts = d.split('\n', 1)
            firstline = parts[0].strip().split(':', 1)
            assert (len(firstline) == 2), (c + '    command    must    have    usage:    description    doc')
            if ((len(parts) == 1) or (len(parts[1].strip()) == 0)):
                multi = ''
            else:
                multi = textwrap.dedent(parts[1])
            if (c == 'mode'):
                if (not self._output_modes):
                    self._cache_output_modes()
                firstline[1] = ((firstline[1] + '    ') + '    '.join(self._output_modes))
                multi = ((multi + '\n\n') + '\n\n'.join(self._output_modes_detail))
            if (c == 'colour'):
                colours = list(self._colours.keys())
                colours.sort()
                firstline[1] = ((firstline[1] + '    from    ') + ',    '.join(colours))
            if (len(multi.strip()) == 0):
                multi = None
            else:
                multi = multi.strip('\n')
                multi = multi.replace('\n\n', '\x00')
                multi = multi.replace('\n', '    ')
                multi = multi.replace('\x00', '\n\n')
                multi = multi.split('\n\n')
            self._help_info[c] = (('.' + firstline[0].strip()), firstline[1].strip(), multi)
    self.write(self.stderr, '\n')
    tw = self._terminal_width()
    if (tw < 32):
        tw = 32
    if (len(cmd) == 0):
        commands = list(self._help_info.keys())
        commands.sort()
        w = 0
        for command in commands:
            if (len(self._help_info[command][0]) > w):
                w = len(self._help_info[command][0])
        out = []
        for command in commands:
            hi = self._help_info[command]
            out.append(hi[0])
            out.append(('    ' * ((2 + w) - len(hi[0]))))
            out.append(('\n' + ('    ' * (2 + w))).join(textwrap.wrap(hi[1], ((tw - w) - 2))))
            out.append('\n')
        self.write(self.stderr, ''.join(out))
    else:
        if (cmd[0] == 'all'):
            cmd = list(self._help_info.keys())
            cmd.sort()
        w = 0
        for command in self._help_info:
            if (len(self._help_info[command][0]) > w):
                w = len(self._help_info[command][0])
        for command in cmd:
            if (command == 'headers'):
                command = 'header'
            if (command not in self._help_info):
                raise self.Error(('No    such    command    "%s"' % (command,)))
            out = []
            hi = self._help_info[command]
            out.append(hi[0])
            out.append(('    ' * ((2 + w) - len(hi[0]))))
            out.append((('\n' + ('    ' * (2 + w))).join(textwrap.wrap(hi[1], ((tw - w) - 2))) + '\n'))
            if hi[2]:
                out.append('\n')
                for (i, para) in enumerate(hi[2]):
                    out.append((textwrap.fill(para, tw) + '\n'))
                    if (i < (len(hi[2]) - 1)):
                        out.append('\n')
            if (command != cmd[0]):
                self.write(self.stderr, (('\n' + ('=' * tw)) + '\n'))
            self.write(self.stderr, ''.join(out))
    self.write(self.stderr, '\n')
