Skip to content

Commit

Permalink
Fix command- syntax capturing for --success (#325)
Browse files Browse the repository at this point in the history
Co-authored-by: Gustavo Henke <guhenke@gmail.com>
  • Loading branch information
paescuj and gustavohenke committed May 22, 2022
1 parent 6f1e11d commit ecbc325
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/completion-listener.ts
Expand Up @@ -43,15 +43,18 @@ export class CompletionListener {
return events[0].exitCode === 0;
} else if (this.successCondition === 'last') {
return events[events.length - 1].exitCode === 0;
} else if (!/^!?command-.+$/.test(this.successCondition)) {
}

const commandSyntaxMatch = this.successCondition.match(/^!?command-(.+)$/);
if (commandSyntaxMatch == null) {
// If not a `command-` syntax, then it's an 'all' condition or it's treated as such.
return events.every(({ exitCode }) => exitCode === 0);
}

// Check `command-` syntax condition.
// Note that a command's `name` is not necessarily unique,
// in which case all of them must meet the success condition.
const [, nameOrIndex] = this.successCondition.split('-');
const nameOrIndex = commandSyntaxMatch[1];
const targetCommandsEvents = events.filter(({ command, index }) => (
command.name === nameOrIndex
|| index === Number(nameOrIndex)
Expand Down

0 comments on commit ecbc325

Please sign in to comment.