Skip to content

Commit 2bb86f2

Browse files
committed
Disable/enable color in the very beginning.
Signed-off-by: Eric Wang <[email protected]>
1 parent 23b0016 commit 2bb86f2

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

bin/lc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env node
22

3-
require('../lib/cli');
3+
require('../lib/cli').run();

lib/cli.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
var yargs = require('yargs');
1+
// We are expecting a tier configuration like:
2+
// global config < local config < cli params
3+
// Color is a tricky one so we manually handle it here.
4+
function setColorMode() {
5+
var useColor = require('./config').USE_COLOR || false;
6+
if (process.argv.indexOf('--color') >= 0) useColor = true;
7+
if (process.argv.indexOf('--no-color') >= 0) useColor = false;
28

3-
yargs.commandDir('commands')
4-
.completion()
5-
.help()
6-
.strict()
7-
.argv;
9+
require('chalk').enabled = useColor;
10+
}
11+
12+
var cli = {};
13+
14+
cli.run = function() {
15+
setColorMode();
16+
17+
require('yargs')
18+
.commandDir('commands')
19+
.completion()
20+
.help()
21+
.strict()
22+
.argv;
23+
};
24+
25+
module.exports = cli;

lib/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ module.exports = {
88
VERIFY_URL: 'https://leetcode.com/submissions/detail/$id/check/',
99

1010
// but you will want change these
11-
LANG: 'cpp' // others: c,csharp,golang,java,javascript,python,ruby,swift
11+
LANG: 'cpp', // avail: [c,cpp,csharp,golang,java,javascript,python,ruby,swift]
12+
USE_COLOR: false
1213
};

0 commit comments

Comments
 (0)