def get_flags_and_sanitize()

in l10n_CM/run_l10n.py [0:0]


def get_flags_and_sanitize(flags_arguments: list[str]) -> list[str]:
    """
    Extract and validate pytest flags from command-line arguments.

    Args:
        flags_arguments (list[str]): List of command-line arguments passed to the script.

    Returns:
        list[str]: A sanitized list of valid pytest flags.

    Raises:
        IndexError: If a flag that is supposed to have an option doesn't
        ValueError: If an arg or flag is not valid.
    """
    # add workers and rerun flaky failed tests.
    flg = []
    for arg in flags_arguments[:]:
        if arg in valid_flags:
            if arg in flag_with_parameter:
                try:
                    i = flags_arguments.index(arg)
                    val = int(flags_arguments[i + 1])
                    flg.extend((arg, str(val)))
                    del flags_arguments[i : i + 2]
                except IndexError:
                    logging.warning(f"Argument {arg} doesn't have proper value.")
                    raise IndexError(f"Argument {arg} doesn't have proper value.")
                except ValueError:
                    logging.warning(f"Value for Argument {arg} must be an int.")
                    raise IndexError(f"Value for Argument {arg} must be an int.")
            else:
                flags_arguments.remove(arg)
                flg.append(arg)
        elif arg in valid_region or arg.isdigit():
            continue
        elif arg in valid_sites:
            live_sites.append(arg)
            flags_arguments.remove(arg)
        else:
            logging.warning(f"Invalid Argument: {arg}.")
            raise ValueError(f"Invalid Argument: {arg}.")
    return flg