core: cli: allow calling with Arg::ObjectId

This commit is contained in:
undefined committed 2021-04-12 22:32:57 +08:00
1 parent e5c959dc28
commit 260261fcfe
2 files changed
+8 -8

No files matched your search

+7 -1
View File
@@ -1,6 +1,7 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable import/no-dynamic-require */
import { argv } from 'yargs';
import { ObjectID } from 'mongodb';
import {
lib, service, model,
builtinLib, builtinModel,
@@ -21,7 +22,7 @@ function parseParameters(fn: Function) {
}
async function cli() {
const [, modelName, func, ...args] = argv._;
const [, modelName, func, ...args] = argv._ as [string, string, string, ...any[]];
if (!global.Hydro.model[modelName]) {
return console.error(`Model ${modelName} doesn't exist.`);
}
@@ -45,6 +46,11 @@ async function cli() {
console.error(`Too few arguments. Min ${parameterMin}`);
return console.error(parameters.join(', '));
}
for (let i = 0; i < args.length; i++) {
if (ObjectID.isValid(args[i])) {
args[i] = new ObjectID(args[i]);
}
}
let result = global.Hydro.model[modelName][func](...args);
if (result instanceof Promise) result = await result;
return console.log(result);
+1 -7
View File
@@ -75,16 +75,10 @@ export async function load(call: Entry) {
while (dbVer < expected) {
logger.info('Upgrading database: from %d to %d', dbVer, expected);
const func = scripts[dbVer];
if (typeof func !== 'function') {
if (typeof func !== 'function' || (isFresh && func.toString().includes('_FRESH_INSTALL_IGNORE'))) {
dbVer++;
continue;
}
if (isFresh) {
if (func.toString().includes('_FRESH_INSTALL_IGNORE')) {
dbVer++;
continue;
}
}
const result = await func();
if (!result) break;
dbVer++;