Skip to content

Commit

Permalink
Add allowNonzeroExitCode option (#176)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
peterchu999 and sindresorhus committed Jul 19, 2020
1 parent 72d9ddb commit e009765
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ declare namespace open {
@default false
*/
readonly url?: boolean;

/**
Allow the opened app to exit with nonzero exit code when the `wait` option is `true`.
We do not recommend setting this option. The convention for success is exit code zero.
@default false
*/
readonly allowNonzeroExitCode?: boolean;
}
}

Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = async (target, options) => {
wait: false,
background: false,
url: false,
allowNonzeroExitCode: false,
...options
};

Expand Down Expand Up @@ -148,7 +149,7 @@ module.exports = async (target, options) => {
subprocess.once('error', reject);

subprocess.once('close', exitCode => {
if (exitCode > 0) {
if (options.allowNonzeroExitCode && exitCode > 0) {
reject(new Error(`Exited with code ${exitCode}`));
return;
}
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ We do not recommend using it on targets that are not URLs.

Especially useful when dealing with the [double-quotes on Windows](#double-quotes-on-windows) caveat.

##### allowNonzeroExitCode

Type: `boolean`\
Default: `false`

Allow the opened app to exit with nonzero exit code when the `wait` option is `true`.

We do not recommend setting this option. The convention for success is exit code zero.

## Caveats

### Double-quotes on Windows
Expand Down

0 comments on commit e009765

Please sign in to comment.