1+ import * as gcp from "../gcp/frameworks" ;
12import { Command } from "../command" ;
23import { Options } from "../options" ;
34import { needProjectId } from "../projectUtils" ;
4- import * as gcp from "../gcp/frameworks" ;
55import { FirebaseError } from "../error" ;
66import { logger } from "../logger" ;
77import { ensureApiEnabled } from "../gcp/frameworks" ;
8+ import { logWarning } from "../utils" ;
89
910const Table = require ( "cli-table" ) ;
1011const COLUMN_LENGTH = 20 ;
11- const TABLE_HEAD = [
12- "Backend Id" ,
13- "Repository Name" ,
14- "Location" ,
15- "URL" ,
16- "Created Date" ,
17- "Updated Date" ,
18- ] ;
12+ const TABLE_HEAD = [ "Backend Id" , "Repository" , "Location" , "URL" , "Created Date" , "Updated Date" ] ;
1913export const command = new Command ( "backends:get <backendId>" )
2014 . description ( "Get backend details of a Firebase project" )
2115 . option ( "-l, --location <location>" , "App Backend location" , "-" )
@@ -36,25 +30,23 @@ export const command = new Command("backends:get <backendId>")
3630 backendsList . push ( backendInRegion ) ;
3731 populateTable ( backendInRegion , table ) ;
3832 } else {
39- const allBackend = await gcp . listBackends ( projectId , location ) ;
40- backendsList = allBackend . backends . filter ( ( bkd ) => bkd . name . split ( "/" ) . pop ( ) === backendId ) ;
33+ const resp = await gcp . listBackends ( projectId , "-" ) ;
34+ const allBackends = resp . backends || [ ] ;
35+ backendsList = allBackends . filter ( ( bkd ) => bkd . name . split ( "/" ) . pop ( ) === backendId ) ;
4136 backendsList . forEach ( ( bkd ) => populateTable ( bkd , table ) ) ;
4237 }
43-
44- if ( backendsList . length !== 0 ) {
45- logger . info ( table . toString ( ) ) ;
46- } else {
47- logger . info ( ) ;
48- logger . info ( `There are no backends with id: ${ backendId } ` ) ;
49- }
5038 } catch ( err : any ) {
5139 throw new FirebaseError (
5240 `Failed to get backend: ${ backendId } . Please check the parameters you have provided.` ,
5341 { original : err }
5442 ) ;
5543 }
56-
57- return backendsList ;
44+ if ( backendsList . length === 0 ) {
45+ logWarning ( `Found no backend with id: ${ backendId } ` ) ;
46+ return ;
47+ }
48+ logger . info ( table . toString ( ) ) ;
49+ return backendsList [ 0 ] ;
5850 } ) ;
5951
6052function populateTable ( backend : gcp . Backend , table : any ) {
0 commit comments