mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 14:36:08 +02:00
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:
@ -97,22 +97,22 @@ impl Command for Ast {
|
||||
);
|
||||
Ok(output_record.into_pipeline_data())
|
||||
} else {
|
||||
let block_value = Value::String {
|
||||
val: if minify {
|
||||
let block_value = Value::string(
|
||||
if minify {
|
||||
format!("{block_output:?}")
|
||||
} else {
|
||||
format!("{block_output:#?}")
|
||||
},
|
||||
span: pipeline.span,
|
||||
};
|
||||
let error_value = Value::String {
|
||||
val: if minify {
|
||||
pipeline.span,
|
||||
);
|
||||
let error_value = Value::string(
|
||||
if minify {
|
||||
format!("{error_output:?}")
|
||||
} else {
|
||||
format!("{error_output:#?}")
|
||||
},
|
||||
span: pipeline.span,
|
||||
};
|
||||
pipeline.span,
|
||||
);
|
||||
let output_record = Value::record(
|
||||
record! {
|
||||
"block" => block_value,
|
||||
|
@ -44,15 +44,9 @@ impl Command for Debug {
|
||||
input.map(
|
||||
move |x| {
|
||||
if raw {
|
||||
Value::String {
|
||||
val: x.debug_value(),
|
||||
span: head,
|
||||
}
|
||||
Value::string(x.debug_value(), head)
|
||||
} else {
|
||||
Value::String {
|
||||
val: x.debug_string(", ", &config),
|
||||
span: head,
|
||||
}
|
||||
Value::string(x.debug_string(", ", &config), head)
|
||||
}
|
||||
},
|
||||
engine_state.ctrlc.clone(),
|
||||
@ -69,23 +63,23 @@ impl Command for Debug {
|
||||
Example {
|
||||
description: "Debug print a list",
|
||||
example: "['hello'] | debug",
|
||||
result: Some(Value::List {
|
||||
vals: vec![Value::test_string("hello")],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_string("hello")],
|
||||
Span::test_data(),
|
||||
)),
|
||||
},
|
||||
Example {
|
||||
description: "Debug print a table",
|
||||
example:
|
||||
"[[version patch]; ['0.1.0' false] ['0.1.1' true] ['0.2.0' false]] | debug",
|
||||
result: Some(Value::List {
|
||||
vals: vec![
|
||||
result: Some(Value::list(
|
||||
vec![
|
||||
Value::test_string("{version: 0.1.0, patch: false}"),
|
||||
Value::test_string("{version: 0.1.1, patch: true}"),
|
||||
Value::test_string("{version: 0.2.0, patch: false}"),
|
||||
],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
Span::test_data(),
|
||||
)),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -213,10 +213,7 @@ fn get_expression_as_value(
|
||||
) -> Value {
|
||||
match eval_expression(engine_state, stack, inner_expr) {
|
||||
Ok(v) => v,
|
||||
Err(error) => Value::Error {
|
||||
error: Box::new(error),
|
||||
span: inner_expr.span,
|
||||
},
|
||||
Err(error) => Value::error(error, inner_expr.span),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,6 +198,7 @@ mod util {
|
||||
|
||||
/// Try to build column names and a table grid.
|
||||
pub fn collect_input(value: Value) -> (Vec<String>, Vec<Vec<String>>) {
|
||||
let span = value.span();
|
||||
match value {
|
||||
Value::Record { val: record, .. } => (
|
||||
record.cols,
|
||||
@ -217,13 +218,10 @@ mod util {
|
||||
|
||||
(columns, data)
|
||||
}
|
||||
Value::String { val, span } => {
|
||||
Value::String { val, .. } => {
|
||||
let lines = val
|
||||
.lines()
|
||||
.map(|line| Value::String {
|
||||
val: line.to_string(),
|
||||
span,
|
||||
})
|
||||
.map(|line| Value::string(line.to_string(), span))
|
||||
.map(|val| vec![debug_string_without_formatting(&val)])
|
||||
.collect();
|
||||
|
||||
|
@ -79,10 +79,7 @@ impl Command for TimeIt {
|
||||
|
||||
let end_time = Instant::now();
|
||||
|
||||
let output = Value::Duration {
|
||||
val: (end_time - start_time).as_nanos() as i64,
|
||||
span: call.head,
|
||||
};
|
||||
let output = Value::duration((end_time - start_time).as_nanos() as i64, call.head);
|
||||
|
||||
Ok(output.into_pipeline_data())
|
||||
}
|
||||
|
@ -34,16 +34,16 @@ impl Command for View {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::String {
|
||||
val: get_full_help(
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&View.signature(),
|
||||
&View.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_parser_keyword(),
|
||||
),
|
||||
span: call.head,
|
||||
}
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -47,11 +47,7 @@ impl Command for ViewFiles {
|
||||
));
|
||||
}
|
||||
|
||||
Ok(Value::List {
|
||||
vals: records,
|
||||
span: call.head,
|
||||
}
|
||||
.into_pipeline_data())
|
||||
Ok(Value::list(records, call.head).into_pipeline_data())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
Reference in New Issue
Block a user