Skip to content

Commit 93f0ed0

Browse files
committed
refs skygragon#76: enhance filtering by tags.
* support multiple tags, e.g. `list -t google -t tree` * tested with 'company' plugin 2017.12.18 Signed-off-by: Eric Wang <[email protected]>
1 parent 26b5ec4 commit 93f0ed0

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

lib/commands/list.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ var cmd = {
3030
default: false,
3131
describe: 'Show problems statistics'
3232
},
33-
tag: {
33+
tags: {
3434
alias: 't',
35-
type: 'string',
36-
default: '',
35+
type: 'array',
36+
default: [],
3737
describe: 'Filter problems by tags'
3838
}
3939
}
@@ -70,6 +70,12 @@ var QUERY_HANDLERS = {
7070
S: _.negate(byStarred)
7171
};
7272

73+
function hasTag(o, tag) {
74+
return _.isArray(o) && _.some(o, function(x) {
75+
return x.indexOf(tag.toLowerCase()) !== -1;
76+
});
77+
}
78+
7379
cmd.handler = function(argv) {
7480
session.argv = argv;
7581
core.getProblems(function(e, problems) {
@@ -86,15 +92,14 @@ cmd.handler = function(argv) {
8692
});
8793
}
8894

89-
if (argv.tag) {
90-
var tag = argv.tag.toLowerCase();
95+
argv.tags.forEach(function(tag) {
9196
// TODO: fill company/tags in problems
92-
problems = _.filter(problems, function(x) {
93-
return x.category === tag ||
94-
(_.isArray(x.companies) && x.companies.indexOf(tag) !== -1) ||
95-
(_.isArray(x.tags) && x.tags.indexOf(tag) !== -1);
97+
problems = _.filter(problems, function(p) {
98+
return p.category === tag ||
99+
hasTag(p.companies, tag) ||
100+
hasTag(p.tags, tag);
96101
});
97-
}
102+
});
98103

99104
var word = String(argv.keyword).toLowerCase();
100105
if (word) {

0 commit comments

Comments
 (0)