diff --git a/Cargo.lock b/Cargo.lock index 88e0178..8ddbbfe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -190,9 +190,9 @@ dependencies = [ [[package]] name = "blocking" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046e47d4b2d391b1f6f8b407b1deb8dee56c1852ccd868becf2710f601b5f427" +checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" dependencies = [ "async-channel", "async-task", @@ -381,9 +381,9 @@ dependencies = [ [[package]] name = "crossterm" -version = "0.23.0" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b75a27dc8d220f1f8521ea69cd55a34d720a200ebb3a624d9aa19193d3b432" +checksum = "f1fd7173631a4e9e2ca8b32ae2fad58aab9843ea5aaf56642661937d87e28a3e" dependencies = [ "bitflags", "crossterm_winapi", @@ -483,9 +483,9 @@ checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541" [[package]] name = "dyn-clone" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2626afccd7561a06cf1367e2950c4718ea04565e20fb5029b6c7d8ad09abcf" +checksum = "21e50f3adc76d6a43f5ed73b698a87d0760ca74617f60f7c3b879003536fdd28" [[package]] name = "either" @@ -987,9 +987,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.119" +version = "0.2.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" +checksum = "ad5c14e80759d0939d013e6ca49930e59fc53dd8e5009132f76240c179380c09" [[package]] name = "libloading" @@ -1141,13 +1141,12 @@ dependencies = [ [[package]] name = "nom" -version = "7.1.0" +version = "7.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" dependencies = [ "memchr", "minimal-lexical", - "version_check", ] [[package]] @@ -1487,9 +1486,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.9" +version = "0.11.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f242f1488a539a79bac6dbe7c8609ae43b7914b7736210f239a37cccb32525" +checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb" dependencies = [ "base64", "bytes", @@ -1551,9 +1550,9 @@ dependencies = [ [[package]] name = "rpassword" -version = "6.0.0" +version = "6.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b7ef46d67d4cecf32ad486814d625738e79e4ccd62531dde0548b2f242f894" +checksum = "2bf099a1888612545b683d2661a1940089f6c2e5a8e38979b2159da876bfd956" dependencies = [ "libc", "serde", @@ -1595,9 +1594,9 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "0.2.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9" +checksum = "1ee86d63972a7c661d1536fefe8c3c8407321c3df668891286de28abcd087360" dependencies = [ "base64", ] @@ -1885,9 +1884,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.86" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" +checksum = "ebd69e719f31e88618baa1eaa6ee2de5c9a1c004f1e9ecdb58e8352a13f20a01" dependencies = [ "proc-macro2", "quote", @@ -1998,17 +1997,17 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tmc" -version = "1.0.5" +version = "1.1.0" dependencies = [ "anyhow", "assert_cmd", "clap", "clap_complete", - "crossterm 0.23.0", + "crossterm 0.23.1", "indicatif", "predicates", "reqwest", - "rpassword 6.0.0", + "rpassword 6.0.1", "serde", "serde_json", "termcolor", @@ -2688,9 +2687,9 @@ checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" [[package]] name = "winreg" -version = "0.7.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ "winapi", ] diff --git a/Cargo.toml b/Cargo.toml index 609832b..9303579 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tmc" -version = "1.0.5" +version = "1.1.0" authors = ["HoolaBoola ", "Robustic ", "ShootingStar91 ", diff --git a/src/cli.rs b/src/cli.rs index 0126757..f9c110c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -92,7 +92,6 @@ pub fn build_cli() -> Command<'static> { .required(false), ), ) - .subcommand(Command::new("update-exercises").about("Update exercises")) .arg( Arg::new("no-update") .short('d') diff --git a/src/commands/courses.rs b/src/commands/courses.rs index 11a6509..d2980c0 100644 --- a/src/commands/courses.rs +++ b/src/commands/courses.rs @@ -1,16 +1,10 @@ use super::util::Client; use crate::io::{Io, PrintColor}; -use tmc_langs::Course; /// Lists available courses from clients organization pub fn list_courses(io: &mut dyn Io, client: &mut dyn Client) -> anyhow::Result<()> { - let course_list = client.list_courses()?; - print_courses(io, &course_list)?; - Ok(()) -} - -/// Prints course names -fn print_courses(io: &mut dyn Io, course_list: &[Course]) -> anyhow::Result<()> { + let mut course_list = client.list_courses()?; + course_list.sort_unstable_by(|l, r| l.name.cmp(&r.name)); io.println("", PrintColor::Normal)?; for course in course_list { io.println(&course.name, PrintColor::Normal)?; @@ -24,7 +18,7 @@ mod tests { use reqwest::Url; use std::{path::Path, slice::Iter}; use tmc_langs::{ - ClientError, CourseDetails, CourseExercise, DownloadOrUpdateCourseExercisesResult, + ClientError, Course, CourseDetails, CourseExercise, DownloadOrUpdateCourseExercisesResult, DownloadResult, ExercisesDetails, LangsError, Language, NewSubmission, Organization, SubmissionFinished, SubmissionStatus, }; @@ -205,52 +199,6 @@ mod tests { mod tests { use super::*; - #[test] - fn list_courses_test() { - let mut v: Vec = Vec::new(); - let input = vec![]; - let mut input = input.iter(); - - let mut io = IoTest { - list: &mut v, - input: &mut input, - }; - - let courses = [ - Course { - id: 0, - name: "name".to_string(), - title: "".to_string(), - description: None, - details_url: "".to_string(), - unlock_url: "".to_string(), - reviews_url: "".to_string(), - comet_url: "".to_string(), - spyware_urls: vec![], - }, - Course { - id: 10, - name: "course of sorts".to_string(), - title: "".to_string(), - description: None, - details_url: "".to_string(), - unlock_url: "".to_string(), - reviews_url: "".to_string(), - comet_url: "".to_string(), - spyware_urls: vec![], - }, - ]; - print_courses(&mut io, &courses).unwrap(); - - assert!(io.list[0].eq("")); - assert!(io.list[1].eq("name"), "Expected 'name', got {}", io.list[1]); - assert!( - io.list[2].eq("course of sorts"), - "Expected 'course of sorts', got {}", - io.list[2] - ); - } - #[test] fn list_courses_with_client_test() { let mut v: Vec = Vec::new(); @@ -266,10 +214,14 @@ mod tests { list_courses(&mut io, &mut client).unwrap(); assert!(io.list[0].eq(""), "first line should be empty"); - assert!(io.list[1].eq("name"), "Expected 'name', got {}", io.list[1]); assert!( - io.list[2].eq("mooc-tutustumiskurssi"), - "Expected 'mooc-tutustumiskurssi', got '{}'", + io.list[1].eq("mooc-tutustumiskurssi"), + "Expected 'mooc-tutustumiskurssi', got {}", + io.list[1] + ); + assert!( + io.list[2].eq("name"), + "Expected 'name', got '{}'", io.list[2] ); } diff --git a/src/commands/download.rs b/src/commands/download.rs index ec42a04..8d489a6 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -186,7 +186,7 @@ pub fn download_exercises( if !downloaded.is_empty() { res.push_str(&format!( - "\n\nSuccessful downloads saved to {}\\", + "\n\nSuccessful downloads saved to {}", path.display() )); } @@ -205,7 +205,7 @@ pub fn download_exercises( } Ok(format!( - "Exercises downloaded successfully to {}\\", + "Exercises downloaded successfully to {}", path.display() )) } diff --git a/src/commands/exercises.rs b/src/commands/exercises.rs index a95bf1e..06b3759 100644 --- a/src/commands/exercises.rs +++ b/src/commands/exercises.rs @@ -14,7 +14,8 @@ pub fn list_exercises( }; let course_id = course.id; - let exercises = client.get_course_exercises(course_id)?; + let mut exercises = client.get_course_exercises(course_id)?; + exercises.sort_unstable_by(|l, r| l.name.cmp(&r.name)); print_exercises(io, course_name, exercises)?; Ok(()) } diff --git a/src/commands/organization.rs b/src/commands/organization.rs index b0b13c5..99fbc9a 100644 --- a/src/commands/organization.rs +++ b/src/commands/organization.rs @@ -8,7 +8,7 @@ use crate::{ pub fn set_organization_old(io: &mut dyn Io, client: &mut dyn Client) -> anyhow::Result { // List all organizations let mut orgs = client.get_organizations()?; - orgs.sort_by(|a, b| b.pinned.cmp(&a.pinned)); + orgs.sort_by(|a, b| b.pinned.cmp(&a.pinned).then(b.name.cmp(&a.name))); let mut last_pinned = true; io.println("Available Organizations:", PrintColor::Normal)?; @@ -42,14 +42,13 @@ pub fn set_organization_old(io: &mut dyn Io, client: &mut dyn Client) -> anyhow: pub fn set_organization(io: &mut dyn Io, client: &mut dyn Client) -> anyhow::Result { io.println("Fetching organizations...", PrintColor::Normal)?; let mut orgs = client.get_organizations()?; + orgs.sort_by(|a, b| b.pinned.cmp(&a.pinned).then(a.name.cmp(&b.name))); let mut pinned = orgs .iter() .filter(|org| org.pinned) .map(|org| org.name.clone()) .collect::>(); - orgs.sort_by(|a, b| b.pinned.cmp(&a.pinned)); - let others = String::from("View all organizations"); pinned.push(others.clone()); diff --git a/src/commands/update.rs b/src/commands/update.rs index 0cfe122..fe087fe 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -65,10 +65,11 @@ pub fn update(io: &mut dyn Io, client: &mut dyn Client, currentdir: bool) -> any } Ok(()) } + fn call_update(path: &Path, client: &mut dyn Client) -> anyhow::Result { client.update_exercises(path)?; Ok(format!( - "Exercises updated succesfully to {}\\", + "Exercises updated succesfully to {}", path.to_str().context("invalid path")? )) } @@ -88,6 +89,7 @@ pub fn elevated_update(io: &mut dyn Io, client: &mut dyn Client) -> anyhow::Resu pause()?; Ok(()) } + fn pause() -> anyhow::Result<()> { use std::{io, io::prelude::*}; let mut stdin = io::stdin(); diff --git a/src/updater.rs b/src/updater.rs index 0e6422d..1d836d0 100644 --- a/src/updater.rs +++ b/src/updater.rs @@ -88,6 +88,7 @@ pub fn process_update() -> anyhow::Result<()> { println!("Update completed succesfully!"); Ok(()) } + fn elevate(command: String) -> anyhow::Result<()> { Command::new("powershell") .args(&[ @@ -102,6 +103,7 @@ fn elevate(command: String) -> anyhow::Result<()> { .context("launch failure")?; Ok(()) } + fn is_it_time_yet() -> anyhow::Result { let config = TmcConfig::load(PLUGIN, get_path()?.as_path())?;