Repository: kedro-org/kedro

Issue:
Better handle the case when using both `--starter` and `--addons` 
## Description
It shouldn't be possible to use both `--starter` and `--addons` when doing `kedro new`. Currently you get a weird error:

```
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /Users/merel_theisen/anaconda3/envs/dev/bin/kedro:8 in <module>                                  │
│                                                                                                  │
│ /Users/merel_theisen/Projects/kedro/kedro/framework/cli/cli.py:197 in main                       │
│                                                                                                  │
│   194 │   """                                                                                    │
│   195 │   _init_plugins()                                                                        │
│   196 │   cli_collection = KedroCLI(project_path=Path.cwd())                                     │
│ ❱ 197 │   cli_collection()                                                                       │
│   198                                                                                            │
│                                                                                                  │
│ /Users/merel_theisen/anaconda3/envs/dev/lib/python3.11/site-packages/click/core.py:1157 in       │
│ __call__                                                                                         │
│                                                                                                  │
│ /Users/merel_theisen/Projects/kedro/kedro/framework/cli/cli.py:125 in main                       │
│                                                                                                  │
│   122 │   │   )                                                                                  │
│   123 │   │                                                                                      │
│   124 │   │   try:                                                                               │
│ ❱ 125 │   │   │   super().main(                                                                  │
│   126 │   │   │   │   args=args,                                                                 │
│   127 │   │   │   │   prog_name=prog_name,                                                       │
│   128 │   │   │   │   complete_var=complete_var,                                                 │
│                                                                                                  │
│ /Users/merel_theisen/anaconda3/envs/dev/lib/python3.11/site-packages/click/core.py:1078 in main  │
│                                                                                                  │
│ /Users/merel_theisen/anaconda3/envs/dev/lib/python3.11/site-packages/click/core.py:1688 in       │
│ invoke                                                                                           │
│                                                                                                  │
│ /Users/merel_theisen/anaconda3/envs/dev/lib/python3.11/site-packages/click/core.py:1434 in       │
│ invoke                                                                                           │
│                                                                                                  │
│ /Users/merel_theisen/anaconda3/envs/dev/lib/python3.11/site-packages/click/core.py:783 in invoke │
│                                                                                                  │
│ /Users/merel_theisen/Projects/kedro/kedro/framework/cli/starters.py:200 in new                   │
│                                                                                                  │
│   197 │   │   selected_add_ons_flag = selected_add_ons_flag.lower()                              │
│   198 │                                                                                          │
│   199 │   # Select which prompts will be displayed to the user based on which flags were selec   │
│ ❱ 200 │   prompts_required = _select_prompts_to_display(                                         │
│   201 │   │   prompts_required, selected_add_ons_flag, project_name                              │
│   202 │   )                                                                                      │
│   203                                                                                            │
│                                                                                                  │
│ /Users/merel_theisen/Projects/kedro/kedro/framework/cli/starters.py:496 in                       │
│ _select_prompts_to_display                                                                       │
│                                                                                                  │
│   493 │   │   │   │   err=True,                                                                  │
│   494 │   │   │   )                                                                              │
│   495 │   │   │   sys.exit(1)                                                                    │
│ ❱ 496 │   │   del prompts_required["add_ons"]                                                    │
│   497 │                                                                                          │
│   498 │   if project_name is not None:                                                           │
│   499 │   │   if not re.match(r"^[\w -]{2,}$", project_name):                                    │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'add_ons'
```

Instead, the user should get a more user friendly message saying these flags can't be used together. 





Discussion:
Same should be done for `--example` and `--starter`. 

Resolving patch:
diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py
--- a/kedro/framework/cli/starters.py
+++ b/kedro/framework/cli/starters.py
@@ -192,6 +192,11 @@ def new(  # noqa: PLR0913
             "Cannot use the --directory flag without a --starter value."
         )
 
+    if (selected_tools or example_pipeline) and starter_alias:
+        raise KedroCliError(
+            "Cannot use the --starter flag with the --example and/or --tools flag."
+        )
+
     starters_dict = _get_starters_dict()
 
     if starter_alias in starters_dict:


Test patch:
diff --git a/tests/framework/cli/test_starters.py b/tests/framework/cli/test_starters.py
--- a/tests/framework/cli/test_starters.py
+++ b/tests/framework/cli/test_starters.py
@@ -915,6 +915,30 @@ def test_directory_flag_with_starter_alias(self, fake_kedro_cli):
         assert result.exit_code != 0
         assert "Cannot use the --directory flag with a --starter alias" in result.output
 
+    def test_starter_flag_with_tools_flag(self, fake_kedro_cli):
+        result = CliRunner().invoke(
+            fake_kedro_cli,
+            ["new", "--tools", "all", "--starter", "spaceflights-pandas"],
+            input=_make_cli_prompt_input(),
+        )
+        assert result.exit_code != 0
+        assert (
+            "Cannot use the --starter flag with the --example and/or --tools flag."
+            in result.output
+        )
+
+    def test_starter_flag_with_example_flag(self, fake_kedro_cli):
+        result = CliRunner().invoke(
+            fake_kedro_cli,
+            ["new", "--starter", "spaceflights-pandas", "--example", "no"],
+            input=_make_cli_prompt_input(),
+        )
+        assert result.exit_code != 0
+        assert (
+            "Cannot use the --starter flag with the --example and/or --tools flag."
+            in result.output
+        )
+
 
 @pytest.mark.usefixtures("chdir_to_tmp")
 class TestToolsAndExampleFromUserPrompts: