(path: &str, value: &Value)
| 445 | } |
| 446 | |
| 447 | fn extract_string_like_value(path: &str, value: &Value) -> Result<Option<String>, Box<dyn Error>> { |
| 448 | match value { |
| 449 | Value::Null => Ok(None), |
| 450 | Value::String(v) => Ok(Some(v.clone())), |
| 451 | Value::Number(v) => Ok(Some(v.to_string())), |
| 452 | Value::Bool(v) => Ok(Some(v.to_string())), |
| 453 | Value::Object(map) => { |
| 454 | for key in ["primary", "default", "model", "id", "name"] { |
| 455 | if let Some(v) = map.get(key) |
| 456 | && let Some(as_string) = scalar_to_string(v) |
| 457 | { |
| 458 | return Ok(Some(as_string)); |
| 459 | } |
| 460 | } |
| 461 | if map.len() == 1 |
| 462 | && let Some((_, only_value)) = map.iter().next() |
| 463 | && let Some(as_string) = scalar_to_string(only_value) |
| 464 | { |
| 465 | return Ok(Some(as_string)); |
| 466 | } |
| 467 | Err(format!( |
| 468 | "`openclaw config get {path}` returned an unsupported object shape; expected a string-like model value or an object containing one of: primary/default/model/id/name." |
| 469 | ) |
| 470 | .into()) |
| 471 | } |
| 472 | Value::Array(_) => Err(format!( |
| 473 | "`openclaw config get {path}` returned an array; expected a string-like model value." |
| 474 | ) |
| 475 | .into()), |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | fn scalar_to_string(value: &Value) -> Option<String> { |
| 480 | match value { |
no test coverage detected