mirror of
https://github.com/nushell/nushell.git
synced 2025-03-14 15:38:29 +01:00
# Description This PR fixes #15131 by allowing the `insert` and `upsert` commands to create lists where they may be expected based on the cell path provided. For example, the below would have previously thrown an error, but now creates lists and list elements where necessary <img width="173" alt="Screenshot 2025-02-17 at 2 46 12 AM" src="https://github.com/user-attachments/assets/6d680e7e-6268-42ed-a037-a0795014a7e0" /> <img width="200" alt="Screenshot 2025-02-17 at 2 46 16 AM" src="https://github.com/user-attachments/assets/50d0e8eb-aabb-49fe-b961-5f7489fdc993" /> <img width="284" alt="Screenshot 2025-02-17 at 2 45 43 AM" src="https://github.com/user-attachments/assets/242a2ec6-7e8f-4a51-92ce-9d5ec10f867f" /> # User-Facing Changes This change removes errors that were previously raised by `insert_data_at_cell_path` and `upsert_data_at_cell_path`. If one of these commands encountered an unknown cell path in cases such as these, it would either raise a "Not a list value" as the list index is used on a record: <img width="326" alt="Screenshot 2025-02-17 at 2 46 43 AM" src="https://github.com/user-attachments/assets/39b9b006-388b-49b3-82a0-8cc9b739feaa" /> Or a "Row number too large" when required to create a new list element along the way: <img width="475" alt="Screenshot 2025-02-17 at 2 46 51 AM" src="https://github.com/user-attachments/assets/007d1268-7d26-42aa-9bf5-d54c0abf4058" /> But both now succeed, which seems to be the intention as it is in parity with record behavior. Any consumers depending on this specific behavior will see these errors subside. This change also includes the static method `Value::with_data_at_cell_path` that creates a value with a given nested value at a given cell path, creating records or lists based on the path member type. # Tests + Formatting In addition to unit tests for the altered behavior, both affected user-facing commands (`insert` and `upsert`) gained a new command example to both explain and test this change at the user level. <img width="382" alt="Screenshot 2025-02-17 at 2 29 26 AM" src="https://github.com/user-attachments/assets/e6973640-3ce6-4ea7-9ba5-d256fe5cb38b" /> Note: A single test did fail locally, due to my config directory differing from expected, but works where this variable is unset (`with-env { XDG_CONFIG_HOME: null } {cargo test}`): ``` ---- repl::test_config_path::test_default_config_path stdout ---- thread 'repl::test_config_path::test_default_config_path' panicked at tests/repl/test_config_path.rs:101:5: assertion failed: `(left == right)` Diff < left / right > : <[home_dir]/Library/Application Support/nushell >[home_dir]/.config/nushell ``` |
||
---|---|---|
.. | ||
src | ||
tests | ||
Cargo.toml | ||
LICENSE | ||
README.md |
nu-protocol
The nu-protocol crate holds the definitions of structs/traits that are used throughout Nushell. This gives us one way to expose them to many other crates, as well as make these definitions available to each other, without causing mutually recursive dependencies.