mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-29 05:34:21 +08:00
- Update yargs to 16.1.1 - Update @rollup/plugin-commonjs to 17.0.0 - Update @types/codemirror to 0.0.100 - Update Puppeteer to 5.5.0 - Update Rollup to 2.34.0 DISABLE_THIRD_PARTY_CHECK=NPM update R=jacktfranklin@chromium.org Change-Id: Ie3ed95b7c83ec615122643769ff5c53ac4111c09 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2567910 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
33 lines
1.0 KiB
JavaScript
33 lines
1.0 KiB
JavaScript
export function parseCommand(cmd) {
|
|
const extraSpacesStrippedCommand = cmd.replace(/\s{2,}/g, ' ');
|
|
const splitCommand = extraSpacesStrippedCommand.split(/\s+(?![^[]*]|[^<]*>)/);
|
|
const bregex = /\.*[\][<>]/g;
|
|
const firstCommand = splitCommand.shift();
|
|
if (!firstCommand)
|
|
throw new Error(`No command found in: ${cmd}`);
|
|
const parsedCommand = {
|
|
cmd: firstCommand.replace(bregex, ''),
|
|
demanded: [],
|
|
optional: [],
|
|
};
|
|
splitCommand.forEach((cmd, i) => {
|
|
let variadic = false;
|
|
cmd = cmd.replace(/\s/g, '');
|
|
if (/\.+[\]>]/.test(cmd) && i === splitCommand.length - 1)
|
|
variadic = true;
|
|
if (/^\[/.test(cmd)) {
|
|
parsedCommand.optional.push({
|
|
cmd: cmd.replace(bregex, '').split('|'),
|
|
variadic,
|
|
});
|
|
}
|
|
else {
|
|
parsedCommand.demanded.push({
|
|
cmd: cmd.replace(bregex, '').split('|'),
|
|
variadic,
|
|
});
|
|
}
|
|
});
|
|
return parsedCommand;
|
|
}
|