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

WIP - Add ability to merge output #79

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
20 changes: 18 additions & 2 deletions src/main.js
Expand Up @@ -45,7 +45,10 @@ var config = {
color: true,

// If true, the output will only be raw output of processes, nothing more
raw: false
raw: false,

// If true, the output will be grouped together for each command
group: false
};

function main() {
Expand Down Expand Up @@ -121,6 +124,12 @@ function parseArgs() {
'The option can be used to shorten long commands.\n' +
'Works only if prefix is set to "command". Default: ' +
config.prefixLength + '\n'
)
.option(
'-g, --group',
'group the output written to stdout and stderr by each command.\n' +
'Default: ' +
config.group + '\n'
);

program.on('--help', function() {
Expand Down Expand Up @@ -246,9 +255,16 @@ function run(commands) {
});
}

function combineSourceStreams(context, sourceStreams, shouldGroupOutput) {
if (shouldGroupOutput) {
return Rx.Observable.concat.apply(this, sourceStreams);
}
return Rx.Observable.merge.apply(this, sourceStreams);
}

function handleOutput(streams, childrenInfo, source) {
var sourceStreams = _.map(streams, source);
var combinedSourceStream = Rx.Observable.merge.apply(this, sourceStreams);
var combinedSourceStream = combineSourceStreams(this, sourceStreams, config.group);
Copy link
Author

Choose a reason for hiding this comment

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

Though the config is available as a global, I chose to pass it as a parameter to this new function. I prefer this style, but I'm open to changing it

Copy link
Member

Choose a reason for hiding this comment

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

It's okay :)


combinedSourceStream.subscribe(function(event) {
var prefix = getPrefix(childrenInfo, event.child);
Expand Down