diff --git a/crates/nu-command/src/filters/default.rs b/crates/nu-command/src/filters/default.rs index 9d9799df23..18dd220376 100644 --- a/crates/nu-command/src/filters/default.rs +++ b/crates/nu-command/src/filters/default.rs @@ -82,7 +82,7 @@ impl Command for Default { }, Example { description: "Get the env value of `MY_ENV` with a default value 'abc' if not present", - example: "$env | get --ignore-errors MY_ENV | default 'abc'", + example: "$env | get --optional MY_ENV | default 'abc'", result: Some(Value::test_string("abc")), }, Example { diff --git a/crates/nu-command/src/filters/get.rs b/crates/nu-command/src/filters/get.rs index ba770d1e66..4a09fd3cf2 100644 --- a/crates/nu-command/src/filters/get.rs +++ b/crates/nu-command/src/filters/get.rs @@ -40,9 +40,14 @@ If multiple cell paths are given, this will produce a list of values."# "The cell path to the data.", ) .rest("rest", SyntaxShape::CellPath, "Additional cell paths.") + .switch( + "optional", + "make all cell path members optional (returns `null` for missing values)", + Some('o'), + ) .switch( "ignore-errors", - "ignore missing data (make all cell path members optional)", + "ignore missing data (make all cell path members optional) (deprecated)", Some('i'), ) .switch( @@ -131,13 +136,14 @@ If multiple cell paths are given, this will produce a list of values."# ) -> Result { let cell_path: CellPath = call.req(engine_state, stack, 0)?; let rest: Vec = call.rest(engine_state, stack, 1)?; - let ignore_errors = call.has_flag(engine_state, stack, "ignore-errors")?; + let optional = call.has_flag(engine_state, stack, "optional")? + || call.has_flag(engine_state, stack, "ignore-errors")?; let metadata = input.metadata(); action( input, cell_path, rest, - ignore_errors, + optional, engine_state.signals().clone(), call.head, ) @@ -152,6 +158,13 @@ If multiple cell paths are given, this will produce a list of values."# since: Some("0.105.0".into()), expected_removal: None, help: Some("Cell-paths are now case-sensitive by default.\nTo access fields case-insensitively, add `!` after the relevant path member.".into()) + }, + DeprecationEntry { + ty: DeprecationType::Flag("ignore-errors".into()), + report_mode: ReportMode::FirstUse, + since: Some("0.106.0".into()), + expected_removal: None, + help: Some("This flag has been renamed to `--optional (-o)` to better reflect its behavior.".into()) } ] } @@ -161,11 +174,11 @@ fn action( input: PipelineData, mut cell_path: CellPath, mut rest: Vec, - ignore_errors: bool, + optional: bool, signals: Signals, span: Span, ) -> Result { - if ignore_errors { + if optional { cell_path.make_optional(); for path in &mut rest { path.make_optional(); diff --git a/crates/nu-command/src/filters/reject.rs b/crates/nu-command/src/filters/reject.rs index 8672242b83..b51dd1b73a 100644 --- a/crates/nu-command/src/filters/reject.rs +++ b/crates/nu-command/src/filters/reject.rs @@ -1,5 +1,5 @@ use nu_engine::command_prelude::*; -use nu_protocol::{ast::PathMember, casing::Casing}; +use nu_protocol::{DeprecationEntry, DeprecationType, ReportMode, ast::PathMember, casing::Casing}; use std::{cmp::Reverse, collections::HashSet}; #[derive(Clone)] @@ -17,9 +17,10 @@ impl Command for Reject { (Type::table(), Type::table()), (Type::list(Type::Any), Type::list(Type::Any)), ]) + .switch("optional", "make all cell path members optional", Some('o')) .switch( "ignore-errors", - "ignore missing data (make all cell path members optional)", + "ignore missing data (make all cell path members optional) (deprecated)", Some('i'), ) .rest( @@ -90,8 +91,9 @@ impl Command for Reject { } let span = call.head; - let ignore_errors = call.has_flag(engine_state, stack, "ignore-errors")?; - if ignore_errors { + let optional = call.has_flag(engine_state, stack, "optional")? + || call.has_flag(engine_state, stack, "ignore-errors")?; + if optional { for cell_path in &mut new_columns { cell_path.make_optional(); } @@ -100,6 +102,19 @@ impl Command for Reject { reject(engine_state, span, input, new_columns) } + fn deprecation_info(&self) -> Vec { + vec![DeprecationEntry { + ty: DeprecationType::Flag("ignore-errors".into()), + report_mode: ReportMode::FirstUse, + since: Some("0.106.0".into()), + expected_removal: None, + help: Some( + "This flag has been renamed to `--optional (-o)` to better reflect its behavior." + .into(), + ), + }] + } + fn examples(&self) -> Vec { vec![ Example { diff --git a/crates/nu-command/src/filters/select.rs b/crates/nu-command/src/filters/select.rs index 6055b38eea..06ce40f890 100644 --- a/crates/nu-command/src/filters/select.rs +++ b/crates/nu-command/src/filters/select.rs @@ -1,5 +1,8 @@ use nu_engine::command_prelude::*; -use nu_protocol::{PipelineIterator, ast::PathMember, casing::Casing}; +use nu_protocol::{ + DeprecationEntry, DeprecationType, PipelineIterator, ReportMode, ast::PathMember, + casing::Casing, +}; use std::collections::BTreeSet; #[derive(Clone)] @@ -18,9 +21,14 @@ impl Command for Select { (Type::table(), Type::table()), (Type::List(Box::new(Type::Any)), Type::Any), ]) + .switch( + "optional", + "make all cell path members optional (returns `null` for missing values)", + Some('o'), + ) .switch( "ignore-errors", - "ignore missing data (make all cell path members optional)", + "ignore missing data (make all cell path members optional) (deprecated)", Some('i'), ) .rest( @@ -100,10 +108,11 @@ produce a table, a list will produce a list, and a record will produce a record. } } } - let ignore_errors = call.has_flag(engine_state, stack, "ignore-errors")?; + let optional = call.has_flag(engine_state, stack, "optional")? + || call.has_flag(engine_state, stack, "ignore-errors")?; let span = call.head; - if ignore_errors { + if optional { for cell_path in &mut new_columns { cell_path.make_optional(); } @@ -112,6 +121,19 @@ produce a table, a list will produce a list, and a record will produce a record. select(engine_state, span, new_columns, input) } + fn deprecation_info(&self) -> Vec { + vec![DeprecationEntry { + ty: DeprecationType::Flag("ignore-errors".into()), + report_mode: ReportMode::FirstUse, + since: Some("0.106.0".into()), + expected_removal: None, + help: Some( + "This flag has been renamed to `--optional (-o)` to better reflect its behavior." + .into(), + ), + }] + } + fn examples(&self) -> Vec { vec![ Example { diff --git a/crates/nu-command/tests/commands/default.rs b/crates/nu-command/tests/commands/default.rs index c419030be3..1738ff8625 100644 --- a/crates/nu-command/tests/commands/default.rs +++ b/crates/nu-command/tests/commands/default.rs @@ -31,7 +31,7 @@ fn adds_row_data_if_column_missing() { #[test] fn default_after_empty_filter() { - let actual = nu!("[a b] | where $it == 'c' | get -i 0 | default 'd'"); + let actual = nu!("[a b] | where $it == 'c' | get -o 0 | default 'd'"); assert_eq!(actual.out, "d"); } diff --git a/crates/nu-command/tests/commands/get.rs b/crates/nu-command/tests/commands/get.rs index c5c1c02e95..411f2de32c 100644 --- a/crates/nu-command/tests/commands/get.rs +++ b/crates/nu-command/tests/commands/get.rs @@ -196,14 +196,14 @@ fn get_does_not_delve_too_deep_in_nested_lists() { #[test] fn ignore_errors_works() { - let actual = nu!(r#" let path = "foo"; {} | get -i $path | to nuon "#); + let actual = nu!(r#" let path = "foo"; {} | get -o $path | to nuon "#); assert_eq!(actual.out, "null"); } #[test] fn ignore_multiple() { - let actual = nu!(r#"[[a];[b]] | get -i c d | to nuon"#); + let actual = nu!(r#"[[a];[b]] | get -o c d | to nuon"#); assert_eq!(actual.out, "[[null], [null]]"); } diff --git a/crates/nu-command/tests/commands/reject.rs b/crates/nu-command/tests/commands/reject.rs index 7db053e27c..74d4d0bce7 100644 --- a/crates/nu-command/tests/commands/reject.rs +++ b/crates/nu-command/tests/commands/reject.rs @@ -174,14 +174,14 @@ fn reject_multiple_rows_descending() { #[test] fn test_ignore_errors_flag() { - let actual = nu!("[[a, b]; [1, 2], [3, 4], [5, 6]] | reject 5 -i | to nuon"); + let actual = nu!("[[a, b]; [1, 2], [3, 4], [5, 6]] | reject 5 -o | to nuon"); assert_eq!(actual.out, "[[a, b]; [1, 2], [3, 4], [5, 6]]"); } #[test] fn test_ignore_errors_flag_var() { let actual = - nu!("let arg = [5 c]; [[a, b]; [1, 2], [3, 4], [5, 6]] | reject ...$arg -i | to nuon"); + nu!("let arg = [5 c]; [[a, b]; [1, 2], [3, 4], [5, 6]] | reject ...$arg -o | to nuon"); assert_eq!(actual.out, "[[a, b]; [1, 2], [3, 4], [5, 6]]"); } diff --git a/crates/nu-command/tests/commands/select.rs b/crates/nu-command/tests/commands/select.rs index 0b949792b8..9e0d6abb3a 100644 --- a/crates/nu-command/tests/commands/select.rs +++ b/crates/nu-command/tests/commands/select.rs @@ -236,7 +236,7 @@ fn select_repeated_column() { fn ignore_errors_works() { let actual = nu!(r#" let path = "foo"; - [{}] | select -i $path | to nuon + [{}] | select -o $path | to nuon "#); assert_eq!(actual.out, "[[foo]; [null]]"); diff --git a/crates/nu-command/tests/format_conversions/csv.rs b/crates/nu-command/tests/format_conversions/csv.rs index abdc31dc11..c7c88bf89e 100644 --- a/crates/nu-command/tests/format_conversions/csv.rs +++ b/crates/nu-command/tests/format_conversions/csv.rs @@ -326,7 +326,7 @@ fn from_csv_text_with_missing_columns_to_table() { r#" open los_tres_caballeros.txt | from csv --flexible - | get -i rusty_luck + | get -o rusty_luck | compact | length "# diff --git a/crates/nu-command/tests/format_conversions/tsv.rs b/crates/nu-command/tests/format_conversions/tsv.rs index 4a6a09f1f8..7c54cc236d 100644 --- a/crates/nu-command/tests/format_conversions/tsv.rs +++ b/crates/nu-command/tests/format_conversions/tsv.rs @@ -245,7 +245,7 @@ fn from_tsv_text_with_missing_columns_to_table() { r#" open los_tres_caballeros.txt | from tsv --flexible - | get -i rusty_luck + | get -o rusty_luck | compact | length "# diff --git a/crates/nu-std/testing.nu b/crates/nu-std/testing.nu index 624a927c67..ae2b225a3c 100644 --- a/crates/nu-std/testing.nu +++ b/crates/nu-std/testing.nu @@ -42,7 +42,7 @@ def get-annotated [ | from nuon | each {|e| # filter commands with test attributes, and map attributes to annotation name - let test_attributes = $e.attributes.name | each {|x| $valid_annotations | get -i $x } + let test_attributes = $e.attributes.name | each {|x| $valid_annotations | get -o $x } if ($test_attributes | is-not-empty) { $e | update attributes $test_attributes.0 } diff --git a/crates/nu-std/tests/logger_tests/test_basic_commands.nu b/crates/nu-std/tests/logger_tests/test_basic_commands.nu index e1616b7f18..b0fa88630e 100644 --- a/crates/nu-std/tests/logger_tests/test_basic_commands.nu +++ b/crates/nu-std/tests/logger_tests/test_basic_commands.nu @@ -11,7 +11,7 @@ def run [ } else { ^$nu.current-exe --no-config-file --commands $'use std; use std/log; NU_LOG_LEVEL=($system_level) log ($message_level) "test message"' } - | complete | get --ignore-errors stderr + | complete | get --optional stderr } def "assert no message" [ diff --git a/crates/nu-std/tests/logger_tests/test_log_custom.nu b/crates/nu-std/tests/logger_tests/test_log_custom.nu index be9c8a30fc..8af5566b29 100644 --- a/crates/nu-std/tests/logger_tests/test_log_custom.nu +++ b/crates/nu-std/tests/logger_tests/test_log_custom.nu @@ -19,7 +19,7 @@ def run-command [ } else { ^$nu.current-exe --no-config-file --commands $'use std/log; NU_LOG_LEVEL=($system_level) log custom "($message)" "($format)" ($log_level) --level-prefix "($level_prefix)" --ansi "($ansi)"' } - | complete | get --ignore-errors stderr + | complete | get --optional stderr } @test diff --git a/crates/nu-std/tests/logger_tests/test_log_format_flag.nu b/crates/nu-std/tests/logger_tests/test_log_format_flag.nu index 76b1725e04..df3c01982d 100644 --- a/crates/nu-std/tests/logger_tests/test_log_format_flag.nu +++ b/crates/nu-std/tests/logger_tests/test_log_format_flag.nu @@ -16,7 +16,7 @@ def run-command [ } else { ^$nu.current-exe --no-config-file --commands $'use std; use std/log; NU_LOG_LEVEL=($system_level) log ($message_level) --format "($format)" "($message)"' } - | complete | get --ignore-errors stderr + | complete | get --optional stderr } diff --git a/tests/parsing/samples/recursive_func_with_alias.nu b/tests/parsing/samples/recursive_func_with_alias.nu index 66dc3b5f11..04dc92ce8c 100644 --- a/tests/parsing/samples/recursive_func_with_alias.nu +++ b/tests/parsing/samples/recursive_func_with_alias.nu @@ -10,7 +10,7 @@ export def "update" [ let input = $in match ($input | describe | str replace --regex '<.*' '') { record => { - if ($input | get -i $field) != null { + if ($input | get -o $field) != null { $input | orig update $field $value } else { $input } }