def run_oneline_cmd(args, cwd=None, env=None):
    """
    run_oneline_cmd(args, cwd=None, env=None) --> line

    Wrapper around run_simple_cmd() that also expects the command to print
    exactly one line (terminated with a newline) to stdout.  If the command
    does not print a single line, a CmdFailedError is raised.

    Returns the command output, with the terminating newline removed.
    """
    cmd_out = run_simple_cmd(args, cwd=cwd, env=env)

    if not cmd_out:
        msg = 'did not print any output'
        raise CmdFailedError(args, msg)

    lines = cmd_out.split('\n')
    num_lines = len(lines)
    if num_lines < 2:
        # XXX: It would be nice to include cmd_out in the exception
        msg = 'did not print a terminating newline'
        raise CmdFailedError(args, msg)
    elif num_lines > 2 or lines[1]:
        # XXX: It would be nice to include cmd_out in the exception
        msg = 'printed more than one line of output'
        raise CmdFailedError(args, msg)

    return lines[0]
dataset/ETHPy150Open facebookarchive/git-review/src/gitreview/proc.py/run_oneline_cmd/original