forked from extern/nushell
Move Value to helpers, separate span call (#10121)
# Description As part of the refactor to split spans off of Value, this moves to using helper functions to create values, and using `.span()` instead of matching span out of Value directly. Hoping to get a few more helping hands to finish this, as there are a lot of commands to update :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: WindSoilder <windsoilder@outlook.com>
This commit is contained in:
@@ -673,7 +673,7 @@ Operating system commands:
|
||||
}
|
||||
};
|
||||
|
||||
let param_is_string = matches!(code, Value::String { val: _, span: _ });
|
||||
let param_is_string = matches!(code, Value::String { .. });
|
||||
|
||||
if escape && osc {
|
||||
return Err(ShellError::IncompatibleParameters {
|
||||
|
@@ -56,20 +56,21 @@ impl Command for SubCommand {
|
||||
}
|
||||
|
||||
fn action(input: &Value, _args: &CellPathOnlyArgs, _span: Span) -> Value {
|
||||
let span = input.span();
|
||||
match input {
|
||||
Value::String { val, span } => {
|
||||
Value::string(nu_utils::strip_ansi_likely(val).to_string(), *span)
|
||||
Value::String { val, .. } => {
|
||||
Value::string(nu_utils::strip_ansi_likely(val).to_string(), span)
|
||||
}
|
||||
other => {
|
||||
let got = format!("value is {}, not string", other.get_type());
|
||||
|
||||
Value::Error {
|
||||
error: Box::new(ShellError::TypeMismatch {
|
||||
Value::error(
|
||||
ShellError::TypeMismatch {
|
||||
err_message: got,
|
||||
span: other.span(),
|
||||
}),
|
||||
span: other.span(),
|
||||
}
|
||||
},
|
||||
other.span(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -49,7 +49,7 @@ impl Command for Clear {
|
||||
.map_err(|e| ShellError::IOErrorSpanned(e.to_string(), span))?;
|
||||
}
|
||||
|
||||
Ok(Value::Nothing { span }.into_pipeline_data())
|
||||
Ok(Value::nothing(span).into_pipeline_data())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
@@ -238,9 +238,6 @@ where
|
||||
Value::nothing(tag)
|
||||
} else {
|
||||
let values = vec.into_iter().map(Into::into).collect::<Vec<Value>>();
|
||||
Value::List {
|
||||
vals: values,
|
||||
span: tag,
|
||||
}
|
||||
Value::list(values, tag)
|
||||
}
|
||||
}
|
||||
|
@@ -179,10 +179,7 @@ impl Command for Du {
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
output.push(Value::Error {
|
||||
error: Box::new(e),
|
||||
span: tag,
|
||||
});
|
||||
output.push(Value::error(e, tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -168,11 +168,7 @@ impl Command for Input {
|
||||
if !suppress_output {
|
||||
std::io::stdout().write_all(b"\n")?;
|
||||
}
|
||||
Ok(Value::String {
|
||||
val: buf,
|
||||
span: call.head,
|
||||
}
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(buf, call.head).into_pipeline_data())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
@@ -151,7 +151,8 @@ impl EventTypeFilter {
|
||||
if let Value::List { vals, .. } = value {
|
||||
let mut filter = Self::none();
|
||||
for event_type in vals {
|
||||
if let Value::String { val, span } = event_type {
|
||||
let span = event_type.span();
|
||||
if let Value::String { val, .. } = event_type {
|
||||
match val.as_str() {
|
||||
"focus" => filter.listen_focus = true,
|
||||
"key" => filter.listen_key = true,
|
||||
|
@@ -231,21 +231,15 @@ impl Command for InputList {
|
||||
|
||||
Ok(match ans {
|
||||
InteractMode::Multi(res) => match res {
|
||||
Some(opts) => Value::List {
|
||||
vals: opts.iter().map(|s| options[*s].value.clone()).collect(),
|
||||
span: head,
|
||||
},
|
||||
None => Value::List {
|
||||
vals: vec![],
|
||||
span: head,
|
||||
},
|
||||
Some(opts) => Value::list(
|
||||
opts.iter().map(|s| options[*s].value.clone()).collect(),
|
||||
head,
|
||||
),
|
||||
None => Value::list(vec![], head),
|
||||
},
|
||||
InteractMode::Single(res) => match res {
|
||||
Some(opt) => options[opt].value.clone(),
|
||||
None => Value::String {
|
||||
val: "".to_string(),
|
||||
span: head,
|
||||
},
|
||||
None => Value::string("".to_string(), head),
|
||||
},
|
||||
}
|
||||
.into_pipeline_data())
|
||||
|
@@ -172,14 +172,11 @@ impl Command for Kill {
|
||||
.trim_end(),
|
||||
);
|
||||
if val.is_empty() {
|
||||
Ok(Value::Nothing { span: call.head }.into_pipeline_data())
|
||||
Ok(Value::nothing(call.head).into_pipeline_data())
|
||||
} else {
|
||||
Ok(vec![Value::String {
|
||||
val,
|
||||
span: call.head,
|
||||
}]
|
||||
.into_iter()
|
||||
.into_pipeline_data(engine_state.ctrlc.clone()))
|
||||
Ok(vec![Value::string(val, call.head)]
|
||||
.into_iter()
|
||||
.into_pipeline_data(engine_state.ctrlc.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -66,7 +66,7 @@ impl Command for Sleep {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Value::Nothing { span: call.head }.into_pipeline_data())
|
||||
Ok(Value::nothing(call.head).into_pipeline_data())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
@@ -74,9 +74,7 @@ impl Command for Sleep {
|
||||
Example {
|
||||
description: "Sleep for 1sec",
|
||||
example: "sleep 1sec",
|
||||
result: Some(Value::Nothing {
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::nothing(Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "Sleep for 3sec",
|
||||
|
Reference in New Issue
Block a user