<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def format_cmd_output(cmd, output, name):
 """format command output for docs"""

    formatted = '.. code-block:: console\n\n'
    formatted += '   (venv)$ {c}\n'.format(c=cmd)
    lines = output.split("\n")
    if name != 'help':
        for idx, line in enumerate(lines):
            if len(line) > 100:
                lines[idx] = line[:100] + ' (...)'
        if len(lines) > 12:
            tmp_lines = lines[:5] + ['(...)'] + lines[-5:]
            if ' -l' in cmd or ' --list-defaults' in cmd:
                # find a line that uses a limit from the API,
                #  and a line with None (unlimited)
                api_line = None
                none_line = None
                for line in lines:
                    if '(API)' in line:
                        api_line = line
                        break
                for line in lines:
                    if line.strip().endswith('None'):
                        none_line = line
                        break
                tmp_lines = lines[:5]
                if api_line not in tmp_lines and api_line is not None:
                    tmp_lines = tmp_lines + ['(...)'] + [api_line]
                if none_line not in tmp_lines and none_line is not None:
                    tmp_lines = tmp_lines + ['(...)'] + [none_line]
                tmp_lines = tmp_lines + ['(...)'] + lines[-5:]
            lines = tmp_lines
    for line in lines:
        if line.strip() == '':
            continue
        formatted += '   ' + line + "\n"
    formatted += '\n'
    return formatted