Skip to content

Commit 5ff0a06

Browse files
authored
Merge pull request #19 from rage/work
Work
2 parents 87e3ebf + 7c48c4a commit 5ff0a06

18 files changed

Lines changed: 159 additions & 155 deletions

src/commands/courses.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ mod tests {
2323
use super::*;
2424
use isolang::Language;
2525
use reqwest::Url;
26-
use std::path::Path;
27-
use std::slice::Iter;
28-
use tmc_langs::ClientError;
29-
use tmc_langs::DownloadOrUpdateCourseExercisesResult;
30-
use tmc_langs::DownloadResult;
31-
use tmc_langs::LangsError;
26+
use std::{path::Path, slice::Iter};
3227
use tmc_langs::{
33-
CourseDetails, CourseExercise, ExercisesDetails, NewSubmission, Organization,
28+
ClientError, CourseDetails, CourseExercise, DownloadOrUpdateCourseExercisesResult,
29+
DownloadResult, ExercisesDetails, LangsError, NewSubmission, Organization,
3430
SubmissionFinished, SubmissionStatus,
3531
};
3632
pub struct IoTest<'a> {
@@ -131,7 +127,7 @@ mod tests {
131127
&mut self,
132128
_path: &Path,
133129
) -> Result<DownloadOrUpdateCourseExercisesResult, LangsError> {
134-
todo!()
130+
unimplemented!()
135131
}
136132
fn submit(
137133
&self,
@@ -184,7 +180,7 @@ mod tests {
184180
&mut self,
185181
_exercise_ids: Vec<u32>,
186182
) -> Result<Vec<ExercisesDetails>, ClientError> {
187-
todo!()
183+
unimplemented!()
188184
}
189185

190186
fn download_or_update_exercises(
@@ -199,10 +195,10 @@ mod tests {
199195
}
200196

201197
fn get_course_details(&self, _: u32) -> std::result::Result<CourseDetails, ClientError> {
202-
todo!()
198+
unimplemented!()
203199
}
204200
fn get_organization(&self, _: &str) -> std::result::Result<Organization, ClientError> {
205-
todo!()
201+
unimplemented!()
206202
}
207203
}
208204

src/commands/download.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
use super::util;
2-
use super::util::{get_organization, get_projects_dir, Client};
3-
use crate::interactive;
4-
use crate::io::{Io, PrintColor};
5-
use crate::progress_reporting;
6-
use crate::progress_reporting::ProgressBarManager;
1+
use super::{
2+
util,
3+
util::{get_organization, get_projects_dir, Client},
4+
};
5+
use crate::{
6+
interactive,
7+
io::{Io, PrintColor},
8+
progress_reporting,
9+
progress_reporting::ProgressBarManager,
10+
};
711
use anyhow::Context;
8-
use std::path::Path;
9-
use std::process::Command;
10-
use tmc_langs::ClientUpdateData;
11-
use tmc_langs::Course;
12-
use tmc_langs::DownloadResult;
12+
use std::{path::Path, process::Command};
13+
use tmc_langs::{ClientUpdateData, Course, DownloadResult};
1314

1415
// Downloads course exercises
1516
// course_name as None will trigger interactive menu for selecting a course
@@ -234,8 +235,7 @@ pub fn elevated_download(io: &mut dyn Io, client: &mut dyn Client) -> anyhow::Re
234235
}
235236

236237
fn pause() -> anyhow::Result<()> {
237-
use std::io;
238-
use std::io::prelude::*;
238+
use std::{io, io::prelude::*};
239239
let stdin = io::stdin();
240240
let mut stdout = io::stdout();
241241
write!(stdout, "Press any enter to continue...")?;

src/commands/exercises.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,15 @@ fn print_exercises(
8888

8989
#[cfg(test)]
9090
mod tests {
91+
use super::*;
9192
use isolang::Language;
9293
use reqwest::Url;
93-
use std::path::Path;
94-
use tmc_langs::ClientError;
95-
use tmc_langs::DownloadOrUpdateCourseExercisesResult;
96-
use tmc_langs::DownloadResult;
97-
use tmc_langs::LangsError;
94+
use std::{path::Path, slice::Iter};
9895
use tmc_langs::{
99-
Course, CourseDetails, CourseExercise, ExercisesDetails, NewSubmission, Organization,
96+
ClientError, Course, CourseDetails, CourseExercise, DownloadOrUpdateCourseExercisesResult,
97+
DownloadResult, ExercisesDetails, LangsError, NewSubmission, Organization,
10098
SubmissionFinished, SubmissionStatus,
10199
};
102-
103-
use super::*;
104-
use std::slice::Iter;
105100
pub struct IoTest<'a> {
106101
list: &'a mut Vec<String>,
107102
input: &'a mut Iter<'a, &'a str>,
@@ -315,13 +310,13 @@ mod tests {
315310
&mut self,
316311
_exercise_ids: Vec<u32>,
317312
) -> Result<Vec<ExercisesDetails>, ClientError> {
318-
todo!()
313+
unimplemented!()
319314
}
320315
fn update_exercises(
321316
&mut self,
322317
_path: &Path,
323318
) -> Result<DownloadOrUpdateCourseExercisesResult, LangsError> {
324-
todo!()
319+
unimplemented!()
325320
}
326321
fn download_or_update_exercises(
327322
&mut self,
@@ -335,10 +330,10 @@ mod tests {
335330
}
336331

337332
fn get_course_details(&self, _: u32) -> Result<CourseDetails, ClientError> {
338-
todo!()
333+
unimplemented!()
339334
}
340335
fn get_organization(&self, _: &str) -> Result<Organization, ClientError> {
341-
todo!()
336+
unimplemented!()
342337
}
343338
}
344339

src/commands/login.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use anyhow::Context;
2-
3-
use super::util::Client;
4-
use super::{download, organization, util};
1+
use super::{download, organization, util, util::Client};
52
use crate::io::{Io, PrintColor};
3+
use anyhow::Context;
64

75
pub fn login(
86
io: &mut dyn Io,
@@ -98,8 +96,7 @@ pub fn download_after_login(client: &mut dyn Client, io: &mut dyn Io) -> anyhow:
9896

9997
#[cfg(test)]
10098
mod tests {
101-
use super::super::util::*;
102-
use super::*;
99+
use super::{super::util::*, *};
103100
use std::slice::Iter;
104101
use tmc_langs::Organization;
105102

src/commands/logout.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ pub fn logout(io: &mut dyn Io, client: &mut dyn Client) -> anyhow::Result<()> {
99

1010
#[cfg(test)]
1111
mod tests {
12-
use super::super::util::*;
13-
use super::*;
12+
use super::{super::util::*, *};
1413
use std::slice::Iter;
1514

1615
pub struct IoTest<'a> {

src/commands/organization.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use super::util;
2-
use super::util::Client;
3-
use crate::interactive::{self, interactive_list};
4-
use crate::io::{Io, PrintColor};
1+
use super::{util, util::Client};
2+
use crate::{
3+
interactive::{self, interactive_list},
4+
io::{Io, PrintColor},
5+
};
56

67
// Asks for organization from user and saves it into file
78
pub fn set_organization_old(io: &mut dyn Io, client: &mut dyn Client) -> anyhow::Result<String> {
@@ -54,11 +55,15 @@ pub fn set_organization(io: &mut dyn Io, client: &mut dyn Client) -> anyhow::Res
5455

5556
let prompt = String::from("Select your organization: ");
5657
let mut org_name = match interactive::interactive_list(&prompt, pinned)? {
57-
Some(result) if result.eq(&others) => {
58-
let all = orgs.iter().map(|org| org.name.clone()).collect();
59-
interactive_list(&prompt, all)?
58+
Some(result) => {
59+
if result.eq(&others) {
60+
let all = orgs.iter().map(|org| org.name.clone()).collect();
61+
interactive_list(&prompt, all)?
62+
} else {
63+
Some(result)
64+
}
6065
}
61-
_ => todo!(),
66+
None => anyhow::bail!("No organization chosen"),
6267
};
6368

6469
org_name = match org_name {

src/commands/paste.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use super::util;
2-
use super::util::Client;
3-
use crate::io::{Io, PrintColor};
4-
use crate::progress_reporting;
5-
use crate::progress_reporting::ProgressBarManager;
1+
use super::{util, util::Client};
2+
use crate::{
3+
io::{Io, PrintColor},
4+
progress_reporting,
5+
progress_reporting::ProgressBarManager,
6+
};
67
use anyhow::Context;
78
use isolang::Language;
89
use tmc_langs::ClientUpdateData;

src/commands/submit.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
use super::util;
2-
use super::util::Client;
3-
use crate::io::{Io, PrintColor};
4-
use crate::progress_reporting;
5-
use crate::progress_reporting::ProgressBarManager;
1+
use super::{util, util::Client};
2+
use crate::{
3+
io::{Io, PrintColor},
4+
progress_reporting,
5+
progress_reporting::ProgressBarManager,
6+
};
67
use anyhow::{Context, Result};
78
use reqwest::Url;
8-
use tmc_langs::ClientUpdateData;
9-
use tmc_langs::Language;
10-
use tmc_langs::SubmissionFinished;
9+
use tmc_langs::{ClientUpdateData, Language, SubmissionFinished};
1110

1211
/// Sends the course exercise submission to the server.
1312
/// Path to the exercise can be given as a parameter or
@@ -17,7 +16,7 @@ use tmc_langs::SubmissionFinished;
1716
/// Returns an error if no exercise was found on given path or current folder.
1817
/// Returns an error if user is not logged in.
1918
pub fn submit(io: &mut dyn Io, client: &mut dyn Client, path: Option<&str>) -> anyhow::Result<()> {
20-
let locale = into_locale("fin").expect("fin is a valid locale");
19+
let locale = into_locale("fin").expect("The locale should always be valid.");
2120

2221
// todo: use context
2322
let exercise_path = util::exercise_pathfinder(path).context("Error finding exercise")?;

src/commands/test.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
use crate::commands::util;
2-
use crate::io::{Io, PrintColor};
1+
use crate::{
2+
commands::util,
3+
io::{Io, PrintColor},
4+
};
35
use anyhow::Context;
46
use std::path::Path;
57
use tmc_langs::RunResult;
@@ -129,8 +131,7 @@ mod tests {
129131
mod tests {
130132
use super::*;
131133
use std::collections::HashMap;
132-
use tmc_langs::RunStatus;
133-
use tmc_langs::TestResult;
134+
use tmc_langs::{RunStatus, TestResult};
134135

135136
#[test]
136137
fn generate_progress_string_empty_test() {

src/commands/update.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use anyhow::Context;
2-
31
use super::util::{get_projects_dir, Client};
42
use crate::io::{Io, PrintColor};
5-
use std::path::{Path, PathBuf};
6-
use std::process::Command;
3+
use anyhow::Context;
4+
use std::{
5+
path::{Path, PathBuf},
6+
process::Command,
7+
};
78

89
/// Updates exercises from project dir or current directory.
910
/// Update is ran only if local exercise checksums differ from
@@ -88,8 +89,7 @@ pub fn elevated_update(io: &mut dyn Io, client: &mut dyn Client) -> anyhow::Resu
8889
Ok(())
8990
}
9091
fn pause() -> anyhow::Result<()> {
91-
use std::io;
92-
use std::io::prelude::*;
92+
use std::{io, io::prelude::*};
9393
let mut stdin = io::stdin();
9494
let mut stdout = io::stdout();
9595
write!(stdout, "Press any enter to continue...")?;

0 commit comments

Comments
 (0)