Skip to content

Commit 86e0dbe

Browse files
committed
return data from download-or-update-course-exercises
1 parent fed2a42 commit 86e0dbe

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

tmc-langs-cli/src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Create clap app
22
3-
use crate::output::CombinedCourseData;
3+
use crate::output::{CombinedCourseData, DownloadOrUpdateCourseExercisesResult};
44
use clap::{App, AppSettings, Arg, SubCommand};
55
use schemars::JsonSchema;
66
use std::path::PathBuf;
@@ -370,7 +370,7 @@ fn create_core_app() -> App<'static, 'static> {
370370

371371
.subcommand(SubCommand::with_name("download-or-update-course-exercises")
372372
.about("Downloads exercises. If downloading an exercise that has been downloaded before, the student file policy will be used to avoid overwriting student files, effectively just updating the exercise files")
373-
.long_about(SCHEMA_NULL)
373+
.long_about(schema_leaked::<DownloadOrUpdateCourseExercisesResult>())
374374
.arg(Arg::with_name("exercise-id")
375375
.help("Exercise id of an exercise that should be downloaded. Multiple ids can be given.")
376376
.long("exercise-id")

tmc-langs-cli/src/main.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use self::config::ProjectsConfig;
99
use self::config::{CourseConfig, Credentials, Exercise, TmcConfig};
1010
use self::error::{InvalidTokenError, SandboxTestError};
1111
use self::output::{
12-
CombinedCourseData, ErrorData, Kind, Output, OutputData, OutputResult, Status, Warnings,
12+
CombinedCourseData, DownloadOrUpdateCourseExercise, DownloadOrUpdateCourseExercisesResult,
13+
ErrorData, Kind, Output, OutputData, OutputResult, Status, Warnings,
1314
};
1415
use anyhow::{Context, Result};
1516
use clap::{ArgMatches, Error, ErrorKind};
@@ -818,6 +819,8 @@ fn run_core(
818819

819820
let mut course_data = HashMap::<String, Vec<(String, String)>>::new();
820821
let mut exercises_and_paths = vec![];
822+
let mut downloaded = vec![];
823+
let mut skipped = vec![];
821824
for exercise_detail in exercises_details {
822825
// check if the checksum is different from what's already on disk
823826
if let Some(course_config) =
@@ -834,10 +837,20 @@ fn run_core(
834837
exercise_detail.course_name,
835838
exercise_detail.exercise_name
836839
);
840+
skipped.push(DownloadOrUpdateCourseExercise {
841+
course_slug: exercise_detail.course_name,
842+
exercise_slug: exercise_detail.exercise_name,
843+
});
837844
continue;
838845
}
839846
}
840847
}
848+
// not skipped, will be downloaded
849+
// if any download fails, an error is returned instead, so it's ok to just push them to downloaded here
850+
downloaded.push(DownloadOrUpdateCourseExercise {
851+
course_slug: exercise_detail.course_name.clone(),
852+
exercise_slug: exercise_detail.exercise_name.clone(),
853+
});
841854

842855
let target = ProjectsConfig::get_exercise_download_target(
843856
&projects_dir,
@@ -873,12 +886,16 @@ fn run_core(
873886
};
874887
}
875888

876-
let output = Output::OutputData::<()>(OutputData {
889+
let data = DownloadOrUpdateCourseExercisesResult {
890+
downloaded,
891+
skipped,
892+
};
893+
let output = Output::OutputData(OutputData {
877894
status: Status::Finished,
878895
message: None,
879896
result: OutputResult::RetrievedData,
880897
percent_done: 1.0,
881-
data: None,
898+
data: Some(data),
882899
});
883900
print_output(&output, pretty, &warnings)?
884901
}

tmc-langs-cli/src/output.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ pub struct CombinedCourseData {
7979
pub settings: CourseData,
8080
}
8181

82+
#[derive(Debug, Serialize, JsonSchema)]
83+
pub struct DownloadOrUpdateCourseExercisesResult {
84+
pub downloaded: Vec<DownloadOrUpdateCourseExercise>,
85+
pub skipped: Vec<DownloadOrUpdateCourseExercise>,
86+
}
87+
88+
#[derive(Debug, Serialize, JsonSchema)]
89+
#[serde(rename_all = "kebab-case")]
90+
pub struct DownloadOrUpdateCourseExercise {
91+
pub course_slug: String,
92+
pub exercise_slug: String,
93+
}
94+
8295
#[derive(Debug, Serialize)]
8396
pub struct DownloadTarget {
8497
pub id: usize,

0 commit comments

Comments
 (0)