diff --git a/src/apphosting/index.ts b/src/apphosting/index.ts index 97869ba1b7f..faba4ab5181 100644 --- a/src/apphosting/index.ts +++ b/src/apphosting/index.ts @@ -408,10 +408,7 @@ export async function deleteBackendAndPoll( /** * Prompts the user for a location. */ -export async function promptLocation( - projectId: string, - prompt = "Please select a location:", -): Promise { +export async function promptLocation(projectId: string, prompt: string): Promise { const allowedLocations = (await apphosting.listLocations(projectId)).map((loc) => loc.locationId); return (await promptOnce({ @@ -430,6 +427,7 @@ export async function promptLocation( export async function getBackendForAmbiguousLocation( projectId: string, backendId: string, + locationDisambugationPrompt: string, ): Promise { let { unreachable, backends } = await apphosting.listBackends(projectId, "-"); if (unreachable && unreachable.length !== 0) { @@ -455,7 +453,7 @@ export async function getBackendForAmbiguousLocation( const location = await promptOnce({ name: "location", type: "list", - message: "Please select the location of the backend you'd like to delete:", + message: locationDisambugationPrompt, choices: [...backendsByLocation.keys()], }); return backendsByLocation.get(location)!; diff --git a/src/commands/apphosting-backends-delete.ts b/src/commands/apphosting-backends-delete.ts index de81b4a6e80..d54e4f6192b 100644 --- a/src/commands/apphosting-backends-delete.ts +++ b/src/commands/apphosting-backends-delete.ts @@ -19,7 +19,11 @@ export const command = new Command("apphosting:backends:delete ") let location = options.location as string; let backend: apphosting.Backend; if (location === "-" || location === "") { - backend = await getBackendForAmbiguousLocation(projectId, backendId); + backend = await getBackendForAmbiguousLocation( + projectId, + backendId, + "Please select the location of the backend you'd like to delete:", + ); location = apphosting.parseBackendName(backend.name).location; } else { backend = await getBackendForLocation(projectId, location, backendId); diff --git a/src/test/apphosting/index.spec.ts b/src/test/apphosting/index.spec.ts index 938181a5fe5..2308859549a 100644 --- a/src/test/apphosting/index.spec.ts +++ b/src/test/apphosting/index.spec.ts @@ -256,7 +256,7 @@ describe("apphosting setup functions", () => { }); }); - describe.only("getBackendForAmbiguousLocation", () => { + describe("getBackendForAmbiguousLocation", () => { const backendFoo = { name: `projects/${projectId}/locations/${location}/backends/foo`, labels: {}, @@ -284,26 +284,26 @@ describe("apphosting setup functions", () => { it("throws if there are no matching backends", async () => { listBackendsStub.resolves({ backends: [] }); - await expect(getBackendForAmbiguousLocation(projectId, "baz")).to.be.rejectedWith( - /No backend named "baz" found./, - ); + await expect( + getBackendForAmbiguousLocation(projectId, "baz", /* prompt= */ ""), + ).to.be.rejectedWith(/No backend named "baz" found./); }); it("returns unambiguous backend", async () => { listBackendsStub.resolves({ backends: [backendFoo, backendBar] }); - await expect(getBackendForAmbiguousLocation(projectId, "foo")).to.eventually.equal( - backendFoo, - ); + await expect( + getBackendForAmbiguousLocation(projectId, "foo", /* prompt= */ ""), + ).to.eventually.equal(backendFoo); }); it("prompts for location if backend is ambiguous", async () => { listBackendsStub.resolves({ backends: [backendFoo, backendFooOtherRegion, backendBar] }); promptOnceStub.resolves(location); - await expect(getBackendForAmbiguousLocation(projectId, "foo")).to.eventually.equal( - backendFoo, - ); + await expect( + getBackendForAmbiguousLocation(projectId, "foo", /* prompt= */ ""), + ).to.eventually.equal(backendFoo); expect(promptOnceStub).to.be.calledWith({ name: "location",