-
-
Notifications
You must be signed in to change notification settings - Fork 207
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
add input
option
#15
Conversation
Lol #16. |
Lol, this is scary close: 🐐 // @kevva |
This has better tests and account for streaming too so 👍 on this. @jamestalmage, you should add the |
input.pipe(spawned.stdin); | ||
} else { | ||
spawned.stdin.write(input); | ||
spawned.stdin.end(); |
There was a problem hiding this comment.
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()
Re fixture, maybe improve it to be: #!/usr/bin/env node
'use strict';
process.stdin.pipe(process.stdout); |
input
option
@@ -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'); |
There was a problem hiding this comment.
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'); | |||
} |
There was a problem hiding this comment.
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 :).
Updated. |
input.pipe(spawned.stdin); | ||
} else { | ||
spawned.stdin.end(input); | ||
} |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Yay. Thanks James! This is going to make my CLI tests a lot nicer. |
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?