mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 16:33:37 +01:00
This reverts commit f0e93c2fa9
(PR #7417).
I'm currently [working on improving cell
paths](https://github.com/nushell/nushell/issues/7498#issuecomment-1356834798),
and I realized that I would need to make several improvements to `into
cellpath` along the lines of Jakub's comment here:
https://github.com/nushell/nushell/pull/7417#issuecomment-1345264955
I don't think `into cellpath` is quite ready for prime-time, and I'd
like to remove it before the upcoming release.
This commit is contained in:
parent
28123841ba
commit
a21af0ade4
@ -1,121 +0,0 @@
|
||||
use nu_protocol::ast::{CellPath, PathMember};
|
||||
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
#[derive(Clone)]
|
||||
pub struct SubCommand;
|
||||
|
||||
impl Command for SubCommand {
|
||||
fn name(&self) -> &str {
|
||||
"into cellpath"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("into cellpath")
|
||||
.input_output_types(vec![(Type::String, Type::CellPath)])
|
||||
.category(Category::Conversions)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Convert value to a cellpath."
|
||||
}
|
||||
|
||||
fn search_terms(&self) -> Vec<&str> {
|
||||
vec!["convert"]
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
call: &Call,
|
||||
input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
into_cellpath(engine_state, call, input)
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Convert from string to cellpath",
|
||||
example: " 'config.show_banner' | into cellpath",
|
||||
result: Some(Value::CellPath {
|
||||
val: CellPath {
|
||||
members: vec![
|
||||
PathMember::String {
|
||||
val: "config".to_string(),
|
||||
span: Span::new(1, 21),
|
||||
},
|
||||
PathMember::String {
|
||||
val: "show_banner".to_string(),
|
||||
span: Span::new(1, 21),
|
||||
},
|
||||
],
|
||||
},
|
||||
span: Span::new(1, 21),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "Convert from string to cellpath",
|
||||
example: " 'a' | into cellpath",
|
||||
result: Some(Value::CellPath {
|
||||
val: CellPath {
|
||||
members: vec![PathMember::String {
|
||||
val: "a".to_string(),
|
||||
span: Span::new(38, 41),
|
||||
}],
|
||||
},
|
||||
span: Span::new(1, 2),
|
||||
}),
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
fn into_cellpath(
|
||||
_: &EngineState,
|
||||
call: &Call,
|
||||
input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let input = input.into_value(call.head);
|
||||
let res = match input {
|
||||
Value::String { val, span } => parse_string_into_cellapth(val, span),
|
||||
other => Value::Error {
|
||||
error: ShellError::UnsupportedInput(
|
||||
"'into cellpath' does not support this input".into(),
|
||||
other.span().unwrap_or(call.head),
|
||||
),
|
||||
},
|
||||
};
|
||||
Ok(res.into_pipeline_data())
|
||||
}
|
||||
|
||||
fn parse_string_into_cellapth(val: String, span: Span) -> Value {
|
||||
let parts = val.split('.').collect::<Vec<&str>>();
|
||||
let mut cellpath: Vec<PathMember> = vec![];
|
||||
for part in parts {
|
||||
cellpath.push(PathMember::String {
|
||||
val: part.to_string(),
|
||||
span,
|
||||
})
|
||||
}
|
||||
Value::CellPath {
|
||||
val: CellPath { members: cellpath },
|
||||
span,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_examples() {
|
||||
use crate::test_examples;
|
||||
|
||||
test_examples(SubCommand {})
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
mod binary;
|
||||
mod bool;
|
||||
mod cellpath;
|
||||
mod command;
|
||||
mod datetime;
|
||||
mod decimal;
|
||||
@ -13,7 +12,6 @@ mod string;
|
||||
pub use self::bool::SubCommand as IntoBool;
|
||||
pub use self::filesize::SubCommand as IntoFilesize;
|
||||
pub use binary::SubCommand as IntoBinary;
|
||||
pub use cellpath::SubCommand as IntoCellPath;
|
||||
pub use command::Into;
|
||||
pub use datetime::SubCommand as IntoDatetime;
|
||||
pub use decimal::SubCommand as IntoDecimal;
|
||||
|
@ -371,7 +371,6 @@ pub fn create_default_context() -> EngineState {
|
||||
IntoDuration,
|
||||
IntoFilesize,
|
||||
IntoInt,
|
||||
IntoCellPath,
|
||||
IntoRecord,
|
||||
IntoString,
|
||||
};
|
||||
|
@ -1,14 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn into_pathcell_string() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
'nu.is.awesome' | into cellpath
|
||||
"#
|
||||
));
|
||||
dbg!(&actual.out);
|
||||
|
||||
assert!(actual.out.contains("nu.is.awesome"));
|
||||
}
|
@ -35,7 +35,6 @@ mod headers;
|
||||
mod help;
|
||||
mod histogram;
|
||||
mod insert;
|
||||
mod into_cellpath;
|
||||
mod into_filesize;
|
||||
mod into_int;
|
||||
mod last;
|
||||
|
21
src/tests.rs
21
src/tests.rs
@ -25,8 +25,6 @@ use tempfile::NamedTempFile;
|
||||
|
||||
pub type TestResult = Result<(), Box<dyn std::error::Error>>;
|
||||
|
||||
const DEFAULT_CONFIG: &str = "./crates/nu-utils/src/sample_config/default_config.nu";
|
||||
|
||||
pub fn run_test_with_env(input: &str, expected: &str, env: &HashMap<&str, &str>) -> TestResult {
|
||||
let mut file = NamedTempFile::new()?;
|
||||
let name = file.path();
|
||||
@ -56,25 +54,6 @@ pub fn run_test(input: &str, expected: &str) -> TestResult {
|
||||
run_cmd_and_assert(cmd, expected)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn run_test_with_default_config(input: &str, expected: &str) -> TestResult {
|
||||
let mut file = NamedTempFile::new()?;
|
||||
let name = file.path();
|
||||
|
||||
let mut cmd = Command::cargo_bin("nu")?;
|
||||
cmd.arg("--config");
|
||||
cmd.arg(DEFAULT_CONFIG);
|
||||
cmd.arg(name);
|
||||
cmd.env(
|
||||
"PWD",
|
||||
std::env::current_dir().expect("Can't get current dir"),
|
||||
);
|
||||
|
||||
writeln!(file, "{}", input)?;
|
||||
|
||||
run_cmd_and_assert(cmd, expected)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn run_cmd_and_assert(mut cmd: Command, expected: &str) -> TestResult {
|
||||
let output = cmd.output()?;
|
||||
|
@ -1,7 +1,5 @@
|
||||
use crate::tests::{run_test, TestResult};
|
||||
|
||||
use super::run_test_with_default_config;
|
||||
|
||||
#[test]
|
||||
fn shorthand_env_1() -> TestResult {
|
||||
run_test(r#"FOO=BAZ $env.FOO"#, "BAZ")
|
||||
@ -24,11 +22,3 @@ fn convert_non_string_env_var_to_nothing() -> TestResult {
|
||||
"nothing",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_string_to_env_var_cellpath() -> TestResult {
|
||||
run_test_with_default_config(
|
||||
r#"let p = 'ls.use_ls_colors'; $env.config | upsert ($p | into cellpath) false | get ls.use_ls_colors"#,
|
||||
"false",
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user