nu-command 0.75.0

Nushell's built-in commands
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use nu_protocol::{FromValue, ShellError, Value};

pub fn extract_strings(value: Value) -> Result<Vec<String>, ShellError> {
    match (
        <String as FromValue>::from_value(&value),
        <Vec<String> as FromValue>::from_value(&value),
    ) {
        (Ok(col), Err(_)) => Ok(vec![col]),
        (Err(_), Ok(cols)) => Ok(cols),
        _ => Err(ShellError::IncompatibleParametersSingle(
            "Expected a string or list of strings".into(),
            value.span()?,
        )),
    }
}