Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added changes to backends:get operation for M2 #6524

Merged
merged 12 commits into from
Nov 17, 2023
75 changes: 56 additions & 19 deletions src/commands/frameworks-backends-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,78 @@
import * as gcp from "../gcp/frameworks";
import { FirebaseError } from "../error";
import { logger } from "../logger";
const Table = require("cli-table");

Check warning on line 7 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value

Check warning on line 7 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Require statement not part of import statement

const COLUMN_LENGTH = 20;
const TABLE_HEAD = [
"Backend Id",
"Repository Name",
"Location",
"URL",
"Created Date",
"Updated Date",
];
export const command = new Command("backends:get")
.description("Get backend details of a Firebase project")
.option("-l, --location <location>", "App Backend location", "us-central1")
.option("--s, --backendId <backendId>", "Backend Id", "")
.option("-l, --location <location>", "App Backend location", "-")
.option("-b, --backend <backend>", "Backend Id", "")
.action(async (options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
const backendId = options.backendId as string;
const backendId = options.backend as string;
if (!backendId) {
throw new FirebaseError("Backend id can't be empty.");
}

let backend;
let backendsList: gcp.Backend[] = [];
const table = new Table({

Check warning on line 30 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value

Check warning on line 30 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe construction of an any type value
head: TABLE_HEAD,
style: { head: ["green"] },
});
table.colWidths = COLUMN_LENGTH;

Check warning on line 34 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .colWidths on an `any` value
try {
backend = await gcp.getBackend(projectId, location, backendId);
const table = new Table({
head: ["Backend Id", "Repository Name", "URL", "Location", "Created Date", "Updated Date"],
style: { head: ["green"] },
});
table.push([
backend.name,
backend.codebase.repository,
backend.uri,
backend.createTime,
backend.updateTime,
]);
logger.info(table.toString());
if (location !== "-") {
const backendInRegion = await gcp.getBackend(projectId, location, 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);
backendsList.forEach((bkd) => populateTable(bkd, table));
}

if (backendsList.length !== 0) {
logger.info(table.toString());

Check warning on line 47 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe argument of type `any` assigned to a parameter of type `Error`

Check warning on line 47 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .toString on an `any` value

Check warning on line 47 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe call of an `any` typed value
} else {
logger.info();
logger.info(`There are no backends with id: ${backendId}`);
}
} catch (err: any) {

Check warning on line 52 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
throw new FirebaseError(
`Failed to get backend: ${backendId}. Please check the parameters you have provided.`,
{ original: err }

Check warning on line 55 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value
);
}

return backend;
return backendsList;
});

function populateTable(backend: gcp.Backend, table: any) {
const [location, , backendId] = backend.name.split("/").slice(3, 6);
const entry = [
backendId,
backend.codebase.repository?.split("/").pop(),
location,
backend.uri,
backend.createTime,
backend.updateTime,
];
const newRow = entry.map((name) => {
const maxCellWidth = COLUMN_LENGTH - 2;
const chunks = [];
for (let i = 0; name && i < name.length; i += maxCellWidth) {
chunks.push(name.substring(i, i + maxCellWidth));
}
return chunks.join("\n");
});
table.push(newRow);
}
Loading