mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: cli: allow calling with Arg::ObjectId
This commit is contained in:
1 parent
e5c959dc28
commit
260261fcfe
2 files changed
+8
-8
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
/* eslint-disable import/no-dynamic-require */
|
/* eslint-disable import/no-dynamic-require */
|
||||||
import { argv } from 'yargs';
|
import { argv } from 'yargs';
|
||||||
|
import { ObjectID } from 'mongodb';
|
||||||
import {
|
import {
|
||||||
lib, service, model,
|
lib, service, model,
|
||||||
builtinLib, builtinModel,
|
builtinLib, builtinModel,
|
||||||
@@ -21,7 +22,7 @@ function parseParameters(fn: Function) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function cli() {
|
async function cli() {
|
||||||
const [, modelName, func, ...args] = argv._;
|
const [, modelName, func, ...args] = argv._ as [string, string, string, ...any[]];
|
||||||
if (!global.Hydro.model[modelName]) {
|
if (!global.Hydro.model[modelName]) {
|
||||||
return console.error(`Model ${modelName} doesn't exist.`);
|
return console.error(`Model ${modelName} doesn't exist.`);
|
||||||
}
|
}
|
||||||
@@ -45,6 +46,11 @@ async function cli() {
|
|||||||
console.error(`Too few arguments. Min ${parameterMin}`);
|
console.error(`Too few arguments. Min ${parameterMin}`);
|
||||||
return console.error(parameters.join(', '));
|
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);
|
let result = global.Hydro.model[modelName][func](...args);
|
||||||
if (result instanceof Promise) result = await result;
|
if (result instanceof Promise) result = await result;
|
||||||
return console.log(result);
|
return console.log(result);
|
||||||
|
|||||||
@@ -75,16 +75,10 @@ export async function load(call: Entry) {
|
|||||||
while (dbVer < expected) {
|
while (dbVer < expected) {
|
||||||
logger.info('Upgrading database: from %d to %d', dbVer, expected);
|
logger.info('Upgrading database: from %d to %d', dbVer, expected);
|
||||||
const func = scripts[dbVer];
|
const func = scripts[dbVer];
|
||||||
if (typeof func !== 'function') {
|
if (typeof func !== 'function' || (isFresh && func.toString().includes('_FRESH_INSTALL_IGNORE'))) {
|
||||||
dbVer++;
|
dbVer++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isFresh) {
|
|
||||||
if (func.toString().includes('_FRESH_INSTALL_IGNORE')) {
|
|
||||||
dbVer++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const result = await func();
|
const result = await func();
|
||||||
if (!result) break;
|
if (!result) break;
|
||||||
dbVer++;
|
dbVer++;
|
||||||
|
|||||||
Reference in new issue
Block a user