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

Code before:
                fg="yellow",
            )

    if "output_dir" in config and not Path(config["output_dir"]).exists():
        raise KedroCliError(
            f"'{config['output_dir']}' is not a valid output directory. "
            "It must be a relative or absolute path to an existing directory."
        )


def _validate_config_file_inputs(config: dict[str, str], starter_alias: str | None):
    """Checks that variables provided through the config file are of the expected format. This
    validate the config provided by `kedro new --config` in a similar way to `prompts.yml`
    for starters.
    Also validates that "tools" or "example_pipeline" options cannot be used in config when any starter option is selected.

    Args:
        config: The config as a dictionary
        starter_alias: Starter alias if it was provided from CLI, otherwise None

    Raises:
        SystemExit: If the provided variables are not properly formatted.
    """
    if starter_alias and ("tools" in config or "example_pipeline" in config):
        raise KedroCliError(
            "Cannot use the --starter flag with the --example and/or --tools options in config."
        )

    project_name_validation_config = {
        "regex_validator": r"^[\w -]{2,}$",
        "error_message": "'{input_project_name}' is an invalid value for project name. It must contain only alphanumeric symbols, spaces, underscores and hyphens and be at least 2 characters long",
    }

    input_project_name = config.get("project_name", "New Kedro Project")
    if not re.match(
        project_name_validation_config["regex_validator"], input_project_name
    ):
        click.secho(project_name_validation_config["error_message"], fg="red", err=True)
        sys.exit(1)

    input_tools = config.get("tools", "none")
    tools_validation_config = {
        "regex_validator": r"^(all|none|(( )*\d*(,\d*)*(,( )*\d*)*( )*|( )*((\d+-\d+)|(\d+ - \d+))( )*))$",
        "error_message": f"'{input_tools}' is an invalid value for project tools. Please select valid options for tools using comma-separated values, ranges, or 'all/none'.",
    }

    if not re.match(tools_validation_config["regex_validator"], input_tools.lower()):
        message = tools_validation_config["error_message"]
        click.secho(message, fg="red", err=True)
        sys.exit(1)


Review comment (suggestion):
```suggestion
            "The --starter flag can not be used with `example_pipeline` and/or `tools` keys in the config file."
```

Code after:
    for key, default_value in additional_keys.items():
        if key in missing_keys:
            click.secho(
                f"The `{key}` key not found in the config file, default value '{default_value}' is being used.",
                fg="yellow",
            )

    if "output_dir" in config and not Path(config["output_dir"]).exists():
        raise KedroCliError(
            f"'{config['output_dir']}' is not a valid output directory. "
            "It must be a relative or absolute path to an existing directory."
        )


def _validate_config_file_inputs(config: dict[str, str], starter_alias: str | None):
    """Checks that variables provided through the config file are of the expected format. This
    validate the config provided by `kedro new --config` in a similar way to `prompts.yml`
    for starters.
    Also validates that "tools" or "example_pipeline" options cannot be used in config when any starter option is selected.

    Args:
        config: The config as a dictionary
        starter_alias: Starter alias if it was provided from CLI, otherwise None

    Raises:
        SystemExit: If the provided variables are not properly formatted.
    """
    if starter_alias and ("tools" in config or "example_pipeline" in config):
        raise KedroCliError(
            "The --starter flag can not be used with `example_pipeline` and/or `tools` keys in the config file."
        )

    project_name_validation_config = {
        "regex_validator": r"^[\w -]{2,}$",
        "error_message": "'{input_project_name}' is an invalid value for project name. It must contain only alphanumeric symbols, spaces, underscores and hyphens and be at least 2 characters long",
    }

    input_project_name = config.get("project_name", "New Kedro Project")
    if not re.match(
        project_name_validation_config["regex_validator"], input_project_name
    ):
        click.secho(project_name_validation_config["error_message"], fg="red", err=True)
        sys.exit(1)

    input_tools = config.get("tools", "none")
    tools_validation_config = {
        "regex_validator": r"""^(
            all|none|                        # A: "all" or "none" or
            (\ *\d+                          # B: any number of spaces followed by one or more digits
            (\ *-\ *\d+)?                    # C: zero or one instances of: a hyphen followed by one or more digits, spaces allowed
            (\ *,\ *\d+(\ *-\ *\d+)?)*       # D: any number of instances of: a comma followed by B and C, spaces allowed