summaryrefslogtreecommitdiff
path: root/src/dev/update.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-04-21 20:22:01 +0200
committermo8it <mo8it@proton.me>2024-04-21 20:22:01 +0200
commit642c3bd37e3195f7f744a5fa60a53e59d8da5526 (patch)
tree03415dd39c601142be147551d421d2648a15682e /src/dev/update.rs
parent49e4a1fab04560cf0e868ab8214dfc94e76b9f4b (diff)
Fix the generated Cargo.toml after rustlings init
Diffstat (limited to 'src/dev/update.rs')
-rw-r--r--src/dev/update.rs20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/dev/update.rs b/src/dev/update.rs
index 1f032f7..d2f20aa 100644
--- a/src/dev/update.rs
+++ b/src/dev/update.rs
@@ -3,26 +3,22 @@ use std::fs;
use anyhow::{Context, Result};
use crate::{
+ cargo_toml::updated_cargo_toml,
info_file::{ExerciseInfo, InfoFile},
DEBUG_PROFILE,
};
-use super::check::{append_bins, bins_start_end_ind};
-
fn update_cargo_toml(
exercise_infos: &[ExerciseInfo],
current_cargo_toml: &str,
- cargo_toml_path: &str,
exercise_path_prefix: &[u8],
+ cargo_toml_path: &str,
) -> Result<()> {
- let (bins_start_ind, bins_end_ind) = bins_start_end_ind(current_cargo_toml)?;
+ let updated_cargo_toml =
+ updated_cargo_toml(exercise_infos, current_cargo_toml, exercise_path_prefix)?;
- let mut new_cargo_toml = Vec::with_capacity(1 << 13);
- new_cargo_toml.extend_from_slice(current_cargo_toml[..bins_start_ind].as_bytes());
- append_bins(&mut new_cargo_toml, exercise_infos, exercise_path_prefix);
- new_cargo_toml.extend_from_slice(current_cargo_toml[bins_end_ind..].as_bytes());
-
- fs::write(cargo_toml_path, new_cargo_toml).context("Failed to write the `Cargo.toml` file")?;
+ fs::write(cargo_toml_path, updated_cargo_toml)
+ .context("Failed to write the `Cargo.toml` file")?;
Ok(())
}
@@ -34,8 +30,8 @@ pub fn update() -> Result<()> {
update_cargo_toml(
&info_file.exercises,
include_str!("../../dev/Cargo.toml"),
- "dev/Cargo.toml",
b"../",
+ "dev/Cargo.toml",
)
.context("Failed to update the file `dev/Cargo.toml`")?;
@@ -43,7 +39,7 @@ pub fn update() -> Result<()> {
} 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, &current_cargo_toml, "Cargo.toml", b"")
+ update_cargo_toml(&info_file.exercises, &current_cargo_toml, b"", "Cargo.toml")
.context("Failed to update the file `Cargo.toml`")?;
println!("Updated `Cargo.toml`");