From 4b4660b789cd6fa628f21b11c9c2c94ee980860d Mon Sep 17 00:00:00 2001 From: undefined Date: Thu, 26 Oct 2023 23:07:34 +0800 Subject: [PATCH] core: support #677 --- packages/hydrooj/src/entry/cli.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/hydrooj/src/entry/cli.ts b/packages/hydrooj/src/entry/cli.ts index c40e3053..da145cc1 100644 --- a/packages/hydrooj/src/entry/cli.ts +++ b/packages/hydrooj/src/entry/cli.ts @@ -73,6 +73,17 @@ async function cli() { args[i] = +args[i]; } else if (args[i].startsWith('~')) { args[i] = argv.options[args[i].substr(1)]; + } else if ((args[i].startsWith('[') && args[i].endsWith(']')) || (args[i].startsWith('{') && args[i].endsWith('}'))) { + try { + args[i] = JSON.parse(args[i]); + for (const key in args[i]) { + if (typeof args[i][key] === 'string' && ObjectId.isValid(args[i][key])) { + args[i][key] = new ObjectId(args[i][key]); + } + } + } catch (e) { + console.error(`Cannot parse argument at position ${i}`); + } } } let result = global.Hydro.model[modelName][func](...args);