Skip to content

Commit

Permalink
Breaking: Use capital letters for aliases in --silent and --log-level
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Dec 21, 2017
1 parent b14cfd9 commit c0fd2f1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
13 changes: 7 additions & 6 deletions lib/shared/cliOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {
'even when color support is detected.'),
},
silent: {
alias: 's',
alias: 'S',
type: 'boolean',
desc: chalk.gray(
'Suppress all gulp logging.'),
Expand All @@ -81,12 +81,13 @@ module.exports = {
desc: chalk.gray(
'Continue execution of tasks upon failure.'),
},
loglevel: {
alias: 'l',
type: 'boolean',
'log-level': {
alias: 'L',
// Type isn't needed because count acts as a boolean
count: true,
// Can't use `default` because it seems to be off by one
desc: chalk.gray(
'Set the loglevel. -l for least verbose and -llll for most verbose.' +
' -lll is default.'),
'Set the loglevel. -L for least verbose and -LLLL for most verbose.' +
' -LLL is default.'),
},
};
19 changes: 10 additions & 9 deletions lib/shared/log/toConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@

var fancyLog = require('fancy-log');

function noop() {}

// The sorting of the levels is
// significant.
var levels = [
'error', // -l: Logs error events.
'warn', // -ll: Logs warn and error events.
'info', // -lll: Logs info, warn and error events.
'debug', // -llll: Logs all log levels.
'error', // -L: Logs error events.
'warn', // -LL: Logs warn and error events.
'info', // -LLL: Logs info, warn and error events.
'debug', // -LLLL: Logs all log levels.
];

function toConsole(log, opts) {
// Return immediately if logging is
// not desired.
if (opts.tasksSimple || opts.silent) {
// Keep from crashing process when silent.
log.on('error', noop);
return;
}

// For some reason yargs sets
// the default count for opts.loglevel to 2
// instead of 0 when we configure count: true
// in the cliOptions.
var loglevel = (opts.loglevel > 2) ? opts.loglevel - 2 : 3;
// Default loglevel to info level (3).
var loglevel = opts.logLevel || 3;

levels
.filter(function(item, i) {
Expand Down
18 changes: 9 additions & 9 deletions test/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ var code = require('code');
var child = require('child_process');

lab.experiment('logging', function() {
lab.test('log-level flag for debug: -llll', function(done) {
child.exec('node ' + __dirname + '/fixtures/logging.js -llll', function(err, stdout, stderr) {
lab.test('log-level flag for debug: -LLLL', function(done) {
child.exec('node ' + __dirname + '/fixtures/logging.js -LLLL', function(err, stdout, stderr) {
stdout = stdout.replace(/\\/g, '/').split('\n');
code.expect(stdout[0]).to.contain('test debug');
code.expect(stdout[1]).to.contain('test info');
Expand All @@ -16,7 +16,7 @@ lab.experiment('logging', function() {
});
});

lab.test('no log-level flag: defaults to -lll', function(done) {
lab.test('no log-level flag: defaults to -LLL', function(done) {
child.exec('node ' + __dirname + '/fixtures/logging.js', function(err, stdout, stderr) {
stdout = stdout.replace(/\\/g, '/').split('\n');
code.expect(stdout[0]).to.contain('test info');
Expand All @@ -26,8 +26,8 @@ lab.experiment('logging', function() {
});
});

lab.test('log-level flag for info: -lll', function(done) {
child.exec('node ' + __dirname + '/fixtures/logging.js -lll', function(err, stdout, stderr) {
lab.test('log-level flag for info: -LLL', function(done) {
child.exec('node ' + __dirname + '/fixtures/logging.js -LLL', function(err, stdout, stderr) {
stdout = stdout.replace(/\\/g, '/').split('\n');
code.expect(stdout[0]).to.contain('test info');
code.expect(stdout[1]).to.contain('test warn');
Expand All @@ -36,17 +36,17 @@ lab.experiment('logging', function() {
});
});

lab.test('log-level flag for warn: -ll', function(done) {
child.exec('node ' + __dirname + '/fixtures/logging.js -ll', function(err, stdout, stderr) {
lab.test('log-level flag for warn: -LL', function(done) {
child.exec('node ' + __dirname + '/fixtures/logging.js -LL', function(err, stdout, stderr) {
stdout = stdout.replace(/\\/g, '/').split('\n');
code.expect(stdout[0]).to.contain('test warn');
code.expect(stderr).to.contain('test error');
done(err);
});
});

lab.test('log-level flag for error: -l', function(done) {
child.exec('node ' + __dirname + '/fixtures/logging.js -l', function(err, stdout, stderr) {
lab.test('log-level flag for error: -L', function(done) {
child.exec('node ' + __dirname + '/fixtures/logging.js -L', function(err, stdout, stderr) {
code.expect(stderr).to.contain('test error');
done(err);
});
Expand Down

0 comments on commit c0fd2f1

Please sign in to comment.