1
use nomiscript::{Value, list_to_vec};
2

            
3
use 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]
9
65
pub fn parse_suggestions(wire: &str) -> Option<Vec<String>> {
10
65
    let Ok(WireValue::Value(Value::String(text))) = parse_wire(wire) else {
11
14
        return None;
12
    };
13
51
    let list = reparse_list(&text).ok()?;
14
51
    list_to_vec(&list)?
15
        .into_iter()
16
88
        .map(|item| match item {
17
87
            Value::String(text) => Some(text),
18
1
            _ => None,
19
88
        })
20
        .collect()
21
65
}