nushell/crates/nu-protocol/src
Artemiy 1867bb1a88
Fix incorrect handling of boolean flags for builtin commands (#11492)
# 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](6f59abaf43/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.
2024-01-11 17:19:48 +02:00
..
ast Fix incorrect handling of boolean flags for builtin commands (#11492) 2024-01-11 17:19:48 +02:00
config Convert Shellerror::GenericError to named fields (#11230) 2023-12-07 00:40:03 +01:00
engine Simplify SIGQUIT handling (#11381) 2023-12-21 17:00:38 +01:00
value Lock out new direct construction of Record (#11414) 2023-12-24 13:12:16 +01:00
alias.rs Refactor scope commands (#10023) 2023-08-17 11:58:38 +03:00
cli_error.rs Refactor and fix Config<->Value mechanism (#10896) 2023-11-08 20:31:30 +01:00
did_you_mean.rs Improve case insensitivity consistency (#10884) 2023-11-08 23:58:54 +01:00
eval_base.rs Allow spreading arguments to commands (#11289) 2023-12-28 15:43:20 +08:00
eval_const.rs Allow spreading arguments to commands (#11289) 2023-12-28 15:43:20 +08:00
example.rs remove unused imports: Deserialize, Serialize compiler warning for nu-protocol/src/example.rs (#8514) 2023-03-18 11:45:12 -07:00
exportable.rs Module: support defining const and use const variables inside of function (#9773) 2023-08-01 07:09:52 +08:00
id.rs Add virtual path abstraction layer (#9245) 2023-05-23 23:48:50 +03:00
lev_distance.rs Suggest existing variables on not found (#8902) 2023-05-02 18:17:14 +03:00
lib.rs Deprecate --flag: bool in custom command (#11365) 2023-12-21 10:07:08 +01:00
module.rs Error on use path item1 item2, if item1 is not a module (#11183) 2023-12-05 11:38:45 +01:00
parse_error.rs Allow spreading arguments to commands (#11289) 2023-12-28 15:43:20 +08:00
parse_warning.rs Deprecate --flag: bool in custom command (#11365) 2023-12-21 10:07:08 +01:00
pipeline_data.rs Don't create a thread if stderr_stream is None (#11421) 2023-12-25 08:10:15 -06:00
plugin_signature.rs Rename main to script name when running scripts (#9948) 2023-08-12 05:58:49 +12:00
shell_error.rs Allow spreading arguments to commands (#11289) 2023-12-28 15:43:20 +08:00
signature.rs Move history into their own module (#11308) 2023-12-15 13:17:12 +01:00
span.rs Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00
syntax_shape.rs Remove Expr::MatchPattern (#11367) 2023-12-20 18:52:28 +01:00
ty.rs Remove Expr::MatchPattern (#11367) 2023-12-20 18:52:28 +01:00
util.rs Convert more ShellError variants to named fields (#11173) 2023-11-28 06:43:51 -06:00
variable.rs Fix broken constants in scopes (#9679) 2023-07-14 00:02:05 +03:00