Repository: meltano/meltano

Issue:
bug: identical project name prevents selection of default project
```
❯ meltano-cloud project use --name taylor-test2
2023-08-21 16:34:58 [debug    ] Making Cloud CLI HTTP request  method=GET url=https://internal.api.meltano.cloud/projects/v1/01GV0Z1VW5TSRF8BYX1J2V3WNT
Error: Multiple Meltano Cloud projects have the same name. Please specify the project using the `--id` option with its internal ID, shown below. Note that these IDs may change at any time. To avoid this issue, please use unique project names.
01GGWBJ538JBBW4TV91E4ST1PF: Meltano Squared ('https://github.com/meltano/squared.git')
01GVR8N319XJPPG9C8184GCKQB: private-meltano-demo-in-a-box ('https://github.com/meltano/meltano-demo-in-a-box.git')
01H7GHXGAZAXGHZR3WPJ1RS2QE: cody-test-9 ('https://github.com/meltano/test-project-9 --root-path /some/path\n\n.git')
01H7GHY1EH9EMMBRF98N5YJF99: cody-test-9 ('https://github.com/meltano/test-project-9.git')
01H8D07597KR2Y474SSJG3CTT2: taylor-test2 ('https://github.com/meltano/squared.git')
```


Discussion:

Resolving patch:
diff --git a/src/meltano/cloud/cli/project.py b/src/meltano/cloud/cli/project.py
--- a/src/meltano/cloud/cli/project.py
+++ b/src/meltano/cloud/cli/project.py
@@ -192,21 +192,42 @@ async def list_projects(
     )
 
 
+def _print_projects(projects: list[CloudProject]) -> None:
+    for project in projects:
+        click.echo(
+            f"{project['project_id']}: {project['project_name']} "
+            f"({project['git_repository']!r})",
+        )
+
+
 def _check_for_duplicate_project_names(projects: list[CloudProject]) -> None:
     project_names = [x["project_name"] for x in projects]
     if len(set(project_names)) != len(project_names):
         click.secho(
-            "Error: Multiple Meltano Cloud projects have the same name. "
+            "Error: Multiple Meltano Cloud projects have the same name. If you are "
+            "trying to use a project with an unambiguous name, please select it with "
+            "the `--name` option. Otherwise, please specify the project using the "
+            "`--id` option with its internal ID, shown below. Note that these IDs may "
+            "change at any time. To avoid this issue, please use unique project names.",
+            fg="red",
+        )
+        _print_projects(projects)
+        sys.exit(1)
+
+
+def _check_for_project_name_conflict(
+    projects: list[CloudProject],
+    project_name: str,
+) -> None:
+    if [x["project_name"] for x in projects].count(project_name) > 1:
+        click.secho(
+            "Error: Multiple Meltano Cloud projects have the specified name. "
             "Please specify the project using the `--id` option with its "
             "internal ID, shown below. Note that these IDs may change at any "
             "time. To avoid this issue, please use unique project names.",
             fg="red",
         )
-        for project in projects:
-            click.echo(
-                f"{project['project_id']}: {project['project_name']} "
-                f"({project['git_repository']!r})",
-            )
+        _print_projects(projects)
         sys.exit(1)
 
 
@@ -297,7 +318,7 @@ async def use_project(
 
     if context.projects is None:  # Interactive config was not used
         context.projects = (await _get_projects(context.config)).items
-        _check_for_duplicate_project_names(context.projects)
+        _check_for_project_name_conflict(context.projects, t.cast(str, project_name))
         if project_name not in {x["project_name"] for x in context.projects}:
             raise click.ClickException(
                 f"Unable to use project named {project_name!r} - no available "


Test patch:
diff --git a/tests/meltano/cloud/cli/test_project.py b/tests/meltano/cloud/cli/test_project.py
--- a/tests/meltano/cloud/cli/test_project.py
+++ b/tests/meltano/cloud/cli/test_project.py
@@ -23,7 +23,7 @@
 
 
 class TestProjectCommand:
-    """Test the logs command."""
+    """Test the project command."""
 
     @pytest.fixture()
     def projects(self, tenant_resource_key: str) -> list[CloudProject]:
@@ -365,7 +365,7 @@ def test_project_use_ambigous_name_error(
         )
         assert result.exit_code == 1
         assert result.output == (
-            "Error: Multiple Meltano Cloud projects have the same name. "
+            "Error: Multiple Meltano Cloud projects have the specified name. "
             "Please specify the project using the `--id` option with its "
             "internal ID, shown below. Note that these IDs may change at any "
             "time. To avoid this issue, please use unique project names.\n"