Skip to content

Commit c0fd2f1

Browse files
committed
Breaking: Use capital letters for aliases in --silent and --log-level
1 parent b14cfd9 commit c0fd2f1

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

lib/shared/cliOptions.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = {
7171
'even when color support is detected.'),
7272
},
7373
silent: {
74-
alias: 's',
74+
alias: 'S',
7575
type: 'boolean',
7676
desc: chalk.gray(
7777
'Suppress all gulp logging.'),
@@ -81,12 +81,13 @@ module.exports = {
8181
desc: chalk.gray(
8282
'Continue execution of tasks upon failure.'),
8383
},
84-
loglevel: {
85-
alias: 'l',
86-
type: 'boolean',
84+
'log-level': {
85+
alias: 'L',
86+
// Type isn't needed because count acts as a boolean
8787
count: true,
88+
// Can't use `default` because it seems to be off by one
8889
desc: chalk.gray(
89-
'Set the loglevel. -l for least verbose and -llll for most verbose.' +
90-
' -lll is default.'),
90+
'Set the loglevel. -L for least verbose and -LLLL for most verbose.' +
91+
' -LLL is default.'),
9192
},
9293
};

lib/shared/log/toConsole.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@
22

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

5+
function noop() {}
6+
57
// The sorting of the levels is
68
// significant.
79
var levels = [
8-
'error', // -l: Logs error events.
9-
'warn', // -ll: Logs warn and error events.
10-
'info', // -lll: Logs info, warn and error events.
11-
'debug', // -llll: Logs all log levels.
10+
'error', // -L: Logs error events.
11+
'warn', // -LL: Logs warn and error events.
12+
'info', // -LLL: Logs info, warn and error events.
13+
'debug', // -LLLL: Logs all log levels.
1214
];
1315

1416
function toConsole(log, opts) {
1517
// Return immediately if logging is
1618
// not desired.
1719
if (opts.tasksSimple || opts.silent) {
20+
// Keep from crashing process when silent.
21+
log.on('error', noop);
1822
return;
1923
}
2024

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

2728
levels
2829
.filter(function(item, i) {

test/logging.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var code = require('code');
55
var child = require('child_process');
66

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

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

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

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

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

0 commit comments

Comments
 (0)