Skip to content

Commit 4191f8e

Browse files
committed
get-course-settings
1 parent 23d32f0 commit 4191f8e

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

tmc-langs-cli/src/app.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ pub fn create_app() -> App<'static, 'static> {
254254
.required(true)
255255
.takes_value(true)))
256256

257+
.subcommand(SubCommand::with_name("get-course-settings")
258+
.about("Get course settings.")
259+
.arg(Arg::with_name("course-id")
260+
.help("The ID of the course.")
261+
.long("course-id")
262+
.required(true)
263+
.takes_value(true)))
264+
257265
.subcommand(SubCommand::with_name("paste")
258266
.about("Send exercise to pastebin with comment.")
259267
.arg(Arg::with_name("submission-url")

tmc-langs-cli/src/main.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,19 @@ fn run() -> Result<()> {
656656
data: Some(courses),
657657
};
658658
print_output(&output)?;
659+
} else if let Some(matches) = matches.subcommand_matches("get-course-settings") {
660+
let course_id = matches.value_of("course-id").unwrap();
661+
let course_id = into_usize(course_id)?;
662+
let course = core.get_course(course_id).context("Failed to get course")?;
663+
664+
let output = Output {
665+
status: Status::Successful,
666+
message: None,
667+
result: OutputResult::RetrievedData,
668+
percent_done: 1.0,
669+
data: Some(course),
670+
};
671+
print_output(&output)?;
659672
} else if let Some(matches) = matches.subcommand_matches("paste") {
660673
let submission_url = matches.value_of("submission-url").unwrap();
661674
let submission_url = into_url(submission_url)?;

tmc-langs-core/src/response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub struct Course {
8787
pub spyware_urls: Vec<String>,
8888
}
8989

90-
#[derive(Debug, Deserialize)]
90+
#[derive(Debug, Deserialize, Serialize)]
9191
pub struct CourseData {
9292
pub name: String,
9393
//pub hide_after

tmc-langs-core/src/tmc_core.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,13 @@ impl TmcCore {
327327
self.organization_courses(organization_slug)
328328
}
329329

330+
pub fn get_course(&self, course_id: usize) -> Result<CourseData> {
331+
if self.token.is_none() {
332+
return Err(CoreError::AuthRequired);
333+
}
334+
self.course(course_id)
335+
}
336+
330337
/// Sends the given submission as a paste.
331338
///
332339
/// # Errors

0 commit comments

Comments
 (0)