You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.0 KiB
34 lines
1.0 KiB
//! Generate toml data
|
|
|
|
use super::{CargoError, Result};
|
|
use std::{fs::File, io::Write, path::PathBuf};
|
|
use toml_edit::{value, Document, Item, Value};
|
|
|
|
/// Sync a document back into it's Cargo.toml
|
|
pub(crate) fn sync(doc: &mut Document, path: PathBuf) -> Result<()> {
|
|
if !path.exists() {
|
|
return Err(CargoError::Io);
|
|
}
|
|
|
|
let mut f = File::create(path)?;
|
|
f.write_all(doc.to_string().as_bytes())?;
|
|
Ok(())
|
|
}
|
|
|
|
/// Takes a mutable document, dependency alias or name, and version
|
|
pub(crate) fn update_dependency(doc: &mut Document, dep: &String, ver: &String) {
|
|
match doc.as_table_mut().entry("dependencies") {
|
|
Item::Table(ref mut t) => match t.entry(dep.as_str()) {
|
|
Item::Value(Value::InlineTable(ref mut t)) => {
|
|
if let Some(v) = t.get_mut("version") {
|
|
*v = Value::from(ver.clone());
|
|
}
|
|
return;
|
|
}
|
|
_ => {}
|
|
},
|
|
_ => {}
|
|
}
|
|
|
|
// eprintln!("Invalid dependency format!");
|
|
}
|
|
|