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
This commit is contained in:
Wind 2024-05-16 16:50:29 +08:00 committed by GitHub
parent e20113a0eb
commit 1b8eb23785
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -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,
..
})
)

View File

@ -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")
}