docs: def execute_cmd(cmd, **kwargs):
      """
      Call given command, yielding output line by line
      """
      yield '$ {}\n'.format(' '.join(cmd))
      kwargs['stdout'] = subprocess.PIPE
      kwargs['stderr'] = subprocess.STDOUT
  
      proc = subprocess.Popen(cmd, **kwargs)
  
      # Capture output for logging.
      # Each line will be yielded as text.
      # This should behave the same as .readline(), but splits on `\r` OR `\n`,
      # not just `\n`.
      buf = []
      def flush():
          line = b''.join(buf).decode('utf8', 'replace')
          buf[:] = []
          return line
  
      c_last = ''
      try:
          for c in iter(partial(proc.stdout.read, 1), b''):
              if c_last == b'\r' and buf and c != b'\n':
                  yield flush()
              buf.append(c)
              if c == b'\n':
                  yield flush()
              c_last = c
      finally:
          ret = proc.wait()
          if ret != 0:
              raise subprocess.CalledProcessError(ret, cmd)