From fe167b604bac6f9e77d70e6dd13d6bb826e8295b Mon Sep 17 00:00:00 2001 From: iapyang Date: Wed, 6 Jul 2022 20:42:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E4=B8=8Bbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/cli/cli.js | 10 ++++++---- bin/cli/worker/cli.worker.js | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bin/cli/cli.js b/bin/cli/cli.js index 7921da776..732fc1133 100644 --- a/bin/cli/cli.js +++ b/bin/cli/cli.js @@ -15,7 +15,7 @@ function getArgs (startIndex = 1) { args[longArgFlag] = longArgValue; // flags } else if (arg[0] === '-') { - const flags = arg.slice(1, arg.length).split(''); + const flags = arg.slice(1, arg.length); args[flags] = true; } }); @@ -27,10 +27,12 @@ const cmds = new Map([ ['worker', workerCmd], ]); -const startIndex = process.argv.findIndex(argv => argv === 'fui-cli'); +const baseCmd = 'fui-cli'; + +const startIndex = process.argv.findIndex(argv => argv.indexOf(baseCmd) !== -1); if (startIndex === -1) { - throw new Error('commad not found'); + throw new Error(`Command ${baseCmd} not found in args`); } const cmd = process.argv[startIndex + 1]; @@ -38,5 +40,5 @@ const cmd = process.argv[startIndex + 1]; if (cmds.has(cmd)) { cmds.get(cmd)?.exec(getArgs(startIndex + 2)); } else { - throw new Error('命令不存在'); + throw new Error(`Command ${cmd} not supported`); } diff --git a/bin/cli/worker/cli.worker.js b/bin/cli/worker/cli.worker.js index 13ad48a5d..0c086db08 100644 --- a/bin/cli/worker/cli.worker.js +++ b/bin/cli/worker/cli.worker.js @@ -21,11 +21,11 @@ function scanAndCreate(structure, root = process.cwd()) { module.exports = { exec: async args => { if (!args.init) { - throw new Error('command not found'); + throw new Error(`Command init not found in args`); } if (!args.name) { - throw new Error('fileName not found'); + throw new Error('Command --name=... not found in args'); } const name = args.name;