Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions src/commands/frameworks-backends-get.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import * as gcp from "../gcp/frameworks";
import { Command } from "../command";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";
import * as gcp from "../gcp/frameworks";
import { FirebaseError } from "../error";
import { logger } from "../logger";
import { ensureApiEnabled } from "../gcp/frameworks";
import { logWarning } from "../utils";

const Table = require("cli-table");
const COLUMN_LENGTH = 20;
const TABLE_HEAD = [
"Backend Id",
"Repository Name",
"Location",
"URL",
"Created Date",
"Updated Date",
];
const TABLE_HEAD = ["Backend Id", "Repository", "Location", "URL", "Created Date", "Updated Date"];
export const command = new Command("backends:get <backendId>")
.description("Get backend details of a Firebase project")
.option("-l, --location <location>", "App Backend location", "-")
Expand All @@ -36,25 +30,23 @@ export const command = new Command("backends:get <backendId>")
backendsList.push(backendInRegion);
populateTable(backendInRegion, table);
} else {
const allBackend = await gcp.listBackends(projectId, location);
backendsList = allBackend.backends.filter((bkd) => bkd.name.split("/").pop() === backendId);
const resp = await gcp.listBackends(projectId, "-");
const allBackends = resp.backends || [];
backendsList = allBackends.filter((bkd) => bkd.name.split("/").pop() === backendId);
backendsList.forEach((bkd) => populateTable(bkd, table));
}

if (backendsList.length !== 0) {
logger.info(table.toString());
} else {
logger.info();
logger.info(`There are no backends with id: ${backendId}`);
}
} catch (err: any) {
throw new FirebaseError(
`Failed to get backend: ${backendId}. Please check the parameters you have provided.`,
{ original: err }
);
}

return backendsList;
if (backendsList.length === 0) {
logWarning(`Found no backend with id: ${backendId}`);
return;
}
logger.info(table.toString());
return backendsList[0];
});

function populateTable(backend: gcp.Backend, table: any) {
Expand Down
7 changes: 1 addition & 6 deletions src/commands/frameworks-backends-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { needProjectId } from "../projectUtils";
import * as gcp from "../gcp/frameworks";
import { FirebaseError } from "../error";
import { logger } from "../logger";
import { bold } from "colorette";
import { ensureApiEnabled } from "../gcp/frameworks";

const Table = require("cli-table");
Expand All @@ -25,12 +24,8 @@ export const command = new Command("backends:list")
const backendsList: gcp.Backend[] = [];
try {
const backendsPerRegion = await gcp.listBackends(projectId, location);
backendsList.push(...backendsPerRegion.backends);
backendsList.push(...(backendsPerRegion.backends || []));
populateTable(backendsList, table);

logger.info();
logger.info(`Backends for project ${bold(projectId)}`);
logger.info();
logger.info(table.toString());
} catch (err: any) {
throw new FirebaseError(
Expand Down