Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit a5fe81b

Browse files
committed
refactor: change behavior of --color
BREAKING CHANGE: The --color option doesn't support string values ('false', 'true') anymore. To disable coloring, use --no-color instead. The -c short option has been removed.
1 parent 8eb265b commit a5fe81b

File tree

7 files changed

+16
-124
lines changed

7 files changed

+16
-124
lines changed

docs/how-to-guides.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ As you can see, the parameters go like this:
712712

713713
::
714714

715-
$ dredd -c apiaryApiKey:<Apiary API Key> -c apiaryApiName:<API Project Subdomain>
715+
$ dredd -j apiaryApiKey:<Apiary API Key> -j apiaryApiName:<API Project Subdomain>
716716

717717
In addition to using parameters and ``dredd.yml``, you can also use environment variables:
718718

docs/usage-js.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Let’s have a look at an example configuration first. (Please also see the :ref
5656
5757
'require': null, // String, When using nodejs hooks, require the given module before executing hooks
5858
59-
'no-color': false,
59+
'color': true,
6060
},
6161
6262
'emitter': EventEmitterInstance, // optional - listen to test progress, your own instance of EventEmitter

lib/CLI.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ class CLI {
1919
constructor(options = {}, cb) {
2020
this.cb = cb;
2121
this.finished = false;
22-
({ exit: this.exit, custom: this.custom } = options);
22+
this.exit = options.exit;
23+
this.custom = options.custom || {};
2324

2425
this.setExitOrCallback();
2526

26-
if (!this.custom) { this.custom = {}; }
27-
2827
if (!this.custom.cwd || typeof this.custom.cwd !== 'string') {
2928
this.custom.cwd = process.cwd();
3029
}
@@ -52,7 +51,7 @@ Example:
5251
.wrap(80);
5352

5453
this.argv = this.optimist.argv;
55-
this.argv = applyLoggingOptions(this.argv);
54+
applyLoggingOptions(this.argv);
5655
}
5756

5857
// Gracefully terminate server
@@ -188,7 +187,7 @@ ${packageData.name} v${packageData.version} \
188187
}
189188
});
190189

191-
this.argv = applyLoggingOptions(this.argv);
190+
applyLoggingOptions(this.argv);
192191
}
193192

194193
parseCustomConfig() {

lib/configuration.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@ function coerceToArray(value) {
1818

1919

2020
function applyLoggingOptions(options) {
21-
// The CLI layer should handle 'color' and it should be implemented
22-
// as a --color/--no-color boolean option with no values
23-
if (options.color === 'false') {
24-
options.color = false;
25-
} else if (options.color === 'true') {
26-
options.color = true;
21+
if (options.color === false) {
22+
logger.transports.console.colorize = false;
23+
reporterOutputLogger.transports.console.colorize = false;
2724
}
28-
logger.transports.console.colorize = options.color;
29-
reporterOutputLogger.transports.console.colorize = options.color;
3025

3126
// Handling the 'loglevel' value
3227
if (options.loglevel) {
@@ -46,8 +41,6 @@ function applyLoggingOptions(options) {
4641
} else {
4742
logger.transports.console.level = 'warn';
4843
}
49-
50-
return options;
5144
}
5245

5346

@@ -118,7 +111,7 @@ function applyConfiguration(config) {
118111
configuration.options.header.push(authHeader);
119112
}
120113

121-
configuration.options = applyLoggingOptions(configuration.options);
114+
applyLoggingOptions(configuration.options);
122115

123116
if (config) {
124117
if (config.hooksData

lib/options.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@
8888
"default": []
8989
},
9090
"color": {
91-
"alias": "c",
92-
"description": "Determines whether console output should include colors.",
91+
"description": "Use --no-color to suppress colors on the output",
92+
"boolean": true,
9393
"default": true
9494
},
9595
"loglevel": {

test/integration/cli/hookfiles-cli-test.js

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -508,31 +508,6 @@ describe('CLI', () => {
508508
});
509509
});
510510

511-
describe('when suppressing color with --color=false', () => {
512-
let runtimeInfo;
513-
514-
before((done) => {
515-
const app = createServer();
516-
app.get('/machines', (req, res) => res.json([{ type: 'bulldozer', name: 'willy' }]));
517-
518-
const args = [
519-
'./test/fixtures/single-get.apib',
520-
`http://127.0.0.1:${DEFAULT_SERVER_PORT}`,
521-
'--color=false',
522-
];
523-
runCLIWithServer(args, app, (err, info) => {
524-
runtimeInfo = info;
525-
done(err);
526-
});
527-
});
528-
529-
it('should print without colors', () => {
530-
// If colors are not on, there is no closing color code between
531-
// the "pass" and the ":"
532-
assert.include(runtimeInfo.dredd.stdout, 'pass:');
533-
});
534-
});
535-
536511
describe('when setting the log output level with --loglevel', () => {
537512
let runtimeInfo;
538513

@@ -544,7 +519,7 @@ describe('CLI', () => {
544519
'./test/fixtures/single-get.apib',
545520
`http://127.0.0.1:${DEFAULT_SERVER_PORT}`,
546521
'--loglevel=error',
547-
'--color=false',
522+
'--no-color',
548523
];
549524
runCLIWithServer(args, app, (err, info) => {
550525
runtimeInfo = info;

test/unit/configuration-test.js

Lines changed: 3 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,9 @@ describe('configuration.applyLoggingOptions()', () => {
1919
reporterOutputLogger.transports.console = reporterOutputLoggerSettings;
2020
});
2121

22-
describe('with color set to true', () => {
23-
let options;
24-
22+
describe('with color not set', () => {
2523
beforeEach(() => {
26-
options = configuration.applyLoggingOptions({ color: true });
27-
});
28-
29-
it('resulting configuration should contain \'color\' set to boolean true', () => {
30-
assert.isTrue(options.color);
31-
});
32-
33-
it('the application logger should be set to colorize', () => {
34-
assert.isTrue(logger.transports.console.colorize);
35-
});
36-
37-
it('the application output should be set to colorize', () => {
38-
assert.isTrue(reporterOutputLogger.transports.console.colorize);
39-
});
40-
});
41-
42-
describe('with color set to \'true\' string value', () => {
43-
let options;
44-
45-
beforeEach(() => {
46-
options = configuration.applyLoggingOptions({ color: 'true' });
47-
});
48-
49-
it('resulting configuration should contain \'color\' set to boolean true', () => {
50-
assert.isTrue(options.color);
24+
configuration.applyLoggingOptions({});
5125
});
5226

5327
it('the application logger should be set to colorize', () => {
@@ -60,34 +34,8 @@ describe('configuration.applyLoggingOptions()', () => {
6034
});
6135

6236
describe('with color set to false', () => {
63-
let options;
64-
65-
beforeEach(() => {
66-
options = configuration.applyLoggingOptions({ color: false });
67-
});
68-
69-
it('resulting configuration should contain \'color\' set to boolean false', () => {
70-
assert.isFalse(options.color);
71-
});
72-
73-
it('the application logger should be set not to colorize', () => {
74-
assert.isFalse(logger.transports.console.colorize);
75-
});
76-
77-
it('the application output should be set not to colorize', () => {
78-
assert.isFalse(reporterOutputLogger.transports.console.colorize);
79-
});
80-
});
81-
82-
describe('with color set to \'false\' string value', () => {
83-
let options;
84-
8537
beforeEach(() => {
86-
options = configuration.applyLoggingOptions({ color: 'false' });
87-
});
88-
89-
it('resulting configuration should contain \'color\' set to boolean false', () => {
90-
assert.isFalse(options.color);
38+
configuration.applyLoggingOptions({ color: false });
9139
});
9240

9341
it('the application logger should be set not to colorize', () => {
@@ -214,26 +162,3 @@ describe('configuration.applyLoggingOptions()', () => {
214162
});
215163
});
216164
});
217-
218-
describe('configuration.applyConfiguration()', () => {
219-
let loggerSettings;
220-
let config;
221-
222-
beforeEach(() => { loggerSettings = clone(logger.transports.console); });
223-
afterEach(() => { logger.transports.console = loggerSettings; });
224-
225-
it('applies logging options', () => {
226-
config = configuration.applyConfiguration({
227-
options: {
228-
color: 'true',
229-
loglevel: 'debug',
230-
},
231-
});
232-
233-
assert.nestedPropertyVal(config, 'options.color', true);
234-
assert.equal(logger.transports.console.colorize, true);
235-
236-
assert.nestedPropertyVal(config, 'options.loglevel', 'debug');
237-
assert.equal(logger.transports.console.level, 'debug');
238-
});
239-
});

0 commit comments

Comments
 (0)