Skip to content

Commit 9fb3fc6

Browse files
committed
added list-local-course-exercises
1 parent 86e0dbe commit 9fb3fc6

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

tmc-langs-cli/src/app.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Create clap app
22
3-
use crate::output::{CombinedCourseData, DownloadOrUpdateCourseExercisesResult};
3+
use crate::output::{CombinedCourseData, DownloadOrUpdateCourseExercisesResult, LocalExercise};
44
use clap::{App, AppSettings, Arg, SubCommand};
55
use schemars::JsonSchema;
66
use std::path::PathBuf;
@@ -122,6 +122,20 @@ pub fn create_app() -> App<'static, 'static> {
122122
.long("output-path")
123123
.takes_value(true)))
124124

125+
.subcommand(SubCommand::with_name("list-local-course-exercises")
126+
.about("Returns a list of local exercises for the given course")
127+
.long_about(schema_leaked::<Vec<LocalExercise>>())
128+
.arg(Arg::with_name("client-name")
129+
.help("The client for which exercises should be listed.")
130+
.long("client-name")
131+
.required(true)
132+
.takes_value(true))
133+
.arg(Arg::with_name("course-slug")
134+
.help("The course slug the local exercises of which should be listed.")
135+
.long("course-slug")
136+
.required(true)
137+
.takes_value(true)))
138+
125139
.subcommand(SubCommand::with_name("prepare-solutions")
126140
.about("Processes the exercise files in exercise-path, removing all code marked as stubs")
127141
.long_about(SCHEMA_NULL)

tmc-langs-cli/src/main.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use self::config::{CourseConfig, Credentials, Exercise, TmcConfig};
1010
use self::error::{InvalidTokenError, SandboxTestError};
1111
use self::output::{
1212
CombinedCourseData, DownloadOrUpdateCourseExercise, DownloadOrUpdateCourseExercisesResult,
13-
ErrorData, Kind, Output, OutputData, OutputResult, Status, Warnings,
13+
ErrorData, Kind, LocalExercise, Output, OutputData, OutputResult, Status, Warnings,
1414
};
1515
use anyhow::{Context, Result};
1616
use clap::{ArgMatches, Error, ErrorKind};
@@ -394,6 +394,36 @@ fn run_app(matches: ArgMatches, pretty: bool, warnings: &mut Vec<anyhow::Error>)
394394
});
395395
print_output(&output, pretty, &warnings)?
396396
}
397+
("list-local-course-exercises", Some(matches)) => {
398+
let client_name = matches.value_of("client-name").unwrap();
399+
400+
let course_slug = matches.value_of("course-slug").unwrap();
401+
402+
let projects_dir = TmcConfig::load(client_name)?.projects_dir;
403+
let mut projects_config = ProjectsConfig::load(&projects_dir)?;
404+
405+
let exercises = projects_config
406+
.courses
407+
.remove(course_slug)
408+
.map(|cc| cc.exercises)
409+
.unwrap_or_default();
410+
let mut local_exercises: Vec<LocalExercise> = vec![];
411+
for (exercise_slug, _) in exercises {
412+
local_exercises.push(LocalExercise {
413+
exercise_path: projects_dir.join(course_slug).join(&exercise_slug),
414+
exercise_slug,
415+
})
416+
}
417+
418+
let output = Output::OutputData(OutputData {
419+
status: Status::Finished,
420+
message: Some(format!("listed local exercises for {}", course_slug,)),
421+
result: OutputResult::ExecutedCommand,
422+
percent_done: 1.0,
423+
data: Some(local_exercises),
424+
});
425+
print_output(&output, pretty, &warnings)?
426+
}
397427
("prepare-solutions", Some(matches)) => {
398428
let exercise_path = matches.value_of("exercise-path").unwrap();
399429
let exercise_path = Path::new(exercise_path);

tmc-langs-cli/src/output.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ pub struct DownloadOrUpdateCourseExercise {
9292
pub exercise_slug: String,
9393
}
9494

95+
#[derive(Debug, Serialize, JsonSchema)]
96+
#[serde(rename_all = "kebab-case")]
97+
pub struct LocalExercise {
98+
pub exercise_slug: String,
99+
pub exercise_path: PathBuf,
100+
}
101+
95102
#[derive(Debug, Serialize)]
96103
pub struct DownloadTarget {
97104
pub id: usize,

0 commit comments

Comments
 (0)