Skip to content

Commit

Permalink
fix(core): handle positional args correctly for run command
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Feb 23, 2023
1 parent cbf33c4 commit 35f665b
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions packages/nx/bin/init-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,35 @@ export function rewriteTargetsAndProjects(args: string[]) {
}

function rewritePositionalArguments(args: string[]) {
if (!args[3] || args[3].startsWith('-')) {
return ['run', `${wrapIntoQuotesIfNeeded(args[2])}`, ...args.slice(3)];
} else {
const relevantPositionalArgs = [];
const rest = [];
for (let i = 2; i < args.length; i++) {
if (!args[i].startsWith('-')) {
relevantPositionalArgs.push(args[i]);
if (relevantPositionalArgs.length === 2) {
rest.push(...args.slice(i + 1));
break;
}
} else {
rest.push(args[i]);
}
}

if (relevantPositionalArgs.length === 1) {
return [
'run',
`${args[3]}:${wrapIntoQuotesIfNeeded(args[2])}`,
...args.slice(4),
`${wrapIntoQuotesIfNeeded(relevantPositionalArgs[0])}`,
...rest,
];
}

return [
'run',
`${relevantPositionalArgs[1]}:${wrapIntoQuotesIfNeeded(
relevantPositionalArgs[0]
)}`,
...rest,
];
}

function wrapIntoQuotesIfNeeded(arg: string) {
Expand Down

0 comments on commit 35f665b

Please sign in to comment.