Skip to content

Commit 00c5b17

Browse files
committed
moved more logic from CLI to tmc-langs
1 parent 2ebed88 commit 00c5b17

File tree

13 files changed

+539
-429
lines changed

13 files changed

+539
-429
lines changed

tmc-client/src/tmc_client.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ impl TmcClient {
225225
None,
226226
);
227227

228+
// for each exercise, check if there's already something on disk
229+
// if yes, check if it needs updating
230+
// if not, check if there's a previous submission
231+
// if yes, download it
232+
// if not, download the exercise template
233+
228234
let thread_count = exercises_len.min(4); // max 4 threads
229235
let mut handles = vec![];
230236
let exercises = Arc::new(Mutex::new(exercises));
@@ -369,7 +375,7 @@ impl TmcClient {
369375

370376
pub fn get_exercises_details(
371377
&self,
372-
exercise_ids: Vec<usize>,
378+
exercise_ids: &[usize],
373379
) -> Result<Vec<ExercisesDetails>, ClientError> {
374380
self.core_exercise_details(exercise_ids)
375381
}

tmc-client/src/tmc_client/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ impl TmcClient {
658658

659659
pub(super) fn core_exercise_details(
660660
&self,
661-
exercise_ids: Vec<usize>,
661+
exercise_ids: &[usize],
662662
) -> Result<Vec<ExercisesDetails>, ClientError> {
663663
if self.0.token.is_none() {
664664
return Err(ClientError::NotLoggedIn);

tmc-langs-cli/src/app.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
//! Create clap app
22
3-
use crate::output::{
4-
CombinedCourseData, DownloadOrUpdateCourseExercisesResult, LocalExercise, UpdatedExercise,
5-
};
3+
use crate::output::{LocalExercise, UpdatedExercise};
64
use clap::{App, AppSettings, Arg, SubCommand};
75
use schemars::JsonSchema;
86
use std::path::PathBuf;
97
use tmc_langs::{
8+
data::{CombinedCourseData, DownloadOrUpdateCourseExercisesResult},
109
CourseData, CourseDetails, CourseExercise, ExerciseDesc, ExerciseDetails,
1110
ExercisePackagingConfiguration, NewSubmission, Organization, Review, RunResult,
1211
StyleValidationResult, Submission, SubmissionFeedbackResponse, SubmissionFinished,
@@ -311,7 +310,7 @@ fn create_core_app() -> App<'static, 'static> {
311310
.subcommand(SubCommand::with_name("download-old-submission")
312311
.about("Downloads an old submission. Resets the exercise at output-path if any, downloading the exercise base from the server. The old submission is then downloaded and extracted on top of the base, using the student file policy to retain student files")
313312
.long_about(SCHEMA_NULL)
314-
.arg(Arg::with_name("save-old-state")
313+
.arg(Arg::with_name("save-old-state") // TODO: unnecessary, remove (submission-url is enough, but probaly needs a rename if the flag is removed)
315314
.help("If set, the exercise is submitted to the server before resetting it.")
316315
.long("save-old-state")
317316
.requires("submission-url"))

tmc-langs-cli/src/error.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::path::PathBuf;
22
use thiserror::Error;
3-
4-
use crate::output::DownloadOrUpdateCourseExercise;
3+
use tmc_langs::ExerciseDownload;
54

65
#[derive(Debug, Error)]
76
#[error("Invalid token. Deleted credentials file")]
@@ -19,7 +18,7 @@ pub struct SandboxTestError {
1918
#[derive(Debug, Error)]
2019
#[error("Failed to download one or more exercises")]
2120
pub struct DownloadsFailedError {
22-
pub downloaded: Vec<DownloadOrUpdateCourseExercise>,
23-
pub skipped: Vec<DownloadOrUpdateCourseExercise>,
24-
pub failed: Vec<(DownloadOrUpdateCourseExercise, Vec<String>)>,
21+
pub downloaded: Vec<ExerciseDownload>,
22+
pub skipped: Vec<ExerciseDownload>,
23+
pub failed: Vec<(ExerciseDownload, Vec<String>)>,
2524
}

0 commit comments

Comments
 (0)