refactor: use a util for script exec

This commit is contained in:
zkldi
2022-07-17 16:17:51 +01:00
parent c25ad6345a
commit b6003f7e87
13 changed files with 71 additions and 113 deletions
+3 -18
View File
@@ -4,6 +4,7 @@ import { Command } from "commander";
import { monkDB } from "external/mongo/db";
import { DatabaseSchemas } from "external/mongo/schemas";
import CreateLogCtx from "lib/logger/logger";
import { WrapScriptPromise } from "utils/misc";
import { FormatPrError } from "utils/prudence";
import type { Databases } from "external/mongo/db";
import type { FindResult } from "monk";
@@ -64,24 +65,8 @@ export async function ValidateAllCollections() {
if (require.main === module) {
if (typeof options.collection === "string") {
// @hack This should be typechecked and warned about outside of ValidateCollection.
ValidateCollection(options.collection as Databases)
.then(() => process.exit(0))
.catch((err: unknown) => {
logger.error(
`Failed to validate collection ${options.collection}?`,
{ err },
() => {
process.exit(1);
}
);
});
WrapScriptPromise(ValidateCollection(options.collection as Databases), logger);
} else {
ValidateAllCollections()
.then(() => process.exit(0))
.catch((err: unknown) => {
logger.error(`Failed to validate all collections?`, { err }, () => {
process.exit(1);
});
});
WrapScriptPromise(ValidateAllCollections(), logger);
}
}