1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
use std::fs;
use anyhow::{Context, Result};
use crate::{
cargo_toml::updated_cargo_toml,
info_file::{ExerciseInfo, InfoFile},
DEBUG_PROFILE,
};
fn update_cargo_toml(
exercise_infos: &[ExerciseInfo],
current_cargo_toml: &str,
exercise_path_prefix: &[u8],
cargo_toml_path: &str,
) -> Result<()> {
let updated_cargo_toml =
updated_cargo_toml(exercise_infos, current_cargo_toml, exercise_path_prefix)?;
fs::write(cargo_toml_path, updated_cargo_toml)
.context("Failed to write the `Cargo.toml` file")?;
Ok(())
}
pub fn update() -> Result<()> {
let info_file = InfoFile::parse()?;
if DEBUG_PROFILE {
update_cargo_toml(
&info_file.exercises,
include_str!("../../dev/Cargo.toml"),
b"../",
"dev/Cargo.toml",
)
.context("Failed to update the file `dev/Cargo.toml`")?;
println!("Updated `dev/Cargo.toml`");
} else {
let current_cargo_toml =
fs::read_to_string("Cargo.toml").context("Failed to read the file `Cargo.toml`")?;
update_cargo_toml(&info_file.exercises, ¤t_cargo_toml, b"", "Cargo.toml")
.context("Failed to update the file `Cargo.toml`")?;
println!("Updated `Cargo.toml`");
}
Ok(())
}
|