Promote any `array ` properties from a single string into a real array: split on commas if the user passed `--keywords foo,bar`, or wrap a single-occurrence string in a one-element array. Runs after parsing so we can see whether the user passed the flag once or many times.
(def: &ToolDefinition, map: &mut Map<String, Value>)
| 664 | /// single-occurrence string in a one-element array. Runs after parsing so we |
| 665 | /// can see whether the user passed the flag once or many times. |
| 666 | pub(super) fn finalize_arrays(def: &ToolDefinition, map: &mut Map<String, Value>) { |
| 667 | let Some(props) = def |
| 668 | .input_schema |
| 669 | .get("properties") |
| 670 | .and_then(Value::as_object) |
| 671 | else { |
| 672 | return; |
| 673 | }; |
| 674 | for (key, schema) in props { |
| 675 | let is_array = schema.get("type").and_then(Value::as_str) == Some("array"); |
| 676 | if !is_array { |
| 677 | continue; |
| 678 | } |
| 679 | if let Some(value) = map.get_mut(key) { |
| 680 | match value { |
| 681 | Value::String(s) => { |
| 682 | let parts: Vec<Value> = if s.contains(',') { |
| 683 | s.split(',') |
| 684 | .map(|p| Value::String(p.trim().to_string())) |
| 685 | .collect() |
| 686 | } else { |
| 687 | vec![Value::String(std::mem::take(s))] |
| 688 | }; |
| 689 | *value = Value::Array(parts); |
| 690 | } |
| 691 | Value::Array(_) => {} |
| 692 | _ => {} |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | /// Consume the next argument as a flag value or return a `missing value` error. |
| 699 | fn take_value(iter: &mut std::slice::Iter<'_, String>, flag: &str) -> Result<String> { |