forked from fanruan/fineui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.0 KiB
42 lines
1.0 KiB
#!/usr/bin/env node |
|
|
|
const workerCmd = require('./worker/cli.worker'); |
|
|
|
function getArgs (startIndex = 1) { |
|
const args = {}; |
|
process.argv |
|
.slice(startIndex, process.argv.length) |
|
.forEach(arg => { |
|
// long arg |
|
if (arg.slice(0, 2) === '--') { |
|
const longArg = arg.split('='); |
|
const longArgFlag = longArg[0].slice(2, longArg[0].length); |
|
const longArgValue = longArg.length > 1 ? longArg[1] : true; |
|
args[longArgFlag] = longArgValue; |
|
// flags |
|
} else if (arg[0] === '-') { |
|
const flags = arg.slice(1, arg.length).split(''); |
|
args[flags] = true; |
|
} |
|
}); |
|
|
|
return args; |
|
} |
|
|
|
const cmds = new Map([ |
|
['worker', workerCmd], |
|
]); |
|
|
|
const startIndex = process.argv.findIndex(argv => argv === 'fui-cli'); |
|
|
|
if (startIndex === -1) { |
|
throw new Error('commad not found'); |
|
} |
|
|
|
const cmd = process.argv[startIndex + 1]; |
|
|
|
if (cmds.has(cmd)) { |
|
cmds.get(cmd)?.exec(getArgs(startIndex + 2)); |
|
} else { |
|
throw new Error('命令不存在'); |
|
}
|
|
|