Skip to content

Commit

Permalink
Change the format string syntax into {index} from $index.
Browse files Browse the repository at this point in the history
  • Loading branch information
robario committed Jun 15, 2016
1 parent 74f720e commit 09e7c1e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/bin/common/parse-cli-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ class ArgumentSet {
function parseCLIArgsCore(set, args) { // eslint-disable-line complexity
const terminator = args.indexOf("--");
if (terminator !== -1) {
set.rest = args.slice(terminator).map(arg => `"${arg.replace(/(^|[^\\])"/g, "$1\\\"")}"`);
set.rest[0] = set.rest.slice(1).join(" ");
set.rest = args.slice(terminator);
args = args.slice(0, terminator); // eslint-disable-line no-param-reassign
}
for (let i = 0; i < args.length; ++i) {
Expand Down
16 changes: 13 additions & 3 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//------------------------------------------------------------------------------

const Promise = require("pinkie-promise");
const shellQuote = require("shell-quote");
const matchTasks = require("./match-tasks");
const readPackageJson = require("./read-package-json");
const runTasksInParallel = require("./run-tasks-in-parallel");
Expand Down Expand Up @@ -162,9 +163,18 @@ module.exports = function npmRunAll(
}

for (let i = 0, len = patterns.length; i < len; ++i) {
patterns[i] = patterns[i].replace(/[$](\d+)(?=\s|$)/g, ($0, $1) => {
const pos = parseInt($1, 10);
return pos >= 0 && pos < rest.length ? rest[pos] : "";
patterns[i] = patterns[i].replace(/[{]([*@]|\d+)[}]/g, (match, index) => {
if (index === "@") {
return shellQuote.quote(rest.slice(1));
}
if (index === "*") {
return shellQuote.quote([rest.slice(1).join(" ")]).replace(/^"|"$/g, '');
}
const position = parseInt(index, 10);
if (position >= 0 && position < rest.length) {
return shellQuote.quote([rest[position]]);
}
return match;
});
}

Expand Down

0 comments on commit 09e7c1e

Please sign in to comment.