Skip to content

Commit 0d27a11

Browse files
authored
Merge pull request #22 from rage/sort
Sort
2 parents 5c1e548 + efdc2a3 commit 0d27a11

File tree

9 files changed

+45
-91
lines changed

9 files changed

+45
-91
lines changed

Cargo.lock

Lines changed: 23 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tmc"
3-
version = "1.0.5"
3+
version = "1.1.0"
44
authors = ["HoolaBoola <jaime.heikkiladias@helsinki.fi>",
55
"Robustic <juha.malinen@helsinki.fi>",
66
"ShootingStar91 <arttu.kangas@helsinki.fi>",

src/cli.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ pub fn build_cli() -> Command<'static> {
9292
.required(false),
9393
),
9494
)
95-
.subcommand(Command::new("update-exercises").about("Update exercises"))
9695
.arg(
9796
Arg::new("no-update")
9897
.short('d')

src/commands/courses.rs

Lines changed: 10 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
use super::util::Client;
22
use crate::io::{Io, PrintColor};
3-
use tmc_langs::Course;
43

54
/// Lists available courses from clients organization
65
pub fn list_courses(io: &mut dyn Io, client: &mut dyn Client) -> anyhow::Result<()> {
7-
let course_list = client.list_courses()?;
8-
print_courses(io, &course_list)?;
9-
Ok(())
10-
}
11-
12-
/// Prints course names
13-
fn print_courses(io: &mut dyn Io, course_list: &[Course]) -> anyhow::Result<()> {
6+
let mut course_list = client.list_courses()?;
7+
course_list.sort_unstable_by(|l, r| l.name.cmp(&r.name));
148
io.println("", PrintColor::Normal)?;
159
for course in course_list {
1610
io.println(&course.name, PrintColor::Normal)?;
@@ -24,7 +18,7 @@ mod tests {
2418
use reqwest::Url;
2519
use std::{path::Path, slice::Iter};
2620
use tmc_langs::{
27-
ClientError, CourseDetails, CourseExercise, DownloadOrUpdateCourseExercisesResult,
21+
ClientError, Course, CourseDetails, CourseExercise, DownloadOrUpdateCourseExercisesResult,
2822
DownloadResult, ExercisesDetails, LangsError, Language, NewSubmission, Organization,
2923
SubmissionFinished, SubmissionStatus,
3024
};
@@ -205,52 +199,6 @@ mod tests {
205199
mod tests {
206200
use super::*;
207201

208-
#[test]
209-
fn list_courses_test() {
210-
let mut v: Vec<String> = Vec::new();
211-
let input = vec![];
212-
let mut input = input.iter();
213-
214-
let mut io = IoTest {
215-
list: &mut v,
216-
input: &mut input,
217-
};
218-
219-
let courses = [
220-
Course {
221-
id: 0,
222-
name: "name".to_string(),
223-
title: "".to_string(),
224-
description: None,
225-
details_url: "".to_string(),
226-
unlock_url: "".to_string(),
227-
reviews_url: "".to_string(),
228-
comet_url: "".to_string(),
229-
spyware_urls: vec![],
230-
},
231-
Course {
232-
id: 10,
233-
name: "course of sorts".to_string(),
234-
title: "".to_string(),
235-
description: None,
236-
details_url: "".to_string(),
237-
unlock_url: "".to_string(),
238-
reviews_url: "".to_string(),
239-
comet_url: "".to_string(),
240-
spyware_urls: vec![],
241-
},
242-
];
243-
print_courses(&mut io, &courses).unwrap();
244-
245-
assert!(io.list[0].eq(""));
246-
assert!(io.list[1].eq("name"), "Expected 'name', got {}", io.list[1]);
247-
assert!(
248-
io.list[2].eq("course of sorts"),
249-
"Expected 'course of sorts', got {}",
250-
io.list[2]
251-
);
252-
}
253-
254202
#[test]
255203
fn list_courses_with_client_test() {
256204
let mut v: Vec<String> = Vec::new();
@@ -266,10 +214,14 @@ mod tests {
266214
list_courses(&mut io, &mut client).unwrap();
267215

268216
assert!(io.list[0].eq(""), "first line should be empty");
269-
assert!(io.list[1].eq("name"), "Expected 'name', got {}", io.list[1]);
270217
assert!(
271-
io.list[2].eq("mooc-tutustumiskurssi"),
272-
"Expected 'mooc-tutustumiskurssi', got '{}'",
218+
io.list[1].eq("mooc-tutustumiskurssi"),
219+
"Expected 'mooc-tutustumiskurssi', got {}",
220+
io.list[1]
221+
);
222+
assert!(
223+
io.list[2].eq("name"),
224+
"Expected 'name', got '{}'",
273225
io.list[2]
274226
);
275227
}

src/commands/download.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub fn download_exercises(
186186

187187
if !downloaded.is_empty() {
188188
res.push_str(&format!(
189-
"\n\nSuccessful downloads saved to {}\\",
189+
"\n\nSuccessful downloads saved to {}",
190190
path.display()
191191
));
192192
}
@@ -205,7 +205,7 @@ pub fn download_exercises(
205205
}
206206

207207
Ok(format!(
208-
"Exercises downloaded successfully to {}\\",
208+
"Exercises downloaded successfully to {}",
209209
path.display()
210210
))
211211
}

src/commands/exercises.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ pub fn list_exercises(
1414
};
1515
let course_id = course.id;
1616

17-
let exercises = client.get_course_exercises(course_id)?;
17+
let mut exercises = client.get_course_exercises(course_id)?;
18+
exercises.sort_unstable_by(|l, r| l.name.cmp(&r.name));
1819
print_exercises(io, course_name, exercises)?;
1920
Ok(())
2021
}

src/commands/organization.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
pub fn set_organization_old(io: &mut dyn Io, client: &mut dyn Client) -> anyhow::Result<String> {
99
// List all organizations
1010
let mut orgs = client.get_organizations()?;
11-
orgs.sort_by(|a, b| b.pinned.cmp(&a.pinned));
11+
orgs.sort_by(|a, b| b.pinned.cmp(&a.pinned).then(b.name.cmp(&a.name)));
1212
let mut last_pinned = true;
1313

1414
io.println("Available Organizations:", PrintColor::Normal)?;
@@ -42,14 +42,13 @@ pub fn set_organization_old(io: &mut dyn Io, client: &mut dyn Client) -> anyhow:
4242
pub fn set_organization(io: &mut dyn Io, client: &mut dyn Client) -> anyhow::Result<String> {
4343
io.println("Fetching organizations...", PrintColor::Normal)?;
4444
let mut orgs = client.get_organizations()?;
45+
orgs.sort_by(|a, b| b.pinned.cmp(&a.pinned).then(a.name.cmp(&b.name)));
4546
let mut pinned = orgs
4647
.iter()
4748
.filter(|org| org.pinned)
4849
.map(|org| org.name.clone())
4950
.collect::<Vec<_>>();
5051

51-
orgs.sort_by(|a, b| b.pinned.cmp(&a.pinned));
52-
5352
let others = String::from("View all organizations");
5453
pinned.push(others.clone());
5554

src/commands/update.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ pub fn update(io: &mut dyn Io, client: &mut dyn Client, currentdir: bool) -> any
6565
}
6666
Ok(())
6767
}
68+
6869
fn call_update(path: &Path, client: &mut dyn Client) -> anyhow::Result<String> {
6970
client.update_exercises(path)?;
7071
Ok(format!(
71-
"Exercises updated succesfully to {}\\",
72+
"Exercises updated succesfully to {}",
7273
path.to_str().context("invalid path")?
7374
))
7475
}
@@ -88,6 +89,7 @@ pub fn elevated_update(io: &mut dyn Io, client: &mut dyn Client) -> anyhow::Resu
8889
pause()?;
8990
Ok(())
9091
}
92+
9193
fn pause() -> anyhow::Result<()> {
9294
use std::{io, io::prelude::*};
9395
let mut stdin = io::stdin();

src/updater.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pub fn process_update() -> anyhow::Result<()> {
8888
println!("Update completed succesfully!");
8989
Ok(())
9090
}
91+
9192
fn elevate(command: String) -> anyhow::Result<()> {
9293
Command::new("powershell")
9394
.args(&[
@@ -102,6 +103,7 @@ fn elevate(command: String) -> anyhow::Result<()> {
102103
.context("launch failure")?;
103104
Ok(())
104105
}
106+
105107
fn is_it_time_yet() -> anyhow::Result<bool> {
106108
let config = TmcConfig::load(PLUGIN, get_path()?.as_path())?;
107109

0 commit comments

Comments
 (0)