Repository: kedro-org/kedro
File: kedro/framework/cli/starters.py (Python)

Code before:
        )

    # Format
    extra_context.setdefault("kedro_version", version)

    add_ons = _convert_addon_names_to_numbers(selected_add_ons_flag)

    if add_ons is not None:
        extra_context["add_ons"] = add_ons

    if project_name is not None:
        extra_context["project_name"] = project_name

    # Map the selected add on lists to readable name
    add_ons = extra_context.get("add_ons")
    if add_ons:
        extra_context["add_ons"] = [
            NUMBER_TO_ADD_ONS_NAME[add_on]
            for add_on in _parse_add_ons_input(add_ons)  # type: ignore
        ]
        extra_context["add_ons"] = str(extra_context["add_ons"])

    extra_context["example_pipeline"] = (
        example_pipeline  # type: ignore
        if example_pipeline is not None
        else _validate_yn(None, None, extra_context.get("example_pipeline", None))
    )

    return extra_context


def _convert_addon_names_to_numbers(selected_add_ons_flag: str | None) -> str | None:
    """Prepares add-on selection from the CLI input to the correct format
    to be put in the project configuration, if it exists.
    Replaces add-on strings with the corresponding prompt number.

    Args:
        selected_add_ons_flag: a string containing the value for the --addons flag,
            or None in case the flag wasn't used, i.e. lint,docs.

    Returns:
        String with the numbers corresponding to the desired add_ons, or
        None in case the --addons flag was not used.
    """
    if selected_add_ons_flag is None:
        return None

    addons = []
    for addon in selected_add_ons_flag.lower().split(","):
        addon_short_name = addon.strip()
        if addon_short_name in ADD_ONS_SHORTNAME_TO_NUMBER:

Review comment (refactor):
The `_validate_yn` is expected to used in `click`. It feels weird to have `_validate_yn(None, None, ...)`. Can we simplify this a little bit, there is a lot of handling or `None`, if we can make sure this is a `bool` early on we can save ourselves a lot of checking.

Code after:
    if add_ons:
        extra_context["add_ons"] = [
            NUMBER_TO_ADD_ONS_NAME[add_on]
            for add_on in _parse_add_ons_input(add_ons)  # type: ignore
        ]
        extra_context["add_ons"] = str(extra_context["add_ons"])

    extra_context["example_pipeline"] = (
        _parse_yes_no_to_bool(
            example_pipeline
            if example_pipeline is not None
            else extra_context.get("example_pipeline", "no")
        )  # type: ignore
    )

    return extra_context


def _convert_addon_names_to_numbers(selected_add_ons_flag: str | None) -> str | None:
    """Prepares add-on selection from the CLI input to the correct format
    to be put in the project configuration, if it exists.
    Replaces add-on strings with the corresponding prompt number.

    Args:
        selected_add_ons_flag: a string containing the value for the --addons flag,
            or None in case the flag wasn't used, i.e. lint,docs.

    Returns:
        String with the numbers corresponding to the desired add_ons, or
        None in case the --addons flag was not used.
    """
    if selected_add_ons_flag is None:
        return None

    addons = []
    for addon in selected_add_ons_flag.lower().split(","):
        addon_short_name = addon.strip()
        if addon_short_name in ADD_ONS_SHORTNAME_TO_NUMBER:
            addons.append(ADD_ONS_SHORTNAME_TO_NUMBER[addon_short_name])
    return ",".join(addons)


def _select_prompts_to_display(
    prompts_required: dict,
    selected_add_ons_flag: str,
    project_name: str,
    example_pipeline: str,
) -> dict:
    """Selects which prompts an user will receive when creating a new
    Kedro project, based on what information was already made available
    through CLI input.