@@ -6,38 +6,25 @@ import { promptOnce } from "../prompt";
6
6
import * as utils from "../utils" ;
7
7
import * as apphosting from "../gcp/apphosting" ;
8
8
import { printBackendsTable } from "./apphosting-backends-list" ;
9
- import {
10
- deleteBackendAndPoll ,
11
- getBackendForAmbiguousLocation ,
12
- getBackendForLocation ,
13
- } from "../apphosting/backend" ;
9
+ import { deleteBackendAndPoll , chooseBackends } from "../apphosting/backend" ;
14
10
import * as ora from "ora" ;
15
11
16
12
export const command = new Command ( "apphosting:backends:delete <backend>" )
17
13
. description ( "delete a Firebase App Hosting backend" )
18
- . option ( "-l, --location <location>" , "specify the location of the backend" )
19
14
. withForce ( )
20
15
. before ( apphosting . ensureApiEnabled )
21
16
. action ( async ( backendId : string , options : Options ) => {
22
17
const projectId = needProjectId ( options ) ;
23
- if ( options . location !== undefined ) {
24
- utils . logWarning ( "--location is being removed in the next major release." ) ;
25
- }
26
- let location = ( options . location as string ) ?? "-" ;
27
- let backend : apphosting . Backend ;
28
- if ( location === "-" || location === "" ) {
29
- backend = await getBackendForAmbiguousLocation (
30
- projectId ,
31
- backendId ,
32
- "Please select the location of the backend you'd like to delete:" ,
33
- ) ;
34
- location = apphosting . parseBackendName ( backend . name ) . location ;
35
- } else {
36
- backend = await getBackendForLocation ( projectId , location , backendId ) ;
37
- }
38
18
39
- utils . logWarning ( "You are about to permanently delete this backend:" ) ;
40
- printBackendsTable ( [ backend ] ) ;
19
+ const backends = await chooseBackends (
20
+ projectId ,
21
+ backendId ,
22
+ "Please select the backends you'd like to delete:" ,
23
+ options . force ,
24
+ ) ;
25
+
26
+ utils . logWarning ( "You are about to permanently delete these backend(s):" ) ;
27
+ printBackendsTable ( backends ) ;
41
28
42
29
const confirmDeletion = await promptOnce (
43
30
{
@@ -52,14 +39,20 @@ export const command = new Command("apphosting:backends:delete <backend>")
52
39
return ;
53
40
}
54
41
55
- const spinner = ora ( "Deleting backend..." ) . start ( ) ;
56
- try {
57
- await deleteBackendAndPoll ( projectId , location , backendId ) ;
58
- spinner . succeed ( `Successfully deleted the backend: ${ backendId } ` ) ;
59
- } catch ( err : unknown ) {
60
- spinner . stop ( ) ;
61
- throw new FirebaseError ( `Failed to delete backend: ${ backendId } .` , {
62
- original : getError ( err ) ,
63
- } ) ;
64
- }
42
+ const spinner = ora ( "Deleting backend(s)..." ) . start ( ) ;
43
+
44
+ backends . forEach ( async ( b ) => {
45
+ const { location, id } = apphosting . parseBackendName ( b . name ) ;
46
+ try {
47
+ await deleteBackendAndPoll ( projectId , location , id ) ;
48
+ spinner . succeed ( `Successfully deleted the backend: ${ id } (${ location } )` ) ;
49
+ } catch ( err : unknown ) {
50
+ throw new FirebaseError (
51
+ `Failed to delete backend: ${ id } (${ location } ). Please retry to delete remaining backends.` ,
52
+ {
53
+ original : getError ( err ) ,
54
+ } ,
55
+ ) ;
56
+ }
57
+ } ) ;
65
58
} ) ;
0 commit comments