Skip to content

Commit ef14cb1

Browse files
authored
Merge pull request #34 from timle1029/add-lang-selection-for-submission
Language selection for submission command
2 parents 1cf4df1 + 042a70e commit ef14cb1

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

lib/commands/submission.js

+18-5
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,21 +74,28 @@ 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+
return argv.lang === 'all' || argv.lang === x.lang;
80+
});
81+
if (submissionInTargetType.length === 0) {
82+
return cb("No previous submission in required language.");
83+
}
84+
var submission = _.find(submissionInTargetType, function(x) {
7485
return x.status_display === 'Accepted';
7586
});
7687

88+
var submissionState = submission === undefined ? 'notac' : 'ac';
89+
7790
// if no accepted, use the latest non-accepted one
78-
submission = submission || submissions[0];
91+
submission = submission || submissionInTargetType[0];
7992

8093
var filename = sprintf('%s/%d.%s.%s.%s%s',
8194
argv.outdir,
8295
problem.id,
8396
problem.key,
8497
submission.id,
85-
problem.state,
98+
submissionState,
8699
h.langToExt(submission.lang));
87100

88101
// skip the existing cached submissions

0 commit comments

Comments
 (0)