def _build_archiver_command(self, command: str, wal_filename: str) -> str:
        """Replace placeholders in the given archiver command's template.
        Applicable for archive_command and restore_command.
        Can also be used for archive_cleanup_command and recovery_end_command,
        however %r value is always set to 000000010000000000000001."""
        cmd = ''
        length = len(command)
        i = 0
        while i < length:
            if command[i] == '%' and i + 1 < length:
                i += 1
                if command[i] == 'p':
                    cmd += os.path.join(self._postgresql.wal_dir, wal_filename)
                elif command[i] == 'f':
                    cmd += wal_filename
                elif command[i] == 'r':
                    cmd += '000000010000000000000001'
                elif command[i] == '%':
                    cmd += '%'
                else:
                    cmd += '%'
                    i -= 1
            else:
                cmd += command[i]
            i += 1

        return cmd
Replace placeholders in the given archiver command's template.
        Applicable for archive_command and restore_command.
        Can also be used for archive_cleanup_command and recovery_end_command,
        however %r value is always set to 000000010000000000000001.
patroni/postgresql/rewind.py