Merge pull request #83 from nushell/string_cell_path
Let strings be cell paths
This commit is contained in:
commit
9a64f1bff3
|
@ -1,7 +1,7 @@
|
||||||
// use std::path::PathBuf;
|
// use std::path::PathBuf;
|
||||||
|
|
||||||
// use nu_path::expand_path;
|
// use nu_path::expand_path;
|
||||||
use nu_protocol::ast::CellPath;
|
use nu_protocol::ast::{CellPath, PathMember};
|
||||||
use nu_protocol::ShellError;
|
use nu_protocol::ShellError;
|
||||||
use nu_protocol::{Range, Spanned, Value};
|
use nu_protocol::{Range, Spanned, Value};
|
||||||
|
|
||||||
|
@ -115,8 +115,15 @@ impl FromValue for ColumnPath {
|
||||||
|
|
||||||
impl FromValue for CellPath {
|
impl FromValue for CellPath {
|
||||||
fn from_value(v: &Value) -> Result<Self, ShellError> {
|
fn from_value(v: &Value) -> Result<Self, ShellError> {
|
||||||
|
let span = v.span();
|
||||||
match v {
|
match v {
|
||||||
Value::CellPath { val, .. } => Ok(val.clone()),
|
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())),
|
v => Err(ShellError::CantConvert("cell path".into(), v.span())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,3 +417,11 @@ fn select() -> TestResult {
|
||||||
"b",
|
"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