From 1b8eb23785be7efdb7b1511416da77959ee6561b Mon Sep 17 00:00:00 2001 From: Wind Date: Thu, 16 May 2024 16:50:29 +0800 Subject: [PATCH] allow passing float value to custom command (#12879) # Description Fixes: #12691 In `parse_short_flag`, it only checks special cases for `SyntaxShape::Int`, `SyntaxShape::Number` to allow a flag to be a number. This pr adds `SyntaxShape::Float` to allow a flag to be float number. # User-Facing Changes This is possible after this pr: ```nushell def spam [val: float] { $val }; spam -1.4 ``` # Tests + Formatting Added 1 test --- crates/nu-parser/src/parser.rs | 2 +- tests/repl/test_custom_commands.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 3416e538df..0f72132d10 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -486,7 +486,7 @@ fn parse_short_flags( && matches!( sig.get_positional(positional_idx), Some(PositionalArg { - shape: SyntaxShape::Int | SyntaxShape::Number, + shape: SyntaxShape::Int | SyntaxShape::Number | SyntaxShape::Float, .. }) ) diff --git a/tests/repl/test_custom_commands.rs b/tests/repl/test_custom_commands.rs index 43a24fa250..1f36b0e90c 100644 --- a/tests/repl/test_custom_commands.rs +++ b/tests/repl/test_custom_commands.rs @@ -274,3 +274,9 @@ fn dont_allow_implicit_casting_between_glob_and_string() -> TestResult { "can't convert", ) } + +#[test] +fn allow_pass_negative_float() -> TestResult { + run_test("def spam [val: float] { $val }; spam -1.4", "-1.4")?; + run_test("def spam [val: float] { $val }; spam -2", "-2") +}