@@ -10,17 +10,27 @@ var queue = require('../queue');
1010
1111var cmd = {
1212 command : 'submission [keyword]' ,
13- desc : 'Retrieve earlier submission by name or index' ,
13+ desc : 'retrieve earlier submission by name or index' ,
1414 builder : {
1515 all : {
1616 alias : 'a' ,
1717 type : 'boolean' ,
1818 describe : 'Retrieve for all problems'
19+ } ,
20+ outdir : {
21+ alias : 'o' ,
22+ type : 'string' ,
23+ describe : 'Where to save the submissions' ,
24+ default : '.'
1925 }
2026 }
2127} ;
2228
2329function getSubmissionDone ( e , msg , problem , cb ) {
30+ // NOTE: msg color means different purpose:
31+ // - red: error
32+ // - yellow: accepted, new download
33+ // - white: existed already, no download
2434 console . log ( sprintf ( '[%3d] %-60s %s' ,
2535 problem . id ,
2636 problem . name ,
@@ -29,7 +39,7 @@ function getSubmissionDone(e, msg, problem, cb) {
2939 if ( cb ) cb ( e ) ;
3040}
3141
32- function getSubmission ( problem , cb ) {
42+ function getSubmission ( argv , problem , cb ) {
3343 var done = _ . partial ( getSubmissionDone , _ , _ , problem , cb ) ;
3444
3545 core . getSubmissions ( problem , function ( e , submissions ) {
@@ -45,7 +55,8 @@ function getSubmission(problem, cb) {
4555 // if no accepted, use the latest non-accepted one
4656 submission = submission || submissions [ 0 ] ;
4757
48- var filename = sprintf ( '%s.%s.%s%s' ,
58+ var filename = sprintf ( '%s/%s.%s.%s%s' ,
59+ argv . outdir ,
4960 problem . key ,
5061 submission . id ,
5162 problem . state ,
@@ -66,6 +77,8 @@ function getSubmission(problem, cb) {
6677}
6778
6879cmd . handler = function ( argv ) {
80+ var doTask = _ . partial ( getSubmission , argv , _ , _ ) ;
81+
6982 if ( argv . all ) {
7083 core . getProblems ( function ( e , problems ) {
7184 if ( e ) return console . log ( 'ERROR:' , e ) ;
@@ -74,7 +87,7 @@ cmd.handler = function(argv) {
7487 return q . state === 'ac' ;
7588 } ) ;
7689
77- queue . run ( problems , getSubmission ) ;
90+ queue . run ( problems , doTask ) ;
7891 } ) ;
7992 return ;
8093 }
@@ -85,7 +98,7 @@ cmd.handler = function(argv) {
8598 core . getProblem ( argv . keyword , function ( e , problem ) {
8699 if ( e ) return console . log ( 'ERROR:' , e ) ;
87100
88- queue . run ( [ problem ] , getSubmission ) ;
101+ queue . run ( [ problem ] , doTask ) ;
89102 } ) ;
90103} ;
91104
0 commit comments