Skip to content

Commit

Permalink
Merge 04039a9 into 08eda4f
Browse files Browse the repository at this point in the history
  • Loading branch information
firoxer committed Oct 2, 2021
2 parents 08eda4f + 04039a9 commit 6874cf5
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
10 changes: 9 additions & 1 deletion bin/concurrently.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ const args = yargs
describe: 'Disables colors from logging',
type: 'boolean'
},
'hide': {
describe:
'Comma-separated list of processes to hide the output.\n' +
'The processes can be identified by their name or index.',
default: defaults.hide,
type: 'string'
},

// Kill others
'k': {
Expand Down Expand Up @@ -135,7 +142,7 @@ const args = yargs
'Can be either the index or the name of the process.'
}
})
.group(['m', 'n', 'name-separator', 'raw', 's', 'no-color'], 'General')
.group(['m', 'n', 'name-separator', 'raw', 's', 'no-color', 'h'], 'General')
.group(['p', 'c', 'l', 't'], 'Prefix styling')
.group(['i', 'default-input-target'], 'Input handling')
.group(['k', 'kill-others-on-fail'], 'Killing other processes')
Expand All @@ -157,6 +164,7 @@ concurrently(args._.map((command, index) => ({
: (args.killOthersOnFail ? ['failure'] : []),
maxProcesses: args.maxProcesses,
raw: args.raw,
hide: args.hide.split(','),
prefix: args.prefix,
prefixColors: args.prefixColors.split(','),
prefixLength: args.prefixLength,
Expand Down
20 changes: 20 additions & 0 deletions bin/concurrently.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ describe('--raw', () => {
});
});

describe('--hide', () => {
it('hides the output of a process by its index', done => {
const child = run('--hide 1 "echo foo" "echo bar"');
child.log.pipe(buffer(child.close)).subscribe(lines => {
expect(lines).toContainEqual(expect.stringContaining('foo'));
expect(lines).not.toContainEqual(expect.stringContaining('bar'));
done();
}, done);
});

it('hides the output of a process by its name', done => {
const child = run('-n foo,bar --hide bar "echo foo" "echo bar"');
child.log.pipe(buffer(child.close)).subscribe(lines => {
expect(lines).toContainEqual(expect.stringContaining('foo'));
expect(lines).not.toContainEqual(expect.stringContaining('bar'));
done();
}, done);
});
});

describe('--names', () => {
it('is aliased to -n', done => {
const child = run('-n foo,bar "echo foo" "echo bar"');
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Logger = require('./src/logger');

module.exports = exports = (commands, options = {}) => {
const logger = new Logger({
hide: options.hide,
outputStream: options.outputStream || process.stdout,
prefixFormat: options.prefix,
prefixLength: options.prefixLength,
Expand Down
2 changes: 2 additions & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports = {
handleInput: false,
// How many processes to run at once
maxProcesses: 0,
// Indices and names of commands whose output to be not logged
hide: '',
nameSeparator: ',',
// Which prefix style to use when logging processes output.
prefix: '',
Expand Down
10 changes: 9 additions & 1 deletion src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ const formatDate = require('date-fns/format');
const defaults = require('./defaults');

module.exports = class Logger {
constructor({ outputStream, prefixFormat, prefixLength, raw, timestampFormat }) {
constructor({ hide, outputStream, prefixFormat, prefixLength, raw, timestampFormat }) {
// To avoid empty strings from hiding the output of commands that don't have a name,
// keep in the list of commands to hide only strings with some length.
// This might happen through the CLI when no `--hide` argument is specified, for example.
this.hide = _.castArray(hide).filter(name => name || name === 0).map(String);
this.raw = raw;
this.outputStream = outputStream;
this.prefixFormat = prefixFormat;
Expand Down Expand Up @@ -76,6 +80,10 @@ module.exports = class Logger {
}

logCommandText(text, command) {
if (this.hide.includes(String(command.index)) || this.hide.includes(command.name)) {
return;
}

const prefix = this.colorText(command, this.getPrefix(command));
return this.log(prefix + (prefix ? ' ' : ''), text);
}
Expand Down
28 changes: 28 additions & 0 deletions src/logger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ describe('#logCommandText()', () => {

expect(logger.log).toHaveBeenCalledWith(chalk.hex(prefixColor)('[1]') + ' ', 'foo');
});

it('does nothing if command is hidden by name', () => {
const logger = createLogger({ hide: ['abc'] });
logger.logCommandText('foo', { name: 'abc' });

expect(logger.log).not.toHaveBeenCalled();
});

it('does nothing if command is hidden by index', () => {
const logger = createLogger({ hide: [3] });
logger.logCommandText('foo', { index: 3 });

expect(logger.log).not.toHaveBeenCalled();
});
});

describe('#logCommandEvent()', () => {
Expand All @@ -186,6 +200,20 @@ describe('#logCommandEvent()', () => {
expect(logger.log).not.toHaveBeenCalled();
});

it('does nothing if command is hidden by name', () => {
const logger = createLogger({ hide: ['abc'] });
logger.logCommandEvent('foo', { name: 'abc' });

expect(logger.log).not.toHaveBeenCalled();
});

it('does nothing if command is hidden by index', () => {
const logger = createLogger({ hide: [3] });
logger.logCommandEvent('foo', { index: 3 });

expect(logger.log).not.toHaveBeenCalled();
});

it('logs text in gray dim', () => {
const logger = createLogger();
logger.logCommandEvent('foo', { index: 1 });
Expand Down

0 comments on commit 6874cf5

Please sign in to comment.