forked from extern/nushell
Let strings be cell paths
This commit is contained in:
parent
a8f9e6dcc2
commit
63a0aa6088
@ -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())),
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user