@@ -5,12 +5,17 @@ var core = require('../core');
55var h = require ( '../helper' ) ;
66
77var cmd = {
8- command : 'list [--cached|-c ] [--undone|-D]' ,
8+ command : 'list [--level|-l] [--stat|-s ] [--undone|-D]' ,
99 desc : 'List all problems.' ,
1010 builder : {
11- cached : {
12- alias : 'c' ,
13- describe : 'List cached problems.'
11+ level : {
12+ alias : 'l' ,
13+ choices : [ 'easy' , 'medium' , 'hard' , 'e' , 'm' , 'h' ] ,
14+ describe : 'Filter problems by level.'
15+ } ,
16+ stat : {
17+ alias : 's' ,
18+ describe : 'Show stats of the problems.'
1419 } ,
1520 undone : {
1621 alias : 'D' ,
@@ -23,17 +28,39 @@ cmd.handler = function(argv) {
2328 core . getProblems ( function ( e , problems ) {
2429 if ( e ) return console . log ( 'ERROR:' , e ) ;
2530
31+ var all = problems . length ;
32+
2633 if ( argv . undone ) {
2734 problems = _ . filter ( problems , function ( x ) {
2835 return x . state !== 'ac' ;
2936 } ) ;
3037 }
3138
39+ if ( argv . level ) {
40+ problems = _ . filter ( problems , function ( x ) {
41+ return x . level [ 0 ] . toLowerCase ( ) === argv . level [ 0 ] ;
42+ } ) ;
43+ }
44+
45+ var stat = { } ;
3246 problems . forEach ( function ( problem ) {
47+ stat [ problem . level ] = ( stat [ problem . level ] || 0 ) + 1 ;
48+ stat [ problem . state ] = ( stat [ problem . state ] || 0 ) + 1 ;
49+
3350 console . log ( sprintf ( '%s [%3d] %-60s %-6s (%s)' ,
3451 h . prettyState ( problem . state ) , problem . id ,
3552 problem . name , problem . level , problem . percent ) ) ;
3653 } ) ;
54+
55+ if ( argv . stat ) {
56+ console . log ( ) ;
57+ console . log ( sprintf ( ' All: %-9d Listed: %-9d' ,
58+ all , problems . length ) ) ;
59+ console . log ( sprintf ( ' AC: %-9d Not-AC: %-9d New: %-9d' ,
60+ ( stat . ac || 0 ) , ( stat . notac || 0 ) , ( stat . None || 0 ) ) ) ;
61+ console . log ( sprintf ( ' Easy: %-9d Medium: %-9d Hard: %-9d' ,
62+ ( stat . Easy || 0 ) , ( stat . Medium || 0 ) , ( stat . Hard || 0 ) ) ) ;
63+ }
3764 } ) ;
3865} ;
3966
0 commit comments