Skip to content

Commit e01431a

Browse files
authored
Merge pull request #93 from rage/cli-to-lib
moved functionality from CLI binary to libraries
2 parents 553ab9a + d71fea8 commit e01431a

File tree

8 files changed

+1903
-1884
lines changed

8 files changed

+1903
-1884
lines changed

tmc-langs-cli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ base64 = "0.13"
2626
schemars = "0.8"
2727
thiserror = "1"
2828
toml = "0.5"
29-
heim = { version = "0.1.0-beta.3", features = ["disk"] }
3029
smol = "1"
3130

3231
[dev-dependencies]

tmc-langs-cli/src/config.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod tmc_config;
77
pub use self::credentials::Credentials;
88
pub use self::projects_config::{CourseConfig, Exercise, ProjectsConfig};
99
pub use self::tmc_config::{ConfigValue, TmcConfig};
10+
use crate::output::LocalExercise;
1011

1112
use anyhow::{Context, Error};
1213
use std::env;
@@ -20,3 +21,25 @@ fn get_tmc_dir(client_name: &str) -> Result<PathBuf, Error> {
2021
};
2122
Ok(config_dir.join(format!("tmc-{}", client_name)))
2223
}
24+
25+
pub fn list_local_course_exercises(
26+
client_name: &str,
27+
course_slug: &str,
28+
) -> Result<Vec<LocalExercise>, anyhow::Error> {
29+
let projects_dir = TmcConfig::load(client_name)?.projects_dir;
30+
let mut projects_config = ProjectsConfig::load(&projects_dir)?;
31+
32+
let exercises = projects_config
33+
.courses
34+
.remove(course_slug)
35+
.map(|cc| cc.exercises)
36+
.unwrap_or_default();
37+
let mut local_exercises: Vec<LocalExercise> = vec![];
38+
for (exercise_slug, _) in exercises {
39+
local_exercises.push(LocalExercise {
40+
exercise_path: projects_dir.join(course_slug).join(&exercise_slug),
41+
exercise_slug,
42+
})
43+
}
44+
Ok(local_exercises)
45+
}

0 commit comments

Comments
 (0)