MCPcopy Create free account
hub / github.com/clawshell/clawshell / extract_string_like_value

Function extract_string_like_value

src/openclaw_cli.rs:447–477  ·  view source on GitHub ↗
(path: &str, value: &Value)

Source from the content-addressed store, hash-verified

445}
446
447fn 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
479fn scalar_to_string(value: &Value) -> Option<String> {
480 match value {

Calls 1

scalar_to_stringFunction · 0.85

Tested by

no test coverage detected