Skip to content

Commit 4343d35

Browse files
authored
Updated backends:list command. (#6519)
* Updated backends:list command w.r.t M2 * formatting file * Added changes to backends:list * resolved linter errors
1 parent 25a7239 commit 4343d35

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

src/commands/frameworks-backends-list.ts

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,67 @@ import * as gcp from "../gcp/frameworks";
55
import { FirebaseError } from "../error";
66
import { logger } from "../logger";
77
import { bold } from "colorette";
8-
const Table = require("cli-table");
98

9+
const Table = require("cli-table");
10+
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+
];
1019
export const command = new Command("backends:list")
1120
.description("List backends of a Firebase project.")
12-
.option("-l, --location <location>", "App Backend location", "us-central1")
21+
.option("-l, --location <location>", "App Backend location", "-")
1322
.action(async (options: Options) => {
1423
const projectId = needProjectId(options);
1524
const location = options.location as string;
1625
const table = new Table({
17-
head: ["Backend Id", "Repository Name", "URL", "Location", "Created Date", "Updated Date"],
26+
head: TABLE_HEAD,
1827
style: { head: ["green"] },
1928
});
20-
21-
let backendsList;
29+
table.colWidths = COLUMN_LENGTH;
30+
const backendsList: gcp.ListBackendsResponse[] = [];
2231
try {
23-
backendsList = await gcp.listBackends(projectId, location);
24-
for (const backend of backendsList.backends) {
25-
const entry = [
26-
backend.name,
27-
backend.codebase.repository,
28-
backend.uri,
29-
backend.createTime,
30-
backend.updateTime,
31-
];
32-
table.push(entry);
33-
}
32+
const backendsPerRegion = await gcp.listBackends(projectId, location);
33+
backendsList.push(backendsPerRegion);
34+
populateTable(backendsPerRegion, location, table);
35+
36+
logger.info();
3437
logger.info(`Backends for project ${bold(projectId)}`);
38+
logger.info();
3539
logger.info(table.toString());
3640
} catch (err: any) {
3741
throw new FirebaseError(
38-
`Unable to list backends present in project: ${projectId}. Please check the parameters you have provided.`,
42+
`Unable to list backends present for project: ${projectId}. Please check the parameters you have provided.`,
3943
{ original: err }
4044
);
4145
}
4246

4347
return backendsList;
4448
});
49+
50+
function populateTable(backendsLists: gcp.ListBackendsResponse, location: string, table: any) {
51+
for (const backend of backendsLists.backends) {
52+
const [location, , backendId] = backend.name.split("/").slice(3, 6);
53+
const entry = [
54+
backendId,
55+
backend.codebase.repository?.split("/").pop(),
56+
location,
57+
backend.uri,
58+
backend.createTime,
59+
backend.updateTime,
60+
];
61+
const newRow = entry.map((name) => {
62+
const maxCellWidth = COLUMN_LENGTH - 2;
63+
const chunks = [];
64+
for (let i = 0; name && i < name.length; i += maxCellWidth) {
65+
chunks.push(name.substring(i, i + maxCellWidth));
66+
}
67+
return chunks.join("\n");
68+
});
69+
table.push(newRow);
70+
}
71+
}

0 commit comments

Comments
 (0)