@@ -10,41 +10,60 @@ var cmd = {
1010 builder : {
1111 keyword : {
1212 type : 'string' ,
13- describe : 'keyword used to search problems .'
13+ describe : 'Filter problems by keyword .'
1414 } ,
15- level : {
16- alias : 'l' ,
17- choices : [ 'easy' , 'medium' , 'hard' , 'e' , 'm' , 'h' ] ,
18- describe : 'Filter problems by level.'
15+ query : {
16+ alias : 'q' ,
17+ type : 'string' ,
18+ describe : 'Filter problems by conditions.\n' +
19+ 'e(easy),m(medium),h(hard),d(done),l(locked)\n' +
20+ 'Uppercase means "not", e.g. D(not done)'
1921 } ,
2022 stat : {
2123 alias : 's' ,
2224 type : 'boolean' ,
23- describe : 'Show stats of the problems.'
24- } ,
25- undone : {
26- alias : 'D' ,
27- type : 'boolean' ,
28- describe : 'List undone problems.'
25+ describe : 'Show stats of the listed problems.'
2926 }
3027 }
3128} ;
3229
30+ function byLevel ( x , q ) {
31+ return x . level [ 0 ] . toLowerCase ( ) === q . toLowerCase ( ) ;
32+ }
33+
34+ function byStateAC ( x , q ) {
35+ return x . state === 'ac' ;
36+ }
37+
38+ function byLocked ( x , q ) {
39+ return x . locked ;
40+ }
41+
42+ var QUERY_HANDLERS = {
43+ e : byLevel ,
44+ E : _ . negate ( byLevel ) ,
45+ m : byLevel ,
46+ M : _ . negate ( byLevel ) ,
47+ h : byLevel ,
48+ H : _ . negate ( byLevel ) ,
49+ l : byLocked ,
50+ L : _ . negate ( byLocked ) ,
51+ d : byStateAC ,
52+ D : _ . negate ( byStateAC )
53+ } ;
54+
3355cmd . handler = function ( argv ) {
3456 core . getProblems ( function ( e , problems ) {
3557 if ( e ) return console . log ( 'ERROR:' , e ) ;
3658
3759 var all = problems . length ;
3860
39- if ( argv . undone ) {
40- problems = _ . filter ( problems , function ( x ) {
41- return x . state !== 'ac' ;
42- } ) ;
43- }
61+ if ( argv . query ) {
62+ argv . query . split ( '' ) . forEach ( function ( q ) {
63+ var f = QUERY_HANDLERS [ q ] ;
64+ if ( ! f ) return ;
4465
45- if ( argv . level ) {
46- problems = _ . filter ( problems , function ( x ) {
47- return x . level [ 0 ] . toLowerCase ( ) === argv . level [ 0 ] ;
66+ problems = _ . filter ( problems , _ . partial ( f , _ , q ) ) ;
4867 } ) ;
4968 }
5069
0 commit comments