1
+ import * as gcp from "../gcp/frameworks" ;
1
2
import { Command } from "../command" ;
2
3
import { Options } from "../options" ;
3
4
import { needProjectId } from "../projectUtils" ;
4
- import * as gcp from "../gcp/frameworks" ;
5
5
import { FirebaseError } from "../error" ;
6
6
import { logger } from "../logger" ;
7
7
import { ensureApiEnabled } from "../gcp/frameworks" ;
8
+ import { logWarning } from "../utils" ;
8
9
9
10
const Table = require ( "cli-table" ) ;
10
11
const 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" ] ;
19
13
export const command = new Command ( "backends:get <backendId>" )
20
14
. description ( "Get backend details of a Firebase project" )
21
15
. option ( "-l, --location <location>" , "App Backend location" , "-" )
@@ -36,25 +30,23 @@ export const command = new Command("backends:get <backendId>")
36
30
backendsList . push ( backendInRegion ) ;
37
31
populateTable ( backendInRegion , table ) ;
38
32
} 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 ) ;
41
36
backendsList . forEach ( ( bkd ) => populateTable ( bkd , table ) ) ;
42
37
}
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
- }
50
38
} catch ( err : any ) {
51
39
throw new FirebaseError (
52
40
`Failed to get backend: ${ backendId } . Please check the parameters you have provided.` ,
53
41
{ original : err }
54
42
) ;
55
43
}
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 ] ;
58
50
} ) ;
59
51
60
52
function populateTable ( backend : gcp . Backend , table : any ) {
0 commit comments