@@ -7,44 +7,43 @@ var cache = require('../cache');
77var session = require ( '../session' ) ;
88
99var cmd = {
10- command : 'cache' ,
10+ command : 'cache [keyword] ' ,
1111 desc : 'show cached problems' ,
1212 builder : {
13- all : {
14- alias : 'a' ,
15- type : 'boolean' ,
16- describe : 'Delete all cached problems' ,
17- default : false
18- } ,
1913 delete : {
2014 alias : 'd' ,
21- type : 'string' ,
22- describe : 'Delete specific cached problem'
15+ type : 'boolean' ,
16+ describe : 'Delete cached problem' ,
17+ default : false
2318 }
2419 }
2520} ;
2621
2722cmd . handler = function ( argv ) {
2823 session . argv = argv ;
29- if ( argv . delete === undefined ) {
30- _ . sortBy ( cache . list ( ) , function ( f ) {
24+
25+ var caches = cache . list ( )
26+ . filter ( function ( f ) {
27+ return argv . keyword === undefined || f . name . startsWith ( argv . keyword + '.' ) ;
28+ } ) ;
29+
30+ if ( argv . delete ) {
31+ caches . forEach ( function ( f ) {
32+ if ( f . name === '.user' ) return ;
33+ cache . del ( f . name ) ;
34+ } ) ;
35+ } else {
36+ _ . sortBy ( caches , function ( f ) {
3137 var x = parseInt ( f . name . split ( '.' ) [ 0 ] , 10 ) ;
3238 if ( _ . isNaN ( x ) ) x = 0 ;
3339 return x ;
3440 } )
3541 . forEach ( function ( f ) {
36- log . printf ( '%-50s %8s %s ago' ,
42+ log . printf ( '%-60s %8s %s ago' ,
3743 chalk . green ( f . name ) ,
3844 h . prettySize ( f . size ) ,
3945 h . prettyTime ( ( Date . now ( ) - f . mtime ) / 1000 ) ) ;
4046 } ) ;
41- } else if ( argv . all ) {
42- cache . list ( ) . forEach ( function ( f ) {
43- if ( f . name === '.user' ) return ;
44- cache . del ( f . name ) ;
45- } ) ;
46- } else {
47- cache . del ( argv . delete ) ;
4847 }
4948} ;
5049
0 commit comments