mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 09:53:43 +01:00
Remove --flag: bool
support (#11541)
# Description This is a follow up to: #11365 After this pr, `--flag: bool` is no longer allowed. I think `ParseWarning::Deprecated` is useful when we want to deprecated something at syntax level, so I just leave it there for now. # User-Facing Changes ## Before ``` ❯ def foo [--b: bool] {} Error: × Deprecated: --flag: bool ╭─[entry #15:1:1] 1 │ def foo [--b: bool] {} · ──┬─ · ╰── `--flag: bool` is deprecated and will be removed in 0.90. Please use `--flag` instead, more info: https://www.nushell.sh/book/custom_commands.html ╰──── ``` ## After ``` ❯ def foo [--b: bool] {} Error: × Type annotations are not allowed for boolean switches. ╭─[entry #2:1:1] 1 │ def foo [--b: bool] {} · ──┬─ · ╰── Remove the `: bool` type annotation. ╰──── ``` # Tests + Formatting Done
This commit is contained in:
parent
f286286510
commit
a4809d2f08
@ -172,19 +172,6 @@ fn def_default_value_should_restrict_implicit_type() {
|
||||
assert!(actual2.err.contains("expected int"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_boolean_flags() {
|
||||
let actual = nu!("def foo [--x: bool] { $x }; foo --x");
|
||||
assert!(actual.err.contains("flag missing bool argument"));
|
||||
let actual = nu!("def foo [--x: bool = false] { $x }; foo");
|
||||
assert_eq!(actual.out, "false");
|
||||
let actual = nu!("def foo [--x: bool = false] { $x }; foo --x");
|
||||
assert!(actual.err.contains("flag missing bool argument"));
|
||||
// boolean flags' default value should be null
|
||||
let actual = nu!("def foo [--x: bool] { $x == null }; foo");
|
||||
assert_eq!(actual.out, "true");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_wrapped_with_block() {
|
||||
let actual = nu!(
|
||||
|
@ -18,8 +18,8 @@ use nu_protocol::{
|
||||
},
|
||||
engine::StateWorkingSet,
|
||||
eval_const::eval_constant,
|
||||
span, BlockId, DidYouMean, Flag, ParseError, ParseWarning, PositionalArg, Signature, Span,
|
||||
Spanned, SyntaxShape, Type, Unit, VarId, ENV_VARIABLE_ID, IN_VARIABLE_ID,
|
||||
span, BlockId, DidYouMean, Flag, ParseError, PositionalArg, Signature, Span, Spanned,
|
||||
SyntaxShape, Type, Unit, VarId, ENV_VARIABLE_ID, IN_VARIABLE_ID,
|
||||
};
|
||||
|
||||
use crate::parse_keywords::{
|
||||
@ -3603,9 +3603,9 @@ pub fn parse_signature_helper(working_set: &mut StateWorkingSet, span: Span) ->
|
||||
} => {
|
||||
working_set.set_variable_type(var_id.expect("internal error: all custom parameters must have var_ids"), syntax_shape.to_type());
|
||||
if syntax_shape == SyntaxShape::Boolean {
|
||||
working_set.warning(ParseWarning::DeprecatedWarning(
|
||||
"--flag: bool".to_string(),
|
||||
"--flag".to_string(),
|
||||
working_set.error(ParseError::LabeledError(
|
||||
"Type annotations are not allowed for boolean switches.".to_string(),
|
||||
"Remove the `: bool` type annotation.".to_string(),
|
||||
span,
|
||||
));
|
||||
}
|
||||
|
@ -149,8 +149,7 @@ fn custom_flag2() -> TestResult {
|
||||
#[test]
|
||||
fn deprecated_boolean_flag() {
|
||||
let actual = nu!(r#"def florb [--dry-run: bool, --another-flag] { "aaa" }; florb"#);
|
||||
assert!(actual.err.contains("Deprecated"));
|
||||
assert_eq!(actual.out, "aaa");
|
||||
assert!(actual.err.contains("not allowed"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user