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 input option #15

Closed
wants to merge 4 commits into from
Closed

Conversation

jamestalmage
Copy link
Contributor

@jamestalmage jamestalmage commented Apr 22, 2016

Fixes #12.

None of the new tests are setup to run on Windows. Is there a cross platform command I can execute that will work well on Travis and AppVeyor?

@kevva
Copy link
Contributor

kevva commented Apr 22, 2016

Lol #16.

@sindresorhus
Copy link
Owner

Lol, this is scary close: 🐐

screen shot 2016-04-23 at 05 25 36

// @kevva

@kevva kevva mentioned this pull request Apr 22, 2016
@kevva
Copy link
Contributor

kevva commented Apr 22, 2016

This has better tests and account for streaming too so 👍 on this.

@jamestalmage, you should add the stdin fixture from my PR though.

input.pipe(spawned.stdin);
} else {
spawned.stdin.write(input);
spawned.stdin.end();
Copy link
Owner

Choose a reason for hiding this comment

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

You can pass input directly to .end()

@sindresorhus
Copy link
Owner

sindresorhus commented Apr 22, 2016

Re fixture, maybe improve it to be:

#!/usr/bin/env node
'use strict';
process.stdin.pipe(process.stdout);

@sindresorhus sindresorhus changed the title allow opts.input to specify stdin contents add input option Apr 22, 2016
@@ -116,6 +134,9 @@ module.exports.spawn = function (cmd, args, opts) {
};

module.exports.sync = function (cmd, args, opts) {
if (opts && isStream(opts.input)) {
throw new TypeError('opts.input can not be a stream in sync mode');
Copy link
Owner

Choose a reason for hiding this comment

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

throw new TypeError('The `input` option cannot be a stream in sync mode');

@@ -116,6 +133,9 @@ module.exports.spawn = function (cmd, args, opts) {
};

module.exports.sync = function (cmd, args, opts) {
if (opts && isStream(opts.input)) {
throw new TypeError('The `input` option cannot be a stream in sync mode');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just nitpicking here, but an extra line break here :).

@jamestalmage
Copy link
Contributor Author

Updated.

input.pipe(spawned.stdin);
} else {
spawned.stdin.end(input);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Also nitpicking:

if (isStream(input)) {
    input.pipe(spawned.stdin);
    return;
}

spawned.stdin.end(input);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. Is there value to that though? I am all for preferring return over nesting some huge else block, but for a short one liner, I think if/else is more readable.

Depending on what we decide, we could make XO catch this one pretty easy.

Copy link
Contributor

@kevva kevva Apr 23, 2016

Choose a reason for hiding this comment

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

Nah, I guess it's a personal preference. If I can, I skip else and return early instead. To me at least, it's somewhat clearer.

May be some value to consistently return as early as possible too rather than doing things differently depending on how deeply nested your if statements are.

Copy link
Owner

Choose a reason for hiding this comment

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

@kevva Open an issue on https://github.com/sindresorhus/eslint-plugin-xo and we can discuss.

sindresorhus pushed a commit that referenced this pull request Apr 23, 2016
Fixes #12.

None of the new tests are setup to run on Windows. Is there a cross platform command I can execute that will work well on Travis and AppVeyor?

Closes #15
@sindresorhus
Copy link
Owner

Yay. Thanks James! This is going to make my CLI tests a lot nicer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants