Let strings be cell paths

This commit is contained in:
JT 2021-10-02 18:43:43 +13:00
parent a8f9e6dcc2
commit 63a0aa6088
2 changed files with 16 additions and 1 deletions

View File

@ -1,7 +1,7 @@
// use std::path::PathBuf;
// use nu_path::expand_path;
use nu_protocol::ast::CellPath;
use nu_protocol::ast::{CellPath, PathMember};
use nu_protocol::ShellError;
use nu_protocol::{Range, Spanned, Value};
@ -115,8 +115,15 @@ impl FromValue for ColumnPath {
impl FromValue for CellPath {
fn from_value(v: &Value) -> Result<Self, ShellError> {
let span = v.span();
match v {
Value::CellPath { val, .. } => Ok(val.clone()),
Value::String { val, .. } => Ok(CellPath {
members: vec![PathMember::String {
val: val.clone(),
span,
}],
}),
v => Err(ShellError::CantConvert("cell path".into(), v.span())),
}
}

View File

@ -417,3 +417,11 @@ fn select() -> TestResult {
"b",
)
}
#[test]
fn string_cell_path() -> TestResult {
run_test(
r#"let x = "name"; [["name", "score"]; [a, b], [c, d]] | get $x | get 1"#,
"c",
)
}