def replace_arguments(cmd, args):
    """Do parameter substitution for the given command.

    The special variable $* is expanded to contain all filenames.
    """
    def arg_sub(m):
        """Replace a positional variable with the appropriate argument."""
        index = int(m.group(1)) - 1

        try:
            return args[index]
        except __HOLE__:
            return ''

    did_replacement = False

    shlex_convert_text_type = (not _SHLEX_SUPPORTS_UNICODE and
                               isinstance(cmd, six.text_type))

    if shlex_convert_text_type:
        cmd = cmd.encode('utf-8')

    for part in shlex.split(cmd):
        if part == '$*':
            did_replacement = True

            for arg in args:
                yield arg
        else:
            part, subs = _arg_re.subn(arg_sub, part)

            if subs != 0:
                did_replacement = True

            if shlex_convert_text_type:
                part = part.decode('utf-8')

            yield part

    if not did_replacement:
        for arg in args:
            yield arg
dataset/ETHPy150Open reviewboard/rbtools/rbtools/utils/aliases.py/replace_arguments