mirror of
https://github.com/nushell/nushell
synced 2024-12-26 04:53:09 +00:00
deprecate --ignore-shell-errors and --ignore-program-errors in do
(#14385)
# Description As title, this pr is going to deprecate `--ignore-shell-errors` and `--ignore-program-errors`. Because I think these two flags makes `do` command complicate, and it should be easy to use `-i` instead. # User-Facing Changes After the pr, using these two flags will raise deprecated warning. ```nushell > do --ignore-program-errors { ^pwd } Error: × Deprecated option ╭─[entry #2:1:1] 1 │ do --ignore-program-errors { ^pwd } · ─┬ · ╰── `--ignore-program-errors` is deprecated and will be removed in 0.102.0. ╰──── help: Please use the `--ignore-errors(-i)` /home/windsoilder/projects/nushell > do --ignore-shell-errors { ^pwd } Error: × Deprecated option ╭─[entry #3:1:1] 1 │ do --ignore-shell-errors { ^pwd } · ─┬ · ╰── `--ignore-shell-errors` is deprecated and will be removed in 0.102.0. ╰──── help: Please use the `--ignore-errors(-i)` /home/windsoilder/projects/nushell ``` # Tests + Formatting NaN
This commit is contained in:
parent
4edce44689
commit
e0c0d39ede
3 changed files with 32 additions and 14 deletions
|
@ -69,6 +69,33 @@ impl Command for Do {
|
||||||
let block: Closure = call.req(engine_state, caller_stack, 0)?;
|
let block: Closure = call.req(engine_state, caller_stack, 0)?;
|
||||||
let rest: Vec<Value> = call.rest(engine_state, caller_stack, 1)?;
|
let rest: Vec<Value> = call.rest(engine_state, caller_stack, 1)?;
|
||||||
let ignore_all_errors = call.has_flag(engine_state, caller_stack, "ignore-errors")?;
|
let ignore_all_errors = call.has_flag(engine_state, caller_stack, "ignore-errors")?;
|
||||||
|
|
||||||
|
if call.has_flag(engine_state, caller_stack, "ignore-shell-errors")? {
|
||||||
|
nu_protocol::report_shell_warning(
|
||||||
|
engine_state,
|
||||||
|
&ShellError::GenericError {
|
||||||
|
error: "Deprecated option".into(),
|
||||||
|
msg: "`--ignore-shell-errors` is deprecated and will be removed in 0.102.0."
|
||||||
|
.into(),
|
||||||
|
span: Some(call.head),
|
||||||
|
help: Some("Please use the `--ignore-errors(-i)`".into()),
|
||||||
|
inner: vec![],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if call.has_flag(engine_state, caller_stack, "ignore-program-errors")? {
|
||||||
|
nu_protocol::report_shell_warning(
|
||||||
|
engine_state,
|
||||||
|
&ShellError::GenericError {
|
||||||
|
error: "Deprecated option".into(),
|
||||||
|
msg: "`--ignore-program-errors` is deprecated and will be removed in 0.102.0."
|
||||||
|
.into(),
|
||||||
|
span: Some(call.head),
|
||||||
|
help: Some("Please use the `--ignore-errors(-i)`".into()),
|
||||||
|
inner: vec![],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
let ignore_shell_errors = ignore_all_errors
|
let ignore_shell_errors = ignore_all_errors
|
||||||
|| call.has_flag(engine_state, caller_stack, "ignore-shell-errors")?;
|
|| call.has_flag(engine_state, caller_stack, "ignore-shell-errors")?;
|
||||||
let ignore_program_errors = ignore_all_errors
|
let ignore_program_errors = ignore_all_errors
|
||||||
|
@ -208,16 +235,6 @@ impl Command for Do {
|
||||||
example: r#"do --ignore-errors { thisisnotarealcommand }"#,
|
example: r#"do --ignore-errors { thisisnotarealcommand }"#,
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
Example {
|
|
||||||
description: "Run the closure and ignore shell errors",
|
|
||||||
example: r#"do --ignore-shell-errors { thisisnotarealcommand }"#,
|
|
||||||
result: None,
|
|
||||||
},
|
|
||||||
Example {
|
|
||||||
description: "Run the closure and ignore external program errors",
|
|
||||||
example: r#"do --ignore-program-errors { nu --commands 'exit 1' }; echo "I'll still run""#,
|
|
||||||
result: None,
|
|
||||||
},
|
|
||||||
Example {
|
Example {
|
||||||
description: "Abort the pipeline if a program returns a non-zero exit code",
|
description: "Abort the pipeline if a program returns a non-zero exit code",
|
||||||
example: r#"do --capture-errors { nu --commands 'exit 1' } | myscarycommand"#,
|
example: r#"do --capture-errors { nu --commands 'exit 1' } | myscarycommand"#,
|
||||||
|
|
|
@ -44,7 +44,7 @@ fn do_with_semicolon_break_on_failed_external() {
|
||||||
fn ignore_shell_errors_works_for_external_with_semicolon() {
|
fn ignore_shell_errors_works_for_external_with_semicolon() {
|
||||||
let actual = nu!(r#"do -s { open asdfasdf.txt }; "text""#);
|
let actual = nu!(r#"do -s { open asdfasdf.txt }; "text""#);
|
||||||
|
|
||||||
assert_eq!(actual.err, "");
|
assert!(actual.err.contains("Deprecated option"));
|
||||||
assert_eq!(actual.out, "text");
|
assert_eq!(actual.out, "text");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ fn ignore_shell_errors_works_for_external_with_semicolon() {
|
||||||
fn ignore_program_errors_works_for_external_with_semicolon() {
|
fn ignore_program_errors_works_for_external_with_semicolon() {
|
||||||
let actual = nu!(r#"do -p { nu -n -c 'exit 1' }; "text""#);
|
let actual = nu!(r#"do -p { nu -n -c 'exit 1' }; "text""#);
|
||||||
|
|
||||||
assert_eq!(actual.err, "");
|
assert!(actual.err.contains("Deprecated option"));
|
||||||
assert_eq!(actual.out, "text");
|
assert_eq!(actual.out, "text");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ fn run_closure_with_it_using() {
|
||||||
#[test]
|
#[test]
|
||||||
fn waits_for_external() {
|
fn waits_for_external() {
|
||||||
let actual = nu!(r#"do -p { nu -c 'sleep 1sec; print before; exit 1'}; print after"#);
|
let actual = nu!(r#"do -p { nu -c 'sleep 1sec; print before; exit 1'}; print after"#);
|
||||||
assert!(actual.err.is_empty());
|
|
||||||
|
assert!(actual.err.contains("Deprecated option"));
|
||||||
assert_eq!(actual.out, "beforeafter");
|
assert_eq!(actual.out, "beforeafter");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
# version = "0.100.1"
|
# version = "0.100.1"
|
||||||
|
|
||||||
$env.PROMPT_COMMAND = {||
|
$env.PROMPT_COMMAND = {||
|
||||||
let dir = match (do --ignore-shell-errors { $env.PWD | path relative-to $nu.home-path }) {
|
let dir = match (do -i { $env.PWD | path relative-to $nu.home-path }) {
|
||||||
null => $env.PWD
|
null => $env.PWD
|
||||||
'' => '~'
|
'' => '~'
|
||||||
$relative_pwd => ([~ $relative_pwd] | path join)
|
$relative_pwd => ([~ $relative_pwd] | path join)
|
||||||
|
|
Loading…
Reference in a new issue