Add -i flag back to get and select (#8488)

https://github.com/nushell/nushell/pull/8379 removed the `-i` flag from
`get` and `select` because the new `?` functionality covers most of the
same use cases. However, https://github.com/nushell/nushell/issues/8480
made me realize that `-i` is still useful when dealing with cell paths
in variables.

This PR re-adds the `-i` flag to `get` and `select`. It works by just
marking every member in the cell path as optional, which will behave
_slightly_ differently than `-i` used to (previously it would suppress
any errors, even type errors) but IMO that's OK.
This commit is contained in:
Reilly Wood
2023-03-16 11:50:04 -07:00
committed by GitHub
parent d74a260883
commit 1b2916988e
4 changed files with 50 additions and 2 deletions

View File

@ -241,3 +241,16 @@ fn get_does_not_delve_too_deep_in_nested_lists() {
assert!(actual.err.contains("cannot find column"));
}
#[test]
fn ignore_errors_works() {
let actual = nu!(
cwd: ".",
r#"
let path = "foo";
{} | get -i $path | to nuon
"#
);
assert_eq!(actual.out, "null");
}

View File

@ -256,3 +256,16 @@ fn select_failed4() {
assert!(actual.err.contains("Select can't get the same row twice"));
}
#[test]
fn ignore_errors_works() {
let actual = nu!(
cwd: ".",
r#"
let path = "foo";
[{}] | select -i $path | to nuon
"#
);
assert_eq!(actual.out, "[[foo]; [null]]");
}