Skip to content

Commit d58eee0

Browse files
committedAug 20, 2016
Implement 'list <keyword>'
* fixes invalid usage of yargs command. Signed-off-by: Eric Wang <skygragon@gmail.com>
1 parent 6eb42a7 commit d58eee0

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed
 

‎README.md

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Navigate all the problems. The heading `✔` means you have AC-ed the problem.
5555
✔ [ 1] Two Sum Easy (25.6%)
5656

5757
* `-D` to only show undone problems.
58+
* `-l` to filter by level.
59+
* `-s` to show statistic counters.
60+
* `lc list <keyword>` to search by keyword.
5861

5962
### 3. Prepare
6063

‎lib/commands/list.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,26 @@ var core = require('../core');
55
var h = require('../helper');
66

77
var cmd = {
8-
command: 'list [--level|-l] [--stat|-s] [--undone|-D]',
8+
command: 'list [keyword]',
99
desc: 'List all problems.',
1010
builder: {
11+
keyword: {
12+
type: 'string',
13+
describe: 'keyword used to search problems.'
14+
},
1115
level: {
1216
alias: 'l',
1317
choices: ['easy', 'medium', 'hard', 'e', 'm', 'h'],
1418
describe: 'Filter problems by level.'
1519
},
1620
stat: {
1721
alias: 's',
22+
type: 'boolean',
1823
describe: 'Show stats of the problems.'
1924
},
2025
undone: {
2126
alias: 'D',
27+
type: 'boolean',
2228
describe: 'List undone problems.'
2329
}
2430
}
@@ -42,6 +48,12 @@ cmd.handler = function(argv) {
4248
});
4349
}
4450

51+
if (argv.keyword) {
52+
problems = _.filter(problems, function(x) {
53+
return x.name.toLowerCase().indexOf(argv.keyword) !== -1;
54+
});
55+
}
56+
4557
var stat = {};
4658
problems.forEach(function(problem) {
4759
stat[problem.level] = (stat[problem.level] || 0) + 1;

‎lib/commands/show.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var core = require('../core');
88
var h = require('../helper');
99

1010
var cmd = {
11-
command: 'show <keyword> [--gen|-g] [--lang|-l]',
11+
command: 'show <keyword>',
1212
desc: 'Show problem details.',
1313
builder: {
1414
keyword: {

‎lib/commands/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var core = require('../core');
55
var h = require('../helper');
66

77
var cmd = {
8-
command: 'test <filename> [--testcase|-t] [-i]',
8+
command: 'test <filename>',
99
desc: 'Run test case to leetcode.',
1010
builder: {
1111
filename: {

‎lib/commands/update.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var cmd = {
2-
command: 'update [--cached|-c] [--all|-a]',
2+
command: 'update',
33
desc: 'Update problems list from leetcode.',
44
builder: {
55
all: {

‎lib/commands/user.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var prompt = require('prompt');
33
var core = require('../core');
44

55
var cmd = {
6-
command: 'user [--login|-l] [--logout|-L]',
6+
command: 'user',
77
desc: 'Login/logout with leetcode account.',
88
builder: {
99
login: {

0 commit comments

Comments
 (0)
Please sign in to comment.