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.
44 lines
1.1 KiB
44 lines
1.1 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); |
|
args[flags] = true; |
|
} |
|
}); |
|
|
|
return args; |
|
} |
|
|
|
const cmds = new Map([ |
|
['worker', workerCmd], |
|
]); |
|
|
|
const baseCmd = 'fui-cli'; |
|
|
|
const startIndex = process.argv.findIndex(argv => argv.indexOf(baseCmd) !== -1); |
|
|
|
if (startIndex === -1) { |
|
throw new Error(`Command ${baseCmd} not found in args`); |
|
} |
|
|
|
const cmd = process.argv[startIndex + 1]; |
|
|
|
if (cmds.has(cmd)) { |
|
cmds.get(cmd)?.exec(getArgs(startIndex + 2)); |
|
} else { |
|
throw new Error(`Command ${cmd} not supported`); |
|
}
|
|
|