Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allowNonzeroExitCode option #176

Merged
merged 7 commits into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference types="node"/>
import {ChildProcess} from 'child_process';
import { ChildProcess } from "child_process";
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved

declare namespace open {
interface Options {
Expand Down Expand Up @@ -42,6 +42,15 @@ declare namespace open {
@default false
*/
readonly url?: boolean;

/**
Option to allow the opened app resolve the promise with nonzero exit code when `wait` option value `true`.
peterchu999 marked this conversation as resolved.
Show resolved Hide resolved

We do not recommend using it because by default the app convention for success exit code was 0.
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved

@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 @@ -28,6 +28,7 @@ module.exports = async (target, options) => {
wait: false,
background: false,
url: false,
allowNonzeroExitCode: false,
...options
};

Expand Down Expand Up @@ -147,7 +148,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
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ 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`

Option to allow the opened app resolve the promise with nonzero exit code when `wait` option value `true`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The readme docs should be in sync with the index.d.ts. The text here is different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so sorry i miss the README

We do not recommend using it because by default the app convention for success exit code was 0.

## Caveats

### Double-quotes on Windows
Expand Down