Skip to content

Commit d60bbe4

Browse files
authored
Merge pull request #141 from rage/etc
added tests and docs, fixed bugs
2 parents 4999e69 + d3d1018 commit d60bbe4

File tree

56 files changed

+491
-502
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+491
-502
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ A "frontend" for tmc-langs. A binary CLI client for TMC-langs for IDEs. Intended
7272

7373
### tmc-langs
7474

75-
The "backend". A library that provides a convenient API for implementing different frontends. A frontend (such as a CLI) should only depend on this and optionally the util library.
75+
The "backend". A library that provides a convenient API for implementing different frontends. A frontend (such as a CLI) should only depend on this.
7676

7777
### tmc-client
7878

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
6+
</packageSources>
7+
</configuration>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
6+
</packageSources>
7+
</configuration>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
6+
</packageSources>
7+
</configuration>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
6+
</packageSources>
7+
</configuration>

tmc-client/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ pub enum ClientError {
5757
CacheDir,
5858
#[error("No values found in exercise details map returned by server")]
5959
MissingDetailsValue,
60+
#[error("List of exercises given was empty")]
61+
NoExercisesGiven,
6062

6163
#[error(transparent)]
6264
SystemTime(#[from] std::time::SystemTimeError),

tmc-client/src/tmc_client.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ use std::sync::Arc;
1818
use std::thread;
1919
use std::time::Duration;
2020
use tempfile::NamedTempFile;
21-
use tmc_langs_util::{file_util, progress_reporter, FileError};
22-
use walkdir::WalkDir;
21+
use tmc_langs_util::{progress_reporter, FileError};
2322

2423
/// Authentication token.
2524
pub type Token =
@@ -347,37 +346,6 @@ impl TmcClient {
347346
Ok(result)
348347
}
349348

350-
pub fn reset(&self, exercise_id: usize, exercise_path: PathBuf) -> Result<(), ClientError> {
351-
// clear out the exercise directory
352-
if exercise_path.exists() {
353-
let mut tries = 0;
354-
for entry in WalkDir::new(&exercise_path).min_depth(1) {
355-
let entry = entry?;
356-
log::debug!("{:?}", entry);
357-
// windows sometimes fails due to files being in use, retry a few times
358-
// todo: handle properly
359-
if entry.path().is_dir() {
360-
while let Err(err) = file_util::remove_dir_all(entry.path()) {
361-
tries += 1;
362-
if tries > 8 {
363-
return Err(ClientError::FileError(err));
364-
}
365-
thread::sleep(Duration::from_secs(1));
366-
}
367-
} else {
368-
while let Err(err) = file_util::remove_file(entry.path()) {
369-
tries += 1;
370-
if tries > 8 {
371-
return Err(ClientError::FileError(err));
372-
}
373-
thread::sleep(Duration::from_secs(1));
374-
}
375-
}
376-
}
377-
}
378-
self.download_exercise(exercise_id, &exercise_path)
379-
}
380-
381349
pub fn download_old_submission(
382350
&self,
383351
submission_id: usize,

tmc-client/src/tmc_client/api.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,10 @@ impl TmcClient {
659659
if self.0.token.is_none() {
660660
return Err(ClientError::NotLoggedIn);
661661
}
662+
if exercise_ids.is_empty() {
663+
return Err(ClientError::NoExercisesGiven);
664+
}
665+
662666
let url_tail = "core/exercises/details";
663667
let exercise_ids = (
664668
"ids".to_string(),

tmc-langs-cli/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ fn run_core(
10591059
}
10601060

10611061
// reset exercise
1062-
client.reset(exercise_id, exercise_path)?;
1062+
tmc_langs::reset(&client, exercise_id, exercise_path)?;
10631063

10641064
let output = Output::finished_with_data("reset exercise", None);
10651065
print_output(&output, pretty)?

tmc-langs-plugins/src/tmc_zip.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ where
168168
Ok(())
169169
}
170170

171+
// TODO: make more robust, use language plugins?
171172
fn find_project_dir<R: Read + Seek>(zip_archive: &mut ZipArchive<R>) -> Result<PathBuf, TmcError> {
172173
for i in 0..zip_archive.len() {
173174
let file = zip_archive.by_index(i)?;

0 commit comments

Comments
 (0)