nushell/crates/nu-command/src/strings/split/row.rs

193 lines
5.8 KiB
Rust
Raw Normal View History

2021-10-09 04:45:25 +02:00
use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
2021-10-25 18:58:58 +02:00
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type,
Value,
2021-10-09 04:45:25 +02:00
};
Add regex separators for split row/list/column (#8707) # Description Verified on discord with maintainer Change adds regex separators in split rows/column/list. The primary motivating reason was to make it easier to split on separators with unbounded whitespace without requiring a lot of trim jiggery. But, secondary motivation is the same as the set of all motivations for adding split regex features to most languages. # User-Facing Changes Adds -r option to split rows/column/list. # Tests + Formatting Ran tests, however tests.nu fails with unrelated errors: ``` ~/src/nushell> cargo run -- crates/nu-utils/standard_library/tests.nu 04/02/2023 02:07:25 AM Finished dev [unoptimized + debuginfo] target(s) in 0.24s Running `target/debug/nu crates/nu-utils/standard_library/tests.nu` INF|2023-04-02T02:07:27.060|Running tests in test_asserts INF|2023-04-02T02:07:27.141|Running tests in test_dirs Error: × list is just pwd after initialization INF|2023-04-02T02:07:27.167|Running tests in test_logger INF|2023-04-02T02:07:27.286|Running tests in test_std Error: × some tests did not pass (see complete errors above): │ │ test_asserts test_assert │ test_asserts test_assert_equal │ test_asserts test_assert_error │ test_asserts test_assert_greater │ test_asserts test_assert_greater_or_equal │ test_asserts test_assert_length │ test_asserts test_assert_less │ test_asserts test_assert_less_or_equal │ test_asserts test_assert_not_equal │ ⨯ test_dirs test_dirs_command │ test_logger test_critical │ test_logger test_debug │ test_logger test_error │ test_logger test_info │ test_logger test_warning │ test_std test_path_add │ ``` Upon investigating seeing this difference: ``` ╭───┬─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 0 │ /var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ │ 1 │ /private/var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ ╰───┴─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` This seems unrelated to my changes, but can investigate further if desired. # 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: Robert Waugh <robert@waugh.io>
2023-04-07 13:46:11 +02:00
use regex::Regex;
2021-10-25 06:01:02 +02:00
#[derive(Clone)]
2021-10-09 04:45:25 +02:00
pub struct SubCommand;
impl Command for SubCommand {
fn name(&self) -> &str {
"split row"
}
fn signature(&self) -> Signature {
Signature::build("split row")
Input output checking (#9680) # Description This PR tights input/output type-checking a bit more. There are a lot of commands that don't have correct input/output types, so part of the effort is updating them. This PR now contains updates to commands that had wrong input/output signatures. It doesn't add examples for these new signatures, but that can be follow-up work. # User-Facing Changes BREAKING CHANGE BREAKING CHANGE This work enforces many more checks on pipeline type correctness than previous nushell versions. This strictness may uncover incompatibilities in existing scripts or shortcomings in the type information for internal commands. # 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 -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `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. -->
2023-07-14 05:20:35 +02:00
.input_output_types(vec![
(Type::String, Type::List(Box::new(Type::String))),
(
Type::List(Box::new(Type::String)),
(Type::List(Box::new(Type::String))),
),
Input output checking (#9680) # Description This PR tights input/output type-checking a bit more. There are a lot of commands that don't have correct input/output types, so part of the effort is updating them. This PR now contains updates to commands that had wrong input/output signatures. It doesn't add examples for these new signatures, but that can be follow-up work. # User-Facing Changes BREAKING CHANGE BREAKING CHANGE This work enforces many more checks on pipeline type correctness than previous nushell versions. This strictness may uncover incompatibilities in existing scripts or shortcomings in the type information for internal commands. # 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 -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `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. -->
2023-07-14 05:20:35 +02:00
])
.allow_variants_without_examples(true)
.required(
"separator",
SyntaxShape::String,
Add regex separators for split row/list/column (#8707) # Description Verified on discord with maintainer Change adds regex separators in split rows/column/list. The primary motivating reason was to make it easier to split on separators with unbounded whitespace without requiring a lot of trim jiggery. But, secondary motivation is the same as the set of all motivations for adding split regex features to most languages. # User-Facing Changes Adds -r option to split rows/column/list. # Tests + Formatting Ran tests, however tests.nu fails with unrelated errors: ``` ~/src/nushell> cargo run -- crates/nu-utils/standard_library/tests.nu 04/02/2023 02:07:25 AM Finished dev [unoptimized + debuginfo] target(s) in 0.24s Running `target/debug/nu crates/nu-utils/standard_library/tests.nu` INF|2023-04-02T02:07:27.060|Running tests in test_asserts INF|2023-04-02T02:07:27.141|Running tests in test_dirs Error: × list is just pwd after initialization INF|2023-04-02T02:07:27.167|Running tests in test_logger INF|2023-04-02T02:07:27.286|Running tests in test_std Error: × some tests did not pass (see complete errors above): │ │ test_asserts test_assert │ test_asserts test_assert_equal │ test_asserts test_assert_error │ test_asserts test_assert_greater │ test_asserts test_assert_greater_or_equal │ test_asserts test_assert_length │ test_asserts test_assert_less │ test_asserts test_assert_less_or_equal │ test_asserts test_assert_not_equal │ ⨯ test_dirs test_dirs_command │ test_logger test_critical │ test_logger test_debug │ test_logger test_error │ test_logger test_info │ test_logger test_warning │ test_std test_path_add │ ``` Upon investigating seeing this difference: ``` ╭───┬─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 0 │ /var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ │ 1 │ /private/var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ ╰───┴─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` This seems unrelated to my changes, but can investigate further if desired. # 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: Robert Waugh <robert@waugh.io>
2023-04-07 13:46:11 +02:00
"a character or regex that denotes what separates rows",
)
.named(
"number",
SyntaxShape::Int,
"Split into maximum number of items",
Some('n'),
)
Add regex separators for split row/list/column (#8707) # Description Verified on discord with maintainer Change adds regex separators in split rows/column/list. The primary motivating reason was to make it easier to split on separators with unbounded whitespace without requiring a lot of trim jiggery. But, secondary motivation is the same as the set of all motivations for adding split regex features to most languages. # User-Facing Changes Adds -r option to split rows/column/list. # Tests + Formatting Ran tests, however tests.nu fails with unrelated errors: ``` ~/src/nushell> cargo run -- crates/nu-utils/standard_library/tests.nu 04/02/2023 02:07:25 AM Finished dev [unoptimized + debuginfo] target(s) in 0.24s Running `target/debug/nu crates/nu-utils/standard_library/tests.nu` INF|2023-04-02T02:07:27.060|Running tests in test_asserts INF|2023-04-02T02:07:27.141|Running tests in test_dirs Error: × list is just pwd after initialization INF|2023-04-02T02:07:27.167|Running tests in test_logger INF|2023-04-02T02:07:27.286|Running tests in test_std Error: × some tests did not pass (see complete errors above): │ │ test_asserts test_assert │ test_asserts test_assert_equal │ test_asserts test_assert_error │ test_asserts test_assert_greater │ test_asserts test_assert_greater_or_equal │ test_asserts test_assert_length │ test_asserts test_assert_less │ test_asserts test_assert_less_or_equal │ test_asserts test_assert_not_equal │ ⨯ test_dirs test_dirs_command │ test_logger test_critical │ test_logger test_debug │ test_logger test_error │ test_logger test_info │ test_logger test_warning │ test_std test_path_add │ ``` Upon investigating seeing this difference: ``` ╭───┬─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 0 │ /var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ │ 1 │ /private/var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ ╰───┴─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` This seems unrelated to my changes, but can investigate further if desired. # 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: Robert Waugh <robert@waugh.io>
2023-04-07 13:46:11 +02:00
.switch("regex", "use regex syntax for separator", Some('r'))
.category(Category::Strings)
2021-10-09 04:45:25 +02:00
}
fn usage(&self) -> &str {
"Split a string into multiple rows using a separator."
2021-10-09 04:45:25 +02:00
}
fn search_terms(&self) -> Vec<&str> {
vec!["separate", "divide", "regex"]
}
2021-10-09 04:45:25 +02:00
fn run(
&self,
2021-10-25 08:31:39 +02:00
engine_state: &EngineState,
stack: &mut Stack,
2021-10-09 04:45:25 +02:00
call: &Call,
2021-10-25 06:01:02 +02:00
input: PipelineData,
) -> Result<PipelineData, ShellError> {
2021-10-25 08:31:39 +02:00
split_row(engine_state, stack, call, input)
2021-10-09 04:45:25 +02:00
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Split a string into rows of char",
example: "'abc' | split row ''",
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>
2023-09-03 16:27:29 +02:00
result: Some(Value::list(
vec![
Value::test_string(""),
Value::test_string("a"),
Value::test_string("b"),
Value::test_string("c"),
Value::test_string(""),
],
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>
2023-09-03 16:27:29 +02:00
Span::test_data(),
)),
},
Example {
description: "Split a string into rows by the specified separator",
example: "'a--b--c' | split row '--'",
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>
2023-09-03 16:27:29 +02:00
result: Some(Value::list(
vec![
Value::test_string("a"),
Value::test_string("b"),
Value::test_string("c"),
],
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>
2023-09-03 16:27:29 +02:00
Span::test_data(),
)),
},
Example {
description: "Split a string by '-'",
example: "'-a-b-c-' | split row '-'",
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>
2023-09-03 16:27:29 +02:00
result: Some(Value::list(
vec![
Value::test_string(""),
Value::test_string("a"),
Value::test_string("b"),
Value::test_string("c"),
Value::test_string(""),
],
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>
2023-09-03 16:27:29 +02:00
Span::test_data(),
)),
},
Add regex separators for split row/list/column (#8707) # Description Verified on discord with maintainer Change adds regex separators in split rows/column/list. The primary motivating reason was to make it easier to split on separators with unbounded whitespace without requiring a lot of trim jiggery. But, secondary motivation is the same as the set of all motivations for adding split regex features to most languages. # User-Facing Changes Adds -r option to split rows/column/list. # Tests + Formatting Ran tests, however tests.nu fails with unrelated errors: ``` ~/src/nushell> cargo run -- crates/nu-utils/standard_library/tests.nu 04/02/2023 02:07:25 AM Finished dev [unoptimized + debuginfo] target(s) in 0.24s Running `target/debug/nu crates/nu-utils/standard_library/tests.nu` INF|2023-04-02T02:07:27.060|Running tests in test_asserts INF|2023-04-02T02:07:27.141|Running tests in test_dirs Error: × list is just pwd after initialization INF|2023-04-02T02:07:27.167|Running tests in test_logger INF|2023-04-02T02:07:27.286|Running tests in test_std Error: × some tests did not pass (see complete errors above): │ │ test_asserts test_assert │ test_asserts test_assert_equal │ test_asserts test_assert_error │ test_asserts test_assert_greater │ test_asserts test_assert_greater_or_equal │ test_asserts test_assert_length │ test_asserts test_assert_less │ test_asserts test_assert_less_or_equal │ test_asserts test_assert_not_equal │ ⨯ test_dirs test_dirs_command │ test_logger test_critical │ test_logger test_debug │ test_logger test_error │ test_logger test_info │ test_logger test_warning │ test_std test_path_add │ ``` Upon investigating seeing this difference: ``` ╭───┬─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 0 │ /var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ │ 1 │ /private/var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ ╰───┴─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` This seems unrelated to my changes, but can investigate further if desired. # 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: Robert Waugh <robert@waugh.io>
2023-04-07 13:46:11 +02:00
Example {
description: "Split a string by regex",
example: r"'a b c' | split row -r '\s+'",
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>
2023-09-03 16:27:29 +02:00
result: Some(Value::list(
vec![
Add regex separators for split row/list/column (#8707) # Description Verified on discord with maintainer Change adds regex separators in split rows/column/list. The primary motivating reason was to make it easier to split on separators with unbounded whitespace without requiring a lot of trim jiggery. But, secondary motivation is the same as the set of all motivations for adding split regex features to most languages. # User-Facing Changes Adds -r option to split rows/column/list. # Tests + Formatting Ran tests, however tests.nu fails with unrelated errors: ``` ~/src/nushell> cargo run -- crates/nu-utils/standard_library/tests.nu 04/02/2023 02:07:25 AM Finished dev [unoptimized + debuginfo] target(s) in 0.24s Running `target/debug/nu crates/nu-utils/standard_library/tests.nu` INF|2023-04-02T02:07:27.060|Running tests in test_asserts INF|2023-04-02T02:07:27.141|Running tests in test_dirs Error: × list is just pwd after initialization INF|2023-04-02T02:07:27.167|Running tests in test_logger INF|2023-04-02T02:07:27.286|Running tests in test_std Error: × some tests did not pass (see complete errors above): │ │ test_asserts test_assert │ test_asserts test_assert_equal │ test_asserts test_assert_error │ test_asserts test_assert_greater │ test_asserts test_assert_greater_or_equal │ test_asserts test_assert_length │ test_asserts test_assert_less │ test_asserts test_assert_less_or_equal │ test_asserts test_assert_not_equal │ ⨯ test_dirs test_dirs_command │ test_logger test_critical │ test_logger test_debug │ test_logger test_error │ test_logger test_info │ test_logger test_warning │ test_std test_path_add │ ``` Upon investigating seeing this difference: ``` ╭───┬─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 0 │ /var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ │ 1 │ /private/var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ ╰───┴─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` This seems unrelated to my changes, but can investigate further if desired. # 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: Robert Waugh <robert@waugh.io>
2023-04-07 13:46:11 +02:00
Value::test_string("a"),
Value::test_string("b"),
Value::test_string("c"),
],
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>
2023-09-03 16:27:29 +02:00
Span::test_data(),
)),
Add regex separators for split row/list/column (#8707) # Description Verified on discord with maintainer Change adds regex separators in split rows/column/list. The primary motivating reason was to make it easier to split on separators with unbounded whitespace without requiring a lot of trim jiggery. But, secondary motivation is the same as the set of all motivations for adding split regex features to most languages. # User-Facing Changes Adds -r option to split rows/column/list. # Tests + Formatting Ran tests, however tests.nu fails with unrelated errors: ``` ~/src/nushell> cargo run -- crates/nu-utils/standard_library/tests.nu 04/02/2023 02:07:25 AM Finished dev [unoptimized + debuginfo] target(s) in 0.24s Running `target/debug/nu crates/nu-utils/standard_library/tests.nu` INF|2023-04-02T02:07:27.060|Running tests in test_asserts INF|2023-04-02T02:07:27.141|Running tests in test_dirs Error: × list is just pwd after initialization INF|2023-04-02T02:07:27.167|Running tests in test_logger INF|2023-04-02T02:07:27.286|Running tests in test_std Error: × some tests did not pass (see complete errors above): │ │ test_asserts test_assert │ test_asserts test_assert_equal │ test_asserts test_assert_error │ test_asserts test_assert_greater │ test_asserts test_assert_greater_or_equal │ test_asserts test_assert_length │ test_asserts test_assert_less │ test_asserts test_assert_less_or_equal │ test_asserts test_assert_not_equal │ ⨯ test_dirs test_dirs_command │ test_logger test_critical │ test_logger test_debug │ test_logger test_error │ test_logger test_info │ test_logger test_warning │ test_std test_path_add │ ``` Upon investigating seeing this difference: ``` ╭───┬─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 0 │ /var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ │ 1 │ /private/var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ ╰───┴─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` This seems unrelated to my changes, but can investigate further if desired. # 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: Robert Waugh <robert@waugh.io>
2023-04-07 13:46:11 +02:00
},
]
}
2021-10-09 04:45:25 +02:00
}
fn split_row(
2021-10-25 08:31:39 +02:00
engine_state: &EngineState,
stack: &mut Stack,
2021-10-09 04:45:25 +02:00
call: &Call,
2021-10-25 06:01:02 +02:00
input: PipelineData,
) -> Result<PipelineData, ShellError> {
2021-10-09 04:45:25 +02:00
let name_span = call.head;
2021-10-25 08:31:39 +02:00
let separator: Spanned<String> = call.req(engine_state, stack, 0)?;
Add regex separators for split row/list/column (#8707) # Description Verified on discord with maintainer Change adds regex separators in split rows/column/list. The primary motivating reason was to make it easier to split on separators with unbounded whitespace without requiring a lot of trim jiggery. But, secondary motivation is the same as the set of all motivations for adding split regex features to most languages. # User-Facing Changes Adds -r option to split rows/column/list. # Tests + Formatting Ran tests, however tests.nu fails with unrelated errors: ``` ~/src/nushell> cargo run -- crates/nu-utils/standard_library/tests.nu 04/02/2023 02:07:25 AM Finished dev [unoptimized + debuginfo] target(s) in 0.24s Running `target/debug/nu crates/nu-utils/standard_library/tests.nu` INF|2023-04-02T02:07:27.060|Running tests in test_asserts INF|2023-04-02T02:07:27.141|Running tests in test_dirs Error: × list is just pwd after initialization INF|2023-04-02T02:07:27.167|Running tests in test_logger INF|2023-04-02T02:07:27.286|Running tests in test_std Error: × some tests did not pass (see complete errors above): │ │ test_asserts test_assert │ test_asserts test_assert_equal │ test_asserts test_assert_error │ test_asserts test_assert_greater │ test_asserts test_assert_greater_or_equal │ test_asserts test_assert_length │ test_asserts test_assert_less │ test_asserts test_assert_less_or_equal │ test_asserts test_assert_not_equal │ ⨯ test_dirs test_dirs_command │ test_logger test_critical │ test_logger test_debug │ test_logger test_error │ test_logger test_info │ test_logger test_warning │ test_std test_path_add │ ``` Upon investigating seeing this difference: ``` ╭───┬─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 0 │ /var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ │ 1 │ /private/var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ ╰───┴─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` This seems unrelated to my changes, but can investigate further if desired. # 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: Robert Waugh <robert@waugh.io>
2023-04-07 13:46:11 +02:00
let regex = if call.has_flag("regex") {
Regex::new(&separator.item)
} else {
let escaped = regex::escape(&separator.item);
Regex::new(&escaped)
}
.map_err(|err| {
ShellError::GenericError(
"Error with regular expression".into(),
err.to_string(),
Some(separator.span),
None,
Vec::new(),
)
})?;
let max_split: Option<usize> = call.get_flag(engine_state, stack, "number")?;
2021-10-28 06:13:10 +02:00
input.flat_map(
Add regex separators for split row/list/column (#8707) # Description Verified on discord with maintainer Change adds regex separators in split rows/column/list. The primary motivating reason was to make it easier to split on separators with unbounded whitespace without requiring a lot of trim jiggery. But, secondary motivation is the same as the set of all motivations for adding split regex features to most languages. # User-Facing Changes Adds -r option to split rows/column/list. # Tests + Formatting Ran tests, however tests.nu fails with unrelated errors: ``` ~/src/nushell> cargo run -- crates/nu-utils/standard_library/tests.nu 04/02/2023 02:07:25 AM Finished dev [unoptimized + debuginfo] target(s) in 0.24s Running `target/debug/nu crates/nu-utils/standard_library/tests.nu` INF|2023-04-02T02:07:27.060|Running tests in test_asserts INF|2023-04-02T02:07:27.141|Running tests in test_dirs Error: × list is just pwd after initialization INF|2023-04-02T02:07:27.167|Running tests in test_logger INF|2023-04-02T02:07:27.286|Running tests in test_std Error: × some tests did not pass (see complete errors above): │ │ test_asserts test_assert │ test_asserts test_assert_equal │ test_asserts test_assert_error │ test_asserts test_assert_greater │ test_asserts test_assert_greater_or_equal │ test_asserts test_assert_length │ test_asserts test_assert_less │ test_asserts test_assert_less_or_equal │ test_asserts test_assert_not_equal │ ⨯ test_dirs test_dirs_command │ test_logger test_critical │ test_logger test_debug │ test_logger test_error │ test_logger test_info │ test_logger test_warning │ test_std test_path_add │ ``` Upon investigating seeing this difference: ``` ╭───┬─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 0 │ /var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ │ 1 │ /private/var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ ╰───┴─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` This seems unrelated to my changes, but can investigate further if desired. # 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: Robert Waugh <robert@waugh.io>
2023-04-07 13:46:11 +02:00
move |x| split_row_helper(&x, &regex, max_split, name_span),
2021-10-28 06:13:10 +02:00
engine_state.ctrlc.clone(),
)
2021-10-09 04:45:25 +02:00
}
Add regex separators for split row/list/column (#8707) # Description Verified on discord with maintainer Change adds regex separators in split rows/column/list. The primary motivating reason was to make it easier to split on separators with unbounded whitespace without requiring a lot of trim jiggery. But, secondary motivation is the same as the set of all motivations for adding split regex features to most languages. # User-Facing Changes Adds -r option to split rows/column/list. # Tests + Formatting Ran tests, however tests.nu fails with unrelated errors: ``` ~/src/nushell> cargo run -- crates/nu-utils/standard_library/tests.nu 04/02/2023 02:07:25 AM Finished dev [unoptimized + debuginfo] target(s) in 0.24s Running `target/debug/nu crates/nu-utils/standard_library/tests.nu` INF|2023-04-02T02:07:27.060|Running tests in test_asserts INF|2023-04-02T02:07:27.141|Running tests in test_dirs Error: × list is just pwd after initialization INF|2023-04-02T02:07:27.167|Running tests in test_logger INF|2023-04-02T02:07:27.286|Running tests in test_std Error: × some tests did not pass (see complete errors above): │ │ test_asserts test_assert │ test_asserts test_assert_equal │ test_asserts test_assert_error │ test_asserts test_assert_greater │ test_asserts test_assert_greater_or_equal │ test_asserts test_assert_length │ test_asserts test_assert_less │ test_asserts test_assert_less_or_equal │ test_asserts test_assert_not_equal │ ⨯ test_dirs test_dirs_command │ test_logger test_critical │ test_logger test_debug │ test_logger test_error │ test_logger test_info │ test_logger test_warning │ test_std test_path_add │ ``` Upon investigating seeing this difference: ``` ╭───┬─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 0 │ /var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ │ 1 │ /private/var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ ╰───┴─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` This seems unrelated to my changes, but can investigate further if desired. # 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: Robert Waugh <robert@waugh.io>
2023-04-07 13:46:11 +02:00
fn split_row_helper(v: &Value, regex: &Regex, max_split: Option<usize>, name: Span) -> Vec<Value> {
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>
2023-09-03 16:27:29 +02:00
let span = v.span();
Spanned Value step 1: span all value cases (#10042) # Description This doesn't really do much that the user could see, but it helps get us ready to do the steps of the refactor to split the span off of Value, so that values can be spanless. This allows us to have top-level values that can hold both a Value and a Span, without requiring that all values have them. We expect to see significant memory reduction by removing so many unnecessary spans from values. For example, a table of 100,000 rows and 5 columns would have a savings of ~8megs in just spans that are almost always duplicated. # User-Facing Changes Nothing yet # 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 -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `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. -->
2023-08-24 22:48:05 +02:00
match v {
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>
2023-09-03 16:27:29 +02:00
Value::Error { error, .. } => {
vec![Value::error(*error.clone(), span)]
Spanned Value step 1: span all value cases (#10042) # Description This doesn't really do much that the user could see, but it helps get us ready to do the steps of the refactor to split the span off of Value, so that values can be spanless. This allows us to have top-level values that can hold both a Value and a Span, without requiring that all values have them. We expect to see significant memory reduction by removing so many unnecessary spans from values. For example, a table of 100,000 rows and 5 columns would have a savings of ~8megs in just spans that are almost always duplicated. # User-Facing Changes Nothing yet # 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 -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `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. -->
2023-08-24 22:48:05 +02:00
}
v => {
let v_span = v.span();
2021-10-11 20:45:31 +02:00
if let Ok(s) = v.as_string() {
match max_split {
Add regex separators for split row/list/column (#8707) # Description Verified on discord with maintainer Change adds regex separators in split rows/column/list. The primary motivating reason was to make it easier to split on separators with unbounded whitespace without requiring a lot of trim jiggery. But, secondary motivation is the same as the set of all motivations for adding split regex features to most languages. # User-Facing Changes Adds -r option to split rows/column/list. # Tests + Formatting Ran tests, however tests.nu fails with unrelated errors: ``` ~/src/nushell> cargo run -- crates/nu-utils/standard_library/tests.nu 04/02/2023 02:07:25 AM Finished dev [unoptimized + debuginfo] target(s) in 0.24s Running `target/debug/nu crates/nu-utils/standard_library/tests.nu` INF|2023-04-02T02:07:27.060|Running tests in test_asserts INF|2023-04-02T02:07:27.141|Running tests in test_dirs Error: × list is just pwd after initialization INF|2023-04-02T02:07:27.167|Running tests in test_logger INF|2023-04-02T02:07:27.286|Running tests in test_std Error: × some tests did not pass (see complete errors above): │ │ test_asserts test_assert │ test_asserts test_assert_equal │ test_asserts test_assert_error │ test_asserts test_assert_greater │ test_asserts test_assert_greater_or_equal │ test_asserts test_assert_length │ test_asserts test_assert_less │ test_asserts test_assert_less_or_equal │ test_asserts test_assert_not_equal │ ⨯ test_dirs test_dirs_command │ test_logger test_critical │ test_logger test_debug │ test_logger test_error │ test_logger test_info │ test_logger test_warning │ test_std test_path_add │ ``` Upon investigating seeing this difference: ``` ╭───┬─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 0 │ /var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ │ 1 │ /private/var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ ╰───┴─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` This seems unrelated to my changes, but can investigate further if desired. # 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: Robert Waugh <robert@waugh.io>
2023-04-07 13:46:11 +02:00
Some(max_split) => regex
.splitn(&s, max_split)
.map(|x: &str| Value::string(x, v_span))
.collect(),
Add regex separators for split row/list/column (#8707) # Description Verified on discord with maintainer Change adds regex separators in split rows/column/list. The primary motivating reason was to make it easier to split on separators with unbounded whitespace without requiring a lot of trim jiggery. But, secondary motivation is the same as the set of all motivations for adding split regex features to most languages. # User-Facing Changes Adds -r option to split rows/column/list. # Tests + Formatting Ran tests, however tests.nu fails with unrelated errors: ``` ~/src/nushell> cargo run -- crates/nu-utils/standard_library/tests.nu 04/02/2023 02:07:25 AM Finished dev [unoptimized + debuginfo] target(s) in 0.24s Running `target/debug/nu crates/nu-utils/standard_library/tests.nu` INF|2023-04-02T02:07:27.060|Running tests in test_asserts INF|2023-04-02T02:07:27.141|Running tests in test_dirs Error: × list is just pwd after initialization INF|2023-04-02T02:07:27.167|Running tests in test_logger INF|2023-04-02T02:07:27.286|Running tests in test_std Error: × some tests did not pass (see complete errors above): │ │ test_asserts test_assert │ test_asserts test_assert_equal │ test_asserts test_assert_error │ test_asserts test_assert_greater │ test_asserts test_assert_greater_or_equal │ test_asserts test_assert_length │ test_asserts test_assert_less │ test_asserts test_assert_less_or_equal │ test_asserts test_assert_not_equal │ ⨯ test_dirs test_dirs_command │ test_logger test_critical │ test_logger test_debug │ test_logger test_error │ test_logger test_info │ test_logger test_warning │ test_std test_path_add │ ``` Upon investigating seeing this difference: ``` ╭───┬─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 0 │ /var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ │ 1 │ /private/var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │ ╰───┴─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` This seems unrelated to my changes, but can investigate further if desired. # 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: Robert Waugh <robert@waugh.io>
2023-04-07 13:46:11 +02:00
None => regex
.split(&s)
.map(|x: &str| Value::string(x, v_span))
.collect(),
}
2021-10-11 20:45:31 +02:00
} else {
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>
2023-09-03 16:27:29 +02:00
vec![Value::error(
ShellError::PipelineMismatch {
exp_input_type: "string".into(),
dst_span: name,
src_span: v_span,
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>
2023-09-03 16:27:29 +02:00
},
name,
)]
2021-10-11 20:45:31 +02:00
}
}
2021-10-09 04:45:25 +02:00
}
}
#[cfg(test)]
mod test {
use super::*;
2021-10-09 04:45:25 +02:00
#[test]
fn test_examples() {
use crate::test_examples;
2021-10-09 04:45:25 +02:00
test_examples(SubCommand {})
}
}