MCPcopy Index your code
hub / github.com/encounter/objdiff / apply_config_args

Function apply_config_args

objdiff-cli/src/cmd/mod.rs:9–33  ·  view source on GitHub ↗
(diff_config: &mut DiffObjConfig, args: &[String])

Source from the content-addressed store, hash-verified

7use objdiff_core::diff::{ConfigEnum, ConfigPropertyId, ConfigPropertyKind, DiffObjConfig};
8
9pub 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}

Callers 2

build_unit_diff_configFunction · 0.85
build_config_from_argsFunction · 0.85

Calls 1

from_strFunction · 0.85

Tested by

no test coverage detected