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

Updated delete command for M2 #6525

Merged
merged 6 commits into from
Nov 16, 2023
Merged
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
78 changes: 72 additions & 6 deletions src/commands/frameworks-backends-delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,73 @@
import * as gcp from "../gcp/frameworks";
import { promptOnce } from "../prompt";
import * as utils from "../utils";
import { logger } from "../logger";
import { DEFAULT_REGION, ALLOWED_REGIONS } from "../init/features/frameworks/constants";
const Table = require("cli-table");

Check warning on line 10 in src/commands/frameworks-backends-delete.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value

Check warning on line 10 in src/commands/frameworks-backends-delete.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:delete")
.description("Delete a backend from 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("-s, --backend <backend>", "Backend Id", "")
.withForce()
.action(async (options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
const backendId = options.backendId as string;
let location = options.location as string;
const backendId = options.backend as string;
if (!backendId) {
throw new FirebaseError("Backend id can't be empty.");
}

if (!location) {
location = await promptOnce({

Check warning on line 36 in src/commands/frameworks-backends-delete.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value
name: "region",
type: "list",
default: DEFAULT_REGION,
message: "Please select the region of the backend you'd like to delete:",
choices: ALLOWED_REGIONS,
});
}

const table = new Table({

Check warning on line 45 in src/commands/frameworks-backends-delete.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value

Check warning on line 45 in src/commands/frameworks-backends-delete.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 49 in src/commands/frameworks-backends-delete.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .colWidths on an `any` value

let backend;
try {
backend = await gcp.getBackend(projectId, location, backendId);
populateTable(backend, table);
} catch (err: any) {

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

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
throw new FirebaseError(`No backends found with given parameters. Command aborted.`, {
original: err,

Check warning on line 57 in src/commands/frameworks-backends-delete.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value
});
}

utils.logWarning("You are about to permanently delete the backend:");
logger.info(table.toString());

Check warning on line 62 in src/commands/frameworks-backends-delete.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 62 in src/commands/frameworks-backends-delete.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .toString on an `any` value

const confirmDeletion = await promptOnce(
{
type: "confirm",
name: "force",
default: false,
message: "You are about to delete the backend with id: " + backendId + "\n Are you sure?",
message: "Are you sure?",
},
options
);
if (!confirmDeletion) {
throw new FirebaseError("Deletion aborted.");
throw new FirebaseError("Deletion Aborted");
}

try {
Expand All @@ -40,4 +83,27 @@
{ original: err }
);
}

return backend;
});

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