(diff_config: &mut DiffObjConfig, args: &[String])
| 7 | use objdiff_core::diff::{ConfigEnum, ConfigPropertyId, ConfigPropertyKind, DiffObjConfig}; |
| 8 | |
| 9 | pub fn apply_config_args(diff_config: &mut DiffObjConfig, args: &[String]) -> Result<()> { |
| 10 | for config in args { |
| 11 | let (key, value) = config.split_once('=').context("--config expects \"key=value\"")?; |
| 12 | let property_id = ConfigPropertyId::from_str(key) |
| 13 | .map_err(|()| anyhow!("Invalid configuration property: {}", key))?; |
| 14 | diff_config.set_property_value_str(property_id, value).map_err(|()| { |
| 15 | let mut options = String::new(); |
| 16 | match property_id.kind() { |
| 17 | ConfigPropertyKind::Boolean => { |
| 18 | options = "true, false".to_string(); |
| 19 | } |
| 20 | ConfigPropertyKind::Choice(variants) => { |
| 21 | for (i, variant) in variants.iter().enumerate() { |
| 22 | if i > 0 { |
| 23 | options.push_str(", "); |
| 24 | } |
| 25 | options.push_str(variant.value); |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | anyhow!("Invalid value for {}. Expected one of: {}", property_id.name(), options) |
| 30 | })?; |
| 31 | } |
| 32 | Ok(()) |
| 33 | } |
no test coverage detected