From 379d89369c6b14c1244208430d257293e384a19d Mon Sep 17 00:00:00 2001 From: Tyarel <98483313+Tyarel8@users.noreply.github.com> Date: Tue, 21 Jan 2025 17:11:40 +0100 Subject: [PATCH] `into cell-path`: noop when input is cell-path (#14881) # Description https://github.com/nushell/nushell/pull/14845#issuecomment-2596371878 When the input to `into cell-path` is a cell-path, it will return it like other into commands. # User-Facing Changes Before, using `into cell-path` with a cell-path as input would return an error, now it will return the input. --- .../src/conversions/into/cell_path.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/nu-command/src/conversions/into/cell_path.rs b/crates/nu-command/src/conversions/into/cell_path.rs index 4fbe732f7f..d96d76deab 100644 --- a/crates/nu-command/src/conversions/into/cell_path.rs +++ b/crates/nu-command/src/conversions/into/cell_path.rs @@ -12,6 +12,7 @@ impl Command for IntoCellPath { fn signature(&self) -> nu_protocol::Signature { Signature::build("into cell-path") .input_output_types(vec![ + (Type::CellPath, Type::CellPath), (Type::Int, Type::CellPath), (Type::List(Box::new(Type::Any)), Type::CellPath), ( @@ -56,6 +57,13 @@ impl Command for IntoCellPath { members: vec![PathMember::test_int(5, false)], })), }, + Example { + description: "Convert cell path into cell path", + example: "5 | into cell-path | into cell-path", + result: Some(Value::test_cell_path(CellPath { + members: vec![PathMember::test_int(5, false)], + })), + }, Example { description: "Convert string into cell path", example: "'some.path' | split row '.' | into cell-path", @@ -96,7 +104,7 @@ fn into_cell_path(call: &Call, input: PipelineData) -> Result Ok(value_to_cell_path(&value, head)?.into_pipeline_data()), + PipelineData::Value(value, _) => Ok(value_to_cell_path(value, head)?.into_pipeline_data()), PipelineData::ListStream(stream, ..) => { let list: Vec<_> = stream.into_iter().collect(); Ok(list_to_cell_path(&list, head)?.into_pipeline_data()) @@ -170,10 +178,11 @@ fn record_to_path_member( Ok(member) } -fn value_to_cell_path(value: &Value, span: Span) -> Result { +fn value_to_cell_path(value: Value, span: Span) -> Result { match value { - Value::Int { val, .. } => Ok(int_to_cell_path(*val, span)), - Value::List { vals, .. } => list_to_cell_path(vals, span), + Value::CellPath { .. } => Ok(value), + Value::Int { val, .. } => Ok(int_to_cell_path(val, span)), + Value::List { vals, .. } => list_to_cell_path(&vals, span), other => Err(ShellError::OnlySupportsThisInputType { exp_input_type: "int, list".into(), wrong_type: other.get_type().to_string(),