Skip to content

Commit 9caf9bc

Browse files
authored
Merge pull request #2 from libaoxi/feature/1/category
Feature/1/category
2 parents 83b3e97 + 057cad7 commit 9caf9bc

File tree

7 files changed

+99
-198
lines changed

7 files changed

+99
-198
lines changed

.eslintrc.js

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
module.exports = {
2-
"env": {
3-
"browser": false,
4-
"es6": true,
5-
"mocha": true,
6-
"node": true
7-
},
8-
"extends": [
9-
"google",
10-
"eslint:recommended"
11-
],
12-
"rules": {
13-
"block-spacing": [2, "always"],
14-
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
15-
"camelcase": [2, {properties: "never"}],
16-
"comma-dangle": 0,
17-
"curly": 0,
18-
"key-spacing": [2, {align: "value"}],
19-
"max-len": [1, 120],
20-
"no-control-regex": 0,
21-
"no-console": 1,
22-
"no-empty": [2, { "allowEmptyCatch": true }],
23-
"no-eval": 1, // we use it on purpose
24-
"no-loop-func": 1,
25-
"no-multi-spaces": 0,
26-
"no-proto": 1,
27-
"no-unused-expressions": 1,
28-
"no-unused-vars": 1,
29-
"no-var": 0,
30-
"no-warning-comments": 0,
31-
"prefer-rest-params": 0,
32-
"prefer-spread": 0,
33-
"quote-props": 1,
34-
"quotes": [2, "single", {avoidEscape: true}],
35-
"require-jsdoc": 0,
36-
}
2+
'env': {
3+
'browser': false,
4+
'es6': true,
5+
'mocha': true,
6+
'node': true
7+
},
8+
'extends': [
9+
'google',
10+
'eslint:recommended'
11+
],
12+
'rules': {
13+
'block-spacing': [2, 'always'],
14+
'brace-style': [2, '1tbs', {'allowSingleLine': true}],
15+
'camelcase': [2, {properties: 'never'}],
16+
'comma-dangle': 0,
17+
'curly': 0,
18+
'key-spacing': [2, {align: 'value'}],
19+
'max-len': [1, 120],
20+
'no-control-regex': 0,
21+
'no-console': 1,
22+
'no-empty': [2, {'allowEmptyCatch': true}],
23+
'no-eval': 1, // we use it on purpose
24+
'no-loop-func': 1,
25+
'no-multi-spaces': 0,
26+
'no-proto': 1,
27+
'no-unused-expressions': 1,
28+
'no-unused-vars': 1,
29+
'no-var': 0,
30+
'no-warning-comments': 0,
31+
'prefer-rest-params': 0,
32+
'prefer-spread': 0,
33+
'quote-props': 1,
34+
'quotes': [2, 'single', {avoidEscape: true}],
35+
'require-jsdoc': 0,
36+
}
3737
};

lib/api.js

-107
This file was deleted.

lib/cli.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function initLogLevel() {
5555

5656
function initDir() {
5757
file.init();
58-
file.mkdir(file.homeDir())
58+
file.mkdir(file.homeDir());
5959
}
6060

6161
function initPlugins(cb) {
@@ -77,13 +77,13 @@ function runCommand() {
7777
var yargs = require('yargs');
7878
h.width = yargs.terminalWidth();
7979
yargs.commandDir('commands')
80-
.completion()
81-
.help('h')
82-
.alias('h', 'help')
83-
.version(false)
84-
.epilog('Seek more help at https://skygragon.github.io/leetcode-cli/commands')
85-
.wrap(Math.min(h.width, 120))
86-
.argv;
80+
.completion()
81+
.help('h')
82+
.alias('h', 'help')
83+
.version(false)
84+
.epilog('Seek more help at https://skygragon.github.io/leetcode-cli/commands')
85+
.wrap(Math.min(h.width, 120))
86+
.argv;
8787
}
8888

8989
cli.run = function() {
@@ -96,7 +96,7 @@ cli.run = function() {
9696
initColor();
9797
initIcon();
9898
initLogLevel();
99-
initDir()
99+
initDir();
100100
initPlugins(function(e) {
101101
if (e) return log.fatal(e);
102102
cache.init();

lib/commands/list.js

+33-31
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,34 @@ const cmd = {
1414
desc: 'List questions',
1515
builder: function(yargs) {
1616
return yargs
17-
.option('q', core.filters.query)
18-
.option('s', {
19-
alias: 'stat',
20-
type: 'boolean',
21-
default: false,
22-
describe: 'Show statistics of listed questions'
23-
})
24-
.option('t', core.filters.tag)
25-
.option('x', {
26-
alias: 'extra',
27-
type: 'boolean',
28-
default: false,
29-
describe: 'Show extra details: category, companies, tags.'
30-
})
31-
.positional('keyword', {
32-
type: 'string',
33-
default: '',
34-
describe: 'Filter questions by keyword'
35-
})
36-
.example(chalk.yellow('leetcode list'), 'List all questions')
37-
.example(chalk.yellow('leetcode list -x'), 'Show extra info of questions, e.g. tags')
38-
.example('', '')
39-
.example(chalk.yellow('leetcode list array'), 'List questions that has "array" in name')
40-
.example(chalk.yellow('leetcode list -q eD'), 'List questions that with easy level and not done')
41-
.example(chalk.yellow('leetcode list -t google'), 'List questions from Google company (require plugin)')
42-
.example(chalk.yellow('leetcode list -t stack'), 'List questions realted to stack (require plugin)');
17+
.option('q', core.filters.query)
18+
.option('s', {
19+
alias: 'stat',
20+
type: 'boolean',
21+
default: false,
22+
describe: 'Show statistics of listed questions'
23+
})
24+
.option('t', core.filters.tag)
25+
.option('x', {
26+
alias: 'extra',
27+
type: 'boolean',
28+
default: false,
29+
describe: 'Show extra details: category, companies, tags.'
30+
})
31+
.option('c', core.filters.category)
32+
.positional('keyword', {
33+
type: 'string',
34+
default: '',
35+
describe: 'Filter questions by keyword'
36+
})
37+
.example(chalk.yellow('leetcode list'), 'List all questions')
38+
.example(chalk.yellow('leetcode list -x'), 'Show extra info of questions, e.g. tags')
39+
.example('', '')
40+
.example(chalk.yellow('leetcode list array'), 'List questions that has "array" in name')
41+
.example(chalk.yellow('leetcode list -q eD'), 'List questions that with easy level and not done')
42+
.example(chalk.yellow('leetcode list -t google'), 'List questions from Google company (require plugin)')
43+
.example(chalk.yellow('leetcode list -t stack'), 'List questions realted to stack (require plugin)')
44+
.example(chalk.yellow('leetcode list -c lcof'), 'List questions from category (require plugin)');
4345
}
4446
};
4547

@@ -53,14 +55,14 @@ cmd.handler = function(argv) {
5355
if (word.endsWith(word.substr(-1).repeat(6))) {
5456
log.warn('Hmmm...you might need a new keyboard?');
5557
}
56-
problems = problems.filter(x => x.name.toLowerCase().includes(word));
58+
problems = problems.filter((x) => x.name.toLowerCase().includes(word));
5759
}
5860

5961
const stat = {};
60-
for (let x of ['locked', 'starred', 'ac', 'notac', 'None', 'Easy', 'Medium', 'Hard']) stat[x] = 0;
62+
for (const x of ['locked', 'starred', 'ac', 'notac', 'None', 'Easy', 'Medium', 'Hard']) stat[x] = 0;
6163

62-
problems = _.sortBy(problems, x => x.id);
63-
for (let problem of problems) {
64+
problems = _.sortBy(problems, (x) => x.id);
65+
for (const problem of problems) {
6466
stat[problem.level] = (stat[problem.level] || 0) + 1;
6567
stat[problem.state] = (stat[problem.state] || 0) + 1;
6668
if (problem.locked) ++stat.locked;
@@ -82,7 +84,7 @@ cmd.handler = function(argv) {
8284

8385
let buf = [];
8486
let len = 0;
85-
for (let x of badges) {
87+
for (const x of badges) {
8688
if (len + x.length + 3 >= 60) {
8789
log.printf('%12s%s', ' ', chalk.gray(buf.join(' | ')));
8890
buf = [];

lib/core.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,23 @@ core.filters = {
3333
type: 'array',
3434
default: [],
3535
describe: 'Filter questions by tag'
36+
},
37+
category: {
38+
alias: 'category',
39+
type: 'string',
40+
default: '',
41+
describe: 'Filter questions by category'
3642
}
3743
};
3844

3945
function hasTag(o, tag) {
40-
return Array.isArray(o) && o.some(x => x.indexOf(tag.toLowerCase()) >= 0);
46+
return Array.isArray(o) && o.some((x) => x.indexOf(tag.toLowerCase()) >= 0);
4147
}
4248

4349
const isLevel = (x, q) => x.level[0].toLowerCase() === q.toLowerCase();
44-
const isACed = x => x.state === 'ac';
45-
const isLocked = x => x.locked;
46-
const isStarred = x => x.starred;
50+
const isACed = (x) => x.state === 'ac';
51+
const isLocked = (x) => x.locked;
52+
const isStarred = (x) => x.starred;
4753

4854
const QUERY_HANDLERS = {
4955
e: isLevel,
@@ -63,14 +69,19 @@ const QUERY_HANDLERS = {
6369
core.filterProblems = function(opts, cb) {
6470
this.getProblems(function(e, problems) {
6571
if (e) return cb(e);
66-
67-
for (let q of (opts.query || '').split('')) {
72+
for (const q of (opts.query || '').split('')) {
6873
const f = QUERY_HANDLERS[q];
6974
if (!f) continue;
70-
problems = problems.filter(x => f(x, q));
75+
problems = problems.filter((x) => f(x, q));
76+
}
77+
78+
if (opts.category) {
79+
problems = problems.filter((x) => {
80+
return x.category === opts.category;
81+
});
7182
}
7283

73-
for (let t of (opts.tag || [])) {
84+
for (const t of (opts.tag || [])) {
7485
problems = problems.filter(function(x) {
7586
return x.category === t ||
7687
hasTag(x.companies, t) ||

package-lock.json

+1-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)