Skip to content

Commit ebf5933

Browse files
author
Jiati Le
committed
Add an option -l for submission command which allows user to retrive recent submission in requried programming language, if no submissino in required language, an error will be printed. If no language is specified, program will retrive retrive most recent accepted submission.
1 parent 1cf4df1 commit ebf5933

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/commands/submission.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ var cmd = {
3030
type: 'boolean',
3131
default: false,
3232
describe: 'Provide extra problem details in submission file'
33+
},
34+
lang: {
35+
alias: 'l',
36+
type: 'string',
37+
default: 'all',
38+
describe: 'Programming language used for previous submission'
3339
}
3440
}
3541
};
@@ -68,9 +74,17 @@ function exportSubmission(argv, problem, cb) {
6874
if (e) return cb(e);
6975
if (submissions.length === 0) return cb('no submissions?');
7076

71-
// find the latest accepted one
72-
var submission = _.find(submissions, function(x) {
73-
// TODO: select by lang?
77+
// get obj list contain required filetype
78+
var submissionInTargetType = _.filter(submissions, function(x) {
79+
if (argv.lang === 'all') {
80+
return true;
81+
}
82+
return argv.lang === x.lang;
83+
});
84+
if (submissionInTargetType.length === 0) {
85+
return cb("No previous submission in required language.");
86+
}
87+
var submission = _.find(submissionInTargetType, function(x) {
7488
return x.status_display === 'Accepted';
7589
});
7690

0 commit comments

Comments
 (0)