Skip to content
Myr

command.js

This file

Path

lib/methods/command.js

25 lines · 866 bytes · JavaScript

Last changed by

Rename files (#977)ehmickybefore adoption4b2e316

History of this file

Take it

Rename files (#977)ehmickybefore adoption4b2e316

lines 1–25why, one step back
1export const mapCommandAsync = ({file, args}) => parseCommand(file, args);
2export const mapCommandSync = ({file, args}) => ({...parseCommand(file, args), isSync: true});34const parseCommand = (command, unusedArgs) => {5 if (unusedArgs.length > 0) {6 throw new TypeError(`The command and its arguments must be passed as a single string: ${command} ${unusedArgs}.`);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 }2021 const [file, ...args] = tokens;22 return {file, args};23};2425const SPACES_REGEXP = / +/g;