differentiating between --x and --x: bool#10456
Conversation
|
ooh i see what this is doing 😮 i'm not sure i am a big fan of requiring to pass as soon as something has a type, either explicitely with boolean flags, a.k.a. switches, a.k.a. flags, are then special and can only be defined with yeah, i can buy that 👍 ❗ however this is a breaking change, all the options / switches that were declared with |
|
Just adding this here because it helped me understand the changes. ❯ def foo [-a, --long, --both(-b), -c: bool, -d: bool = true, --eee(-e): bool = true] {
echo $"-a = ($a)"
echo $"--long = ($long)"
echo $"--both(-b) = ($both)"
echo $"-c = ($c)"
echo $"-d = ($d)"
echo $"--eee = ($eee)"
} This PR now requires that I think the reason they require a parameter on the flag now is because they have a predefined type. e.g. |
|
Doesn't it seem like having this I'm trying to figure out the rules. This is what I have so far.
Correct me if I'm wrong, maybe the reasoning that |
Yeah, you're right, so in this way, we have two type of flag, one is switch(which works the same), one is something like keyword argument(once it have explicit type like |
|
i think |
amtoine
left a comment
There was a problem hiding this comment.
@WindSoilder
i went and fixed the toolkit.nu because it was broken 👍
i was also able to fix all my scripts with this new PR and quite like the change 👌
i personally aprove this 👌
|
ooh i hit a wall try to fix another one of my scripts, what does that mean @WindSoilder? 😕 > def foo [-x: bool] { if not $x { print "ok" }}; foo
Error: nu::shell::type_mismatch
× Type mismatch.
╭─[entry #3:1:1]
1 │ def foo [-x: bool] { if not $x { print "ok" }}; foo
· ─┬
· ╰── bool
╰────EDIT: even adding > cargo run -- ~/documents/repos/github.com/goatfiles/scripts/nu_scripts/scripts/tmux-sessionizer.nu list-sessions
Error: nu::shell::type_mismatch
× Type mismatch.
╭─[/home/amtoine/documents/repos/github.com/goatfiles/scripts/nu_scripts/scripts/tmux-sessionizer.nu:211:1]
211 │
212 │ if not $more {
· ──┬──
· ╰── bool
213 │ return $sessions
╰──── |
|
@WindSoilder - I think for your example: If you call: Then |
|
@jntrnr > def foo [--bar: bool] { $bar | describe }; foo
nothing |
fdncred
left a comment
There was a problem hiding this comment.
+1 from me to land this PR. Thanks @WindSoilder!!!
|
@WindSoilder |
|
@amtoine I couldn't use ❯ def foo [-x: bool] { if ($x != true) { print "ok" }}You would think that since |
|
@amtoine It's because when you ran So we need to handle null value in |
|
ooh wow, appreciate you investigating the actual script @WindSoilder 🙏 this one is actually quite subtle 😮 let's go ahead and land this, i'll file an issue with the unhelpful error just after i upgrade 😉 |
|
because the changes can be a bit tricky when not used to them, i think we need to mention this in the release notes of 0.86.0 😌 |
related to - #10456 # Description this PR will fix the public API of the standard library by removing the type annotations from public boolean switches. 1. the signature before ```nushell clip [--silent: bool, --no-notify: bool, --no-strip: bool, --expand (-e): bool, --codepage (-c): int] ``` 2. the signature after ```nushell clip [--silent, --no-notify, --no-strip, --expand (-e), --codepage (-c): int] ``` # User-Facing Changes ### before ```nushell > "foo" | clip Error: nu::shell::cant_convert × Can't convert to bool. ╭─[NU_STDLIB_VIRTUAL_DIR/std/mod.nu:148:1] 148 │ $in 149 │ | if $expand { table --expand } else { table } · ───┬─── · ╰── can't convert nothing to bool 150 │ | into string ╰──── ``` ### after ```nushell > "foo" | clip foo saved to clipboard ``` # Tests + Formatting # After Submitting
related to - nushell/nushell#10456 - nushell/nushell.github.io#1071 ## description after the changes on boolean switches from nushell/nushell#10456, we need to not annotate then with `: bool` when part of a public API. this PR is required for nushell/nushell.github.io#1071 to move forward.
# Description Fixes: #11033 Sorry for the issue, it's a regression which introduce by this pr: #10456. And this pr is going to fix it. About the change: create a new field named `type_annotated` for `Arg::Flag` and `Arg::Signature` instead of `arg_explicit_type` variable. When we meet a type in `TypeMode`, we set `type_annotated` field of the argument to be true, then we know that if the arg have a annotated type easily
# Description Fixes: nushell#10450 This pr differentiating between `--x: bool` and `--x` Here are examples which demostrate difference between them: ```nushell def a [--x: bool] { $x }; a --x # not allowed, you need to parse a value to the flag. a # it's allowed, and the value of `$x` is false, which behaves the same to `def a [--x] { $x }; a` ``` For boolean flag with default value, it works a little bit different to nushell#10450 mentioned: ```nushell def foo [--option: bool = false] { $option } foo # output false foo --option # not allowed, you need to parse a value to the flag. foo --option true # output true ``` # User-Facing Changes After the pr, the following code is not allowed: ```nushell def a [--x: bool] { $x }; a --x ``` Instead, you have to pass a value to flag `--x` like `a --x false`. But bare flag works in the same way as before. ## Update: one more breaking change to help on nushell#7260 ``` def foo [--option: bool] { $option == null } foo ``` After the pr, if we don't use a boolean flag, the value will be `null` instead of `true`. Because here `--option: bool` is treated as a flag rather than a switch --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
related to - nushell#10456 # Description this PR will fix the public API of the standard library by removing the type annotations from public boolean switches. 1. the signature before ```nushell clip [--silent: bool, --no-notify: bool, --no-strip: bool, --expand (-e): bool, --codepage (-c): int] ``` 2. the signature after ```nushell clip [--silent, --no-notify, --no-strip, --expand (-e), --codepage (-c): int] ``` # User-Facing Changes ### before ```nushell > "foo" | clip Error: nu::shell::cant_convert × Can't convert to bool. ╭─[NU_STDLIB_VIRTUAL_DIR/std/mod.nu:148:1] 148 │ $in 149 │ | if $expand { table --expand } else { table } · ───┬─── · ╰── can't convert nothing to bool 150 │ | into string ╰──── ``` ### after ```nushell > "foo" | clip foo saved to clipboard ``` # Tests + Formatting # After Submitting
# Description Fixes: nushell#11033 Sorry for the issue, it's a regression which introduce by this pr: nushell#10456. And this pr is going to fix it. About the change: create a new field named `type_annotated` for `Arg::Flag` and `Arg::Signature` instead of `arg_explicit_type` variable. When we meet a type in `TypeMode`, we set `type_annotated` field of the argument to be true, then we know that if the arg have a annotated type easily
# Description Fixes: nushell#11033 Sorry for the issue, it's a regression which introduce by this pr: nushell#10456. And this pr is going to fix it. About the change: create a new field named `type_annotated` for `Arg::Flag` and `Arg::Signature` instead of `arg_explicit_type` variable. When we meet a type in `TypeMode`, we set `type_annotated` field of the argument to be true, then we know that if the arg have a annotated type easily
related to - nushell/nushell#10456 - nushell/nushell.github.io#1071 ## description after the changes on boolean switches from nushell/nushell#10456, we need to not annotate then with `: bool` when part of a public API. this PR is required for nushell/nushell.github.io#1071 to move forward.
related to - nushell/nushell#10456 - nushell/nushell.github.io#1071 ## description after the changes on boolean switches from nushell/nushell#10456, we need to not annotate then with `: bool` when part of a public API. this PR is required for nushell/nushell.github.io#1071 to move forward.
Description
Fixes: #10450
This pr differentiating between
--x: booland--xHere are examples which demostrate difference between them:
For boolean flag with default value, it works a little bit different to #10450 mentioned:
User-Facing Changes
After the pr, the following code is not allowed:
Instead, you have to pass a value to flag
--xlikea --x false. But bare flag works in the same way as before.Update: one more breaking change to help on #7260
After the pr, if we don't use a boolean flag, the value will be
nullinstead oftrue. Because here--option: boolis treated as a flag rather than a switch