cli_core/forms/suggestions.rs
1use nomiscript::{Value, list_to_vec};
2
3use crate::render::{WireValue, parse_wire, reparse_list};
4
5/// Parse a `form-options` suggestion reply: a list of strings.
6///
7/// `None` on a failure reply or anything but a list of strings.
8#[must_use]
9pub fn parse_suggestions(wire: &str) -> Option<Vec<String>> {
10 let Ok(WireValue::Value(Value::String(text))) = parse_wire(wire) else {
11 return None;
12 };
13 let list = reparse_list(&text).ok()?;
14 list_to_vec(&list)?
15 .into_iter()
16 .map(|item| match item {
17 Value::String(text) => Some(text),
18 _ => None,
19 })
20 .collect()
21}