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:
JT
2023-09-04 02:27:29 +12:00
committed by GitHub
parent af79eb2943
commit 6cdfee3573
372 changed files with 5811 additions and 7448 deletions

View File

@ -134,11 +134,7 @@ pub fn cal(
current_day_option,
)?;
Ok(Value::List {
vals: calendar_vec_deque.into_iter().collect(),
span: tag,
}
.into_pipeline_data())
Ok(Value::list(calendar_vec_deque.into_iter().collect(), tag).into_pipeline_data())
}
fn get_invalid_year_shell_error(head: Span) -> ShellError {
@ -324,10 +320,7 @@ fn add_month_to_table(
if should_show_month_column || should_show_month_names {
let month_value = if should_show_month_names {
Value::String {
val: month_helper.month_name.clone(),
span: tag,
}
Value::string(month_helper.month_name.clone(), tag)
} else {
Value::int(month_helper.selected_month as i64, tag)
};
@ -339,7 +332,7 @@ fn add_month_to_table(
let should_add_day_number_to_table =
(day_number > total_start_offset) && (day_number <= day_limit);
let mut value = Value::Nothing { span: tag };
let mut value = Value::nothing(tag);
if should_add_day_number_to_table {
let adjusted_day_number = day_number - total_start_offset;

View File

@ -40,8 +40,8 @@ impl Command for Seq {
Example {
description: "sequence 1 to 10",
example: "seq 1 10",
result: Some(Value::List {
vals: vec![
result: Some(Value::list(
vec![
Value::test_int(1),
Value::test_int(2),
Value::test_int(3),
@ -53,14 +53,14 @@ impl Command for Seq {
Value::test_int(9),
Value::test_int(10),
],
span: Span::test_data(),
}),
Span::test_data(),
)),
},
Example {
description: "sequence 1.0 to 2.0 by 0.1s",
example: "seq 1.0 0.1 2.0",
result: Some(Value::List {
vals: vec![
result: Some(Value::list(
vec![
Value::test_float(1.0000),
Value::test_float(1.1000),
Value::test_float(1.2000),
@ -73,8 +73,8 @@ impl Command for Seq {
Value::test_float(1.9000),
Value::test_float(2.0000),
],
span: Span::test_data(),
}),
Span::test_data(),
)),
},
Example {
description: "sequence 1 to 5, then convert to a string with a pipe separator",

View File

@ -38,16 +38,16 @@ impl Command for SeqChar {
Example {
description: "sequence a to e",
example: "seq char a e",
result: Some(Value::List {
vals: vec![
result: Some(Value::list(
vec![
Value::test_string('a'),
Value::test_string('b'),
Value::test_string('c'),
Value::test_string('d'),
Value::test_string('e'),
],
span: Span::test_data(),
}),
Span::test_data(),
)),
},
Example {
description: "sequence a to e, and put the characters in a pipe-separated string",
@ -127,9 +127,9 @@ fn run_seq_char(start_ch: char, end_ch: char, span: Span) -> Result<PipelineData
let result = result_vec
.into_iter()
.map(|x| Value::String { val: x, span })
.map(|x| Value::string(x, span))
.collect::<Vec<Value>>();
Ok(Value::List { vals: result, span }.into_pipeline_data())
Ok(Value::list(result, span).into_pipeline_data())
}
#[cfg(test)]

View File

@ -78,8 +78,8 @@ impl Command for SeqDate {
Example {
description: "print the first 10 days in January, 2020",
example: "seq date -b '2020-01-01' -e '2020-01-10'",
result: Some(Value::List {
vals: vec![
result: Some(Value::list(
vec![
Value::test_string("2020-01-01"),
Value::test_string("2020-01-02"),
Value::test_string("2020-01-03"),
@ -91,14 +91,14 @@ impl Command for SeqDate {
Value::test_string("2020-01-09"),
Value::test_string("2020-01-10"),
],
span: Span::test_data(),
}),
Span::test_data(),
)),
},
Example {
description: "print every fifth day between January 1st 2020 and January 31st 2020",
example: "seq date -b '2020-01-01' -e '2020-01-31' -n 5",
result: Some(Value::List {
vals: vec![
result: Some(Value::list(
vec![
Value::test_string("2020-01-01"),
Value::test_string("2020-01-06"),
Value::test_string("2020-01-11"),
@ -107,8 +107,8 @@ impl Command for SeqDate {
Value::test_string("2020-01-26"),
Value::test_string("2020-01-31"),
],
span: Span::test_data(),
}),
Span::test_data(),
)),
},
]
}
@ -324,10 +324,7 @@ pub fn run_seq_dates(
}
}
Ok(Value::List {
vals: ret,
span: call_span,
})
Ok(Value::list(ret, call_span))
}
#[cfg(test)]