New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix incorrect handling of boolean flags for builtin commands #11492
Conversation
2de5a91
to
496c941
Compare
The fix seems good. Two points:
|
Also, since you essentially renamed the old |
Add test for ls command testing various boolean flags with explicit false values
|
Test sandbox does not have a OS-agnostic way of creating hidden files which breaks `ls --all` test on windows
OK, the test looks good enough. One thing that I also noticed is that the parser shouldn't depend on the engine. If you check, |
That's fair. I think |
(retroactively added the label to merge after the dust settles around the new release) OK, could you then make a new PR moving the |
Done. Moved all |
OK, thanks, let's try it out! |
# Description #11492 fixed flags for builtin commands but I missed that plugins don't use the same `has_flag` that builtins do. This PR addresses this. Unfortunately this means that return value of `has_flag` needs to change from `bool` to `Result<bool, ShellError>` to produce an error when explicit value is not a boolean (just like in case of `has_flag` for builtin commands. It is not possible to check this in `EvaluatedCall::try_from_call` because # User-Facing Changes Passing explicit values to flags of plugin commands (like `--flag=true` `--flag=false`) should work now. BREAKING: changed return value of `EvaluatedCall::has_flag` method from `bool` to `Result<bool, ShellError>` # Tests + Formatting Added tests and updated documentation and examples
Hi, @NotLebedev, it seems that b90fe82 introduced a regression. When I build the latest Error: nu::shell::cant_convert
× Can't convert to bool.
╭─[entry #3:1:1]
1 │ touch -r deps build
· ──┬─
· ╰── can't convert string to bool
╰──── On commits prior to that there's no issues. Could you check what went wrong? |
…#11492) # Description Possible fix of nushell#11456 This PR fixes a bug where builtin commands did not respect the logic of dynamically passed boolean flags. The reason is [has_flag](https://github.com/nushell/nushell/blob/6f59abaf4310487f7a6319437be6ec61abcbc3b9/crates/nu-protocol/src/ast/call.rs#L204C5-L212C6) method did not evaluate and take into consideration expression used with flag. To address this issue a solution is proposed: 1. `has_flag` method is moved to `CallExt` and new logic to evaluate expression and check if it is a boolean value is added 2. `has_flag_const` method is added to `CallExt` which is a constant version of `has_flag` 3. `has_named` method is added to `Call` which is basically the old logic of `has_flag` 4. All usages of `has_flag` in code are updated, mostly to pass `engine_state` and `stack` to new `has_flag`. In `run_const` commands it is replaced with `has_flag_const`. And in a few select places: parser, `to nuon` and `into string` old logic via `has_named` is used. # User-Facing Changes Explicit values of boolean flags are now respected in builtin commands. Before: ![image](https://github.com/nushell/nushell/assets/17511668/f9fbabb2-3cfd-43f9-ba9e-ece76d80043c) After: ![image](https://github.com/nushell/nushell/assets/17511668/21867596-2075-437f-9c85-45563ac70083) Another example: Before: ![image](https://github.com/nushell/nushell/assets/17511668/efdbc5ca-5227-45a4-ac5b-532cdc2bbf5f) After: ![image](https://github.com/nushell/nushell/assets/17511668/2907d5c5-aa93-404d-af1c-21cdc3d44646) # Tests + Formatting Added test reproducing some variants of original issue.
# Description nushell#11492 fixed flags for builtin commands but I missed that plugins don't use the same `has_flag` that builtins do. This PR addresses this. Unfortunately this means that return value of `has_flag` needs to change from `bool` to `Result<bool, ShellError>` to produce an error when explicit value is not a boolean (just like in case of `has_flag` for builtin commands. It is not possible to check this in `EvaluatedCall::try_from_call` because # User-Facing Changes Passing explicit values to flags of plugin commands (like `--flag=true` `--flag=false`) should work now. BREAKING: changed return value of `EvaluatedCall::has_flag` method from `bool` to `Result<bool, ShellError>` # Tests + Formatting Added tests and updated documentation and examples
Description
Possible fix of #11456
This PR fixes a bug where builtin commands did not respect the logic of dynamically passed boolean flags. The reason is has_flag method did not evaluate and take into consideration expression used with flag.
To address this issue a solution is proposed:
has_flag
method is moved toCallExt
and new logic to evaluate expression and check if it is a boolean value is addedhas_flag_const
method is added toCallExt
which is a constant version ofhas_flag
has_named
method is added toCall
which is basically the old logic ofhas_flag
has_flag
in code are updated, mostly to passengine_state
andstack
to newhas_flag
. Inrun_const
commands it is replaced withhas_flag_const
. And in a few select places: parser,to nuon
andinto string
old logic viahas_named
is used.User-Facing Changes
Explicit values of boolean flags are now respected in builtin commands.
Before:
After:
Another example:
Before:
After:
Tests + Formatting
Added test reproducing some variants of original issue.