diff --git a/crates/nu-engine/src/from_value.rs b/crates/nu-engine/src/from_value.rs index ceb92187b4..b356bbf6fd 100644 --- a/crates/nu-engine/src/from_value.rs +++ b/crates/nu-engine/src/from_value.rs @@ -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 { + 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())), } } diff --git a/src/tests.rs b/src/tests.rs index 914f0da519..3ac7dc6817 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -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", + ) +}