nushell/crates/nu-command/src/formats/to
João Fidalgo 63335e99ae
Fix usage of --tabs flag while converting to json (#12115) (#12251)
closes #12115 

# Description
This fix addresses a bug where the --tabs flag couldn't be utilized due
to improper handling of the tab quantity provided by the user.
Previously, the code mistakenly attempted to convert the tab quantity to
a boolean value, leading to a conversion error. The resolution involves
adjusting the condition clauses to properly validate the presence of the
flag's value. Now, the code checks whether the get_flag() function
returns a value or None associated with the --tabs flag. This adjustment
enables the --tabs flag to function correctly, triggering the
appropriate condition and allowing the conversion to proceed as
expected. Similarly, the fix applies to the --indent flag. Additionally,
a default case was added, and the conversion now works properly without
flags. Two tests were added to validate the corrected behavior of these
flags.

# User-Facing Changes
Now the conversion should work properly instead of displaying an error.

# Tests + Formatting
-🟢 toolkit fmt
-🟢 toolkit clippy
-🟢 toolkit test
-🟢 toolkit test stdlib

To run added tests:
- cargo test --package nu-command --test main --
format_conversions::json::test_tabs_indent_flag
- cargo test --package nu-command --test main --
format_conversions::json::test_indent_flag
2024-03-20 11:55:51 -05:00
..
command.rs Move Value to helpers, separate span call (#10121) 2023-09-03 07:27:29 -07:00
csv.rs Fix incorrect handling of boolean flags for builtin commands (#11492) 2024-01-11 17:19:48 +02:00
delimited.rs Name the Value conversion functions more clearly (#11851) 2024-02-17 18:14:16 +00:00
json.rs Fix usage of --tabs flag while converting to json (#12115) (#12251) 2024-03-20 11:55:51 -05:00
md.rs fix: process empty headers in to md command (#12012) 2024-02-28 20:44:11 -06:00
mod.rs REFACTOR: move the 0% commands to nu-cmd-extra (#9404) 2023-07-06 08:31:31 -07:00
nuon.rs open, rm, umv, cp, rm and du: Don't globs if inputs are variables or string interpolation (#11886) 2024-02-23 09:17:09 +08:00
text.rs Make custom value type handling more consistent (#12230) 2024-03-19 11:09:59 +01:00
toml.rs open, rm, umv, cp, rm and du: Don't globs if inputs are variables or string interpolation (#11886) 2024-02-23 09:17:09 +08:00
tsv.rs Fix incorrect handling of boolean flags for builtin commands (#11492) 2024-01-11 17:19:48 +02:00
xml.rs Add self-closed tag support for to xml (#11577) 2024-01-19 05:35:29 -06:00
yaml.rs open, rm, umv, cp, rm and du: Don't globs if inputs are variables or string interpolation (#11886) 2024-02-23 09:17:09 +08:00