@@ -6,35 +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
- let location = options . location as string ;
24
- let backend : apphosting . Backend ;
25
- if ( location === "-" || location === "" ) {
26
- backend = await getBackendForAmbiguousLocation (
27
- projectId ,
28
- backendId ,
29
- "Please select the location of the backend you'd like to delete:" ,
30
- ) ;
31
- location = apphosting . parseBackendName ( backend . name ) . location ;
32
- } else {
33
- backend = await getBackendForLocation ( projectId , location , backendId ) ;
34
- }
35
18
36
- utils . logWarning ( "You are about to permanently delete this backend:" ) ;
37
- 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 ) ;
38
28
39
29
const confirmDeletion = await promptOnce (
40
30
{
@@ -49,14 +39,20 @@ export const command = new Command("apphosting:backends:delete <backend>")
49
39
return ;
50
40
}
51
41
52
- const spinner = ora ( "Deleting backend..." ) . start ( ) ;
53
- try {
54
- await deleteBackendAndPoll ( projectId , location , backendId ) ;
55
- spinner . succeed ( `Successfully deleted the backend: ${ backendId } ` ) ;
56
- } catch ( err : unknown ) {
57
- spinner . stop ( ) ;
58
- throw new FirebaseError ( `Failed to delete backend: ${ backendId } .` , {
59
- original : getError ( err ) ,
60
- } ) ;
42
+ for ( const b of backends ) {
43
+ const { location, id } = apphosting . parseBackendName ( b . name ) ;
44
+ const spinner = ora ( `Deleting backend ${ id } (${ location } )...` ) . start ( ) ;
45
+ try {
46
+ await deleteBackendAndPoll ( projectId , location , id ) ;
47
+ spinner . succeed ( `Successfully deleted the backend: ${ id } (${ location } )` ) ;
48
+ } catch ( err : unknown ) {
49
+ spinner . stop ( ) ;
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
+ }
61
57
}
62
58
} ) ;
0 commit comments