@@ -24,11 +24,17 @@ var cmd = {
24
24
type : 'string' ,
25
25
describe : 'Where to save the submissions' ,
26
26
default : '.'
27
+ } ,
28
+ extra : {
29
+ alias : 'x' ,
30
+ type : 'boolean' ,
31
+ default : false ,
32
+ describe : 'Provide extra problem details in submission file'
27
33
}
28
34
}
29
35
} ;
30
36
31
- function getSubmissionDone ( e , msg , problem , cb ) {
37
+ function onTaskDone ( e , msg , problem , cb ) {
32
38
// NOTE: msg color means different purpose:
33
39
// - red: error
34
40
// - green: accepted, fresh download
@@ -42,12 +48,25 @@ function getSubmissionDone(e, msg, problem, cb) {
42
48
if ( cb ) cb ( e ) ;
43
49
}
44
50
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
+ }
47
65
66
+ function exportSubmission ( argv , problem , cb ) {
48
67
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?' ) ;
51
70
52
71
// find the latest accepted one
53
72
var submission = _ . find ( submissions , function ( x ) {
@@ -67,24 +86,25 @@ function getSubmission(argv, problem, cb) {
67
86
68
87
// skip the existing cached submissions
69
88
if ( fs . existsSync ( filename ) ) {
70
- return done ( null , chalk . underline ( filename ) ) ;
89
+ return cb ( null , chalk . underline ( filename ) ) ;
71
90
}
72
91
73
92
core . getSubmission ( submission , function ( e , submission ) {
74
- if ( e ) return done ( e ) ;
93
+ if ( e ) return cb ( e ) ;
75
94
76
- fs . writeFileSync ( filename , submission . code ) ;
95
+ problem . code = submission . code ;
96
+ core . exportProblem ( problem , filename , ! argv . extra ) ;
77
97
78
98
if ( submission . state === 'Accepted' )
79
- done ( null , chalk . green . underline ( filename ) ) ;
99
+ cb ( null , chalk . green . underline ( filename ) ) ;
80
100
else
81
- done ( null , chalk . yellow . underline ( filename ) ) ;
101
+ cb ( null , chalk . yellow . underline ( filename ) ) ;
82
102
} ) ;
83
103
} ) ;
84
104
}
85
105
86
106
cmd . handler = function ( argv ) {
87
- var doTask = _ . partial ( getSubmission , argv , _ , _ ) ;
107
+ var doTask = _ . partial ( onTaskRun , argv , _ , _ ) ;
88
108
89
109
if ( argv . all ) {
90
110
core . getProblems ( function ( e , problems ) {
0 commit comments