@@ -429,6 +429,52 @@ export async function getBackendForLocation(
429
429
}
430
430
}
431
431
432
+ /**
433
+ * Fetches
434
+ *
435
+ *
436
+ */
437
+ export async function chooseBackend (
438
+ projectId : string ,
439
+ backendId : string ,
440
+ chooseBackendPrompt : string ,
441
+ force ?: boolean ,
442
+ ) : Promise < apphosting . Backend > {
443
+ let { unreachable, backends } = await apphosting . listBackends ( projectId , "-" ) ;
444
+ if ( unreachable && unreachable . length !== 0 ) {
445
+ logWarning (
446
+ `The following locations are currently unreachable: ${ unreachable } .\n` +
447
+ "If your backend is in one of these regions, please try again later." ,
448
+ ) ;
449
+ }
450
+ backends = backends . filter (
451
+ ( backend ) => apphosting . parseBackendName ( backend . name ) . id === backendId ,
452
+ ) ;
453
+ if ( backends . length === 0 ) {
454
+ throw new FirebaseError ( `No backend named "${ backendId } " found.` ) ;
455
+ }
456
+ if ( backends . length === 1 ) {
457
+ return backends [ 0 ] ;
458
+ }
459
+ if ( force ) {
460
+ throw new FirebaseError (
461
+ `Force cannot be used because multiple backends were found with ID ${ backendId } .`
462
+ ) ;
463
+ }
464
+
465
+ const backendsByName = new Map < string , apphosting . Backend > ( ) ;
466
+ backends . forEach ( ( backend ) =>
467
+ backendsByName . set ( `${ apphosting . parseBackendName ( backend . name ) . id } (${ apphosting . parseBackendName ( backend . name ) . location } )` , backend ) ,
468
+ ) ;
469
+ const chosenBackend = await promptOnce ( {
470
+ name : "backend" ,
471
+ type : "list" ,
472
+ message : chooseBackendPrompt ,
473
+ choices : [ ...backendsByName . keys ( ) ] ,
474
+ } ) ;
475
+ return backendsByName . get ( chosenBackend ) ! ;
476
+ }
477
+
432
478
/**
433
479
* Fetches a backend from the server. If there are multiple backends with that name (ie multi-regional backends),
434
480
* prompts the user to disambiguate. If the force option is specified and multiple backends have the same name,
0 commit comments