@@ -24,11 +24,17 @@ var cmd = {
2424 type : 'string' ,
2525 describe : 'Where to save the submissions' ,
2626 default : '.'
27+ } ,
28+ extra : {
29+ alias : 'x' ,
30+ type : 'boolean' ,
31+ default : false ,
32+ describe : 'Provide extra problem details in submission file'
2733 }
2834 }
2935} ;
3036
31- function getSubmissionDone ( e , msg , problem , cb ) {
37+ function onTaskDone ( e , msg , problem , cb ) {
3238 // NOTE: msg color means different purpose:
3339 // - red: error
3440 // - green: accepted, fresh download
@@ -42,12 +48,25 @@ function getSubmissionDone(e, msg, problem, cb) {
4248 if ( cb ) cb ( e ) ;
4349}
4450
45- function getSubmission ( argv , problem , cb ) {
46- var done = _ . partial ( getSubmissionDone , _ , _ , problem , cb ) ;
51+ function onTaskRun ( argv , problem , cb ) {
52+ var done = _ . partial ( onTaskDone , _ , _ , problem , cb ) ;
53+
54+ if ( argv . extra ) {
55+ // have to get problem details, e.g. problem description.
56+ core . getProblem ( problem . id , function ( e , problem ) {
57+ if ( e ) return done ( e ) ;
58+
59+ exportSubmission ( argv , problem , done ) ;
60+ } ) ;
61+ } else {
62+ exportSubmission ( argv , problem , done ) ;
63+ }
64+ }
4765
66+ function exportSubmission ( argv , problem , cb ) {
4867 core . getSubmissions ( problem , function ( e , submissions ) {
49- if ( e ) return done ( e ) ;
50- if ( submissions . length === 0 ) return done ( 'no submissions?' ) ;
68+ if ( e ) return cb ( e ) ;
69+ if ( submissions . length === 0 ) return cb ( 'no submissions?' ) ;
5170
5271 // find the latest accepted one
5372 var submission = _ . find ( submissions , function ( x ) {
@@ -67,24 +86,25 @@ function getSubmission(argv, problem, cb) {
6786
6887 // skip the existing cached submissions
6988 if ( fs . existsSync ( filename ) ) {
70- return done ( null , chalk . underline ( filename ) ) ;
89+ return cb ( null , chalk . underline ( filename ) ) ;
7190 }
7291
7392 core . getSubmission ( submission , function ( e , submission ) {
74- if ( e ) return done ( e ) ;
93+ if ( e ) return cb ( e ) ;
7594
76- fs . writeFileSync ( filename , submission . code ) ;
95+ problem . code = submission . code ;
96+ core . exportProblem ( problem , filename , ! argv . extra ) ;
7797
7898 if ( submission . state === 'Accepted' )
79- done ( null , chalk . green . underline ( filename ) ) ;
99+ cb ( null , chalk . green . underline ( filename ) ) ;
80100 else
81- done ( null , chalk . yellow . underline ( filename ) ) ;
101+ cb ( null , chalk . yellow . underline ( filename ) ) ;
82102 } ) ;
83103 } ) ;
84104}
85105
86106cmd . handler = function ( argv ) {
87- var doTask = _ . partial ( getSubmission , argv , _ , _ ) ;
107+ var doTask = _ . partial ( onTaskRun , argv , _ , _ ) ;
88108
89109 if ( argv . all ) {
90110 core . getProblems ( function ( e , problems ) {
0 commit comments