xtask: Report fixing cargo.toml issues

This commit is contained in:
Tobias Hunger 2023-06-15 16:16:50 +02:00 committed by Olivier Goffart
parent 7e50d3c740
commit ef0ce14930

View file

@ -506,26 +506,30 @@ impl CargoToml {
expected_str: &'a str, expected_str: &'a str,
) -> Result<()> { ) -> Result<()> {
match self.package()?.get(field) { match self.package()?.get(field) {
Some(field_value) => match field_value.as_str() { Some(field_value) => {
Some(text) => { match field_value.as_str() {
if text != expected_str { Some(text) => {
if fix_it { if text != expected_str {
self.doc["package"][field] = toml_edit::value(expected_str); if fix_it {
self.edited = true; eprintln!("Fixing up {:?} as instructed. It has unexpected data in {field}.", self.path);
} else { self.doc["package"][field] = toml_edit::value(expected_str);
return Err(anyhow::anyhow!( self.edited = true;
"Incorrect {}. Found {} expected {}", } else {
field, return Err(anyhow::anyhow!(
text, "Incorrect {}. Found {} expected {}",
expected_str field,
)); text,
expected_str
));
}
} }
} }
None => return Err(anyhow::anyhow!("{} field is not a string", field)),
} }
None => return Err(anyhow::anyhow!("{} field is not a string", field)), }
},
None => { None => {
if fix_it { if fix_it {
eprintln!("Fixing up {:?} as instructed. It has no {field}.", self.path);
self.doc["package"][field] = toml_edit::value(expected_str); self.doc["package"][field] = toml_edit::value(expected_str);
self.edited = true; self.edited = true;
} else { } else {