mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-21 21:42:23 -05:00
Update Cargo.toml on dev check
This commit is contained in:
parent
d1ebbaa6f6
commit
aa813fbce1
4 changed files with 20 additions and 7 deletions
|
@ -1,6 +1,8 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
|
|
||||||
|
use crate::info_file::InfoFile;
|
||||||
|
|
||||||
mod check;
|
mod check;
|
||||||
mod init;
|
mod init;
|
||||||
|
|
||||||
|
@ -11,10 +13,10 @@ pub enum DevCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DevCommands {
|
impl DevCommands {
|
||||||
pub fn run(self) -> Result<()> {
|
pub fn run(self, info_file: InfoFile) -> Result<()> {
|
||||||
match self {
|
match self {
|
||||||
DevCommands::Init => init::init().context(INIT_ERR),
|
DevCommands::Init => init::init().context(INIT_ERR),
|
||||||
DevCommands::Check => check::check(),
|
DevCommands::Check => check::check(info_file),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
use anyhow::Result;
|
use std::fs;
|
||||||
|
|
||||||
pub fn check() -> Result<()> {
|
use anyhow::{Context, Result};
|
||||||
todo!()
|
|
||||||
|
use crate::{info_file::InfoFile, init::cargo_toml};
|
||||||
|
|
||||||
|
pub fn check(info_file: InfoFile) -> Result<()> {
|
||||||
|
// TODO: Add checks
|
||||||
|
|
||||||
|
fs::write("Cargo.toml", cargo_toml(&info_file.exercises))
|
||||||
|
.context("Failed to update the file `Cargo.toml`")?;
|
||||||
|
|
||||||
|
println!("Everything looks fine!");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::{
|
||||||
|
|
||||||
use crate::{embedded::EMBEDDED_FILES, info_file::ExerciseInfo};
|
use crate::{embedded::EMBEDDED_FILES, info_file::ExerciseInfo};
|
||||||
|
|
||||||
fn cargo_toml(exercise_infos: &[ExerciseInfo]) -> Vec<u8> {
|
pub fn cargo_toml(exercise_infos: &[ExerciseInfo]) -> Vec<u8> {
|
||||||
let mut cargo_toml = Vec::with_capacity(1 << 13);
|
let mut cargo_toml = Vec::with_capacity(1 << 13);
|
||||||
cargo_toml.extend_from_slice(b"bin = [\n");
|
cargo_toml.extend_from_slice(b"bin = [\n");
|
||||||
for exercise_info in exercise_infos {
|
for exercise_info in exercise_infos {
|
||||||
|
|
|
@ -76,7 +76,7 @@ fn main() -> Result<()> {
|
||||||
Some(Subcommands::Init) => {
|
Some(Subcommands::Init) => {
|
||||||
return init::init(&info_file.exercises).context("Initialization failed");
|
return init::init(&info_file.exercises).context("Initialization failed");
|
||||||
}
|
}
|
||||||
Some(Subcommands::Dev(dev_command)) => return dev_command.run(),
|
Some(Subcommands::Dev(dev_command)) => return dev_command.run(info_file),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue