Skip to content
Myr

command.js

This file

Path

lib/methods/command.js

25 lines · 953 bytes · JavaScript

Last changed by

Upgrade xo (#980)ehmickybefore adoptionccfa412

History of this file

Take it

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 1–2why, one step back
1export const mapCommandAsync = ({file, commandArguments}) => parseCommand(file, commandArguments);
2export const mapCommandSync = ({file, commandArguments}) => ({...parseCommand(file, commandArguments), isSync: true});

Rename files (#977)ehmickybefore adoption4b2e316

line 3why, one step back
3

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 4–6why, one step back
4const parseCommand = (command, unusedArguments) => {
5 if (unusedArguments.length > 0) {6 throw new TypeError(`The command and its arguments must be passed as a single string: ${command} ${unusedArguments}.`);

Rename files (#977)ehmickybefore adoption4b2e316

lines 7–20why, one step back
7 }
89 const tokens = [];10 for (const token of command.trim().split(SPACES_REGEXP)) {11 // Allow spaces to be escaped by a backslash if not meant as a delimiter12 const previousToken = tokens.at(-1);13 if (previousToken && previousToken.endsWith('\\')) {14 // Merge previous token with current one15 tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;16 } else {17 tokens.push(token);18 }19 }20

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 21–22why, one step back
21 const [file, ...commandArguments] = tokens;
22 return {file, commandArguments};

Rename files (#977)ehmickybefore adoption4b2e316

lines 23–25why, one step back
23};
2425const SPACES_REGEXP = / +/g;