diff --git a/lib/commands/submission.js b/lib/commands/submission.js index badb4c64..63afcf43 100644 --- a/lib/commands/submission.js +++ b/lib/commands/submission.js @@ -30,6 +30,12 @@ var cmd = { type: 'boolean', default: false, describe: 'Provide extra problem details in submission file' + }, + lang: { + alias: 'l', + type: 'string', + default: 'all', + describe: 'Programming language used for previous submission' } } }; @@ -68,21 +74,28 @@ function exportSubmission(argv, problem, cb) { if (e) return cb(e); if (submissions.length === 0) return cb('no submissions?'); - // find the latest accepted one - var submission = _.find(submissions, function(x) { - // TODO: select by lang? + // get obj list contain required filetype + var submissionInTargetType = _.filter(submissions, function(x) { + return argv.lang === 'all' || argv.lang === x.lang; + }); + if (submissionInTargetType.length === 0) { + return cb("No previous submission in required language."); + } + var submission = _.find(submissionInTargetType, function(x) { return x.status_display === 'Accepted'; }); + var submissionState = submission === undefined ? 'notac' : 'ac'; + // if no accepted, use the latest non-accepted one - submission = submission || submissions[0]; + submission = submission || submissionInTargetType[0]; var filename = sprintf('%s/%d.%s.%s.%s%s', argv.outdir, problem.id, problem.key, submission.id, - problem.state, + submissionState, h.langToExt(submission.lang)); // skip the existing cached submissions