Repository navigation
feat!: Explicit cell-path case sensitivity syntax - #15692
Conversation
- Add `CellPath::String::insensitive: bool`, represented with an exclamation mark in `Display` - Update `into cell-path` and `split cell-path` to take case insensitivity into account while constructing and splitting cell-paths
- remove `insensitive` parameter, case sensitivity is determined by the cell-path itself - update call sites
can round trip `$. | to nuon | from nuon`
- remove `--sensitive(-s)` - add `--ignore-case(-I)`
…tivity Make case sensitivity explicit in various places.
|
I really like the current ... and it works on all platforms. I think this is good shell behavior. Let's not deprecate or change that behavior, please? The user can opt-in to case-sensitivity already using I've got to run for a bit, but I'm looking through the other commands trying to see - Are there others besides |
|
@NotTheDr01ds This PR makes all cell-path accesses case sensitive by default (with the exception of # this is special cased and will continue to work
$env.path
# unfortunately I couldn't special case this one as once `$env` is piped as a value,
# it is just another record
$env | get path
Yes, but there wasn't any way to specify case-sensitivity for other commands or direct cell-path accesses. The new behavior is consistent across board and allows both case-sensitivity and case-insensitivity in places they couldn't use before. |
I'm concerned, especially, about this statement, though:
I'm not sure I like removing cell-path and If we want to strive for consistency, I'd propose making all commands case-insensitive by default and opt-in to the strict behavior with a
Which ones were case-insensitive other than I'd probably be okay with cell-path and |
|
I'm not sure about making I see where @NotTheDr01ds is coming from with the case-insensitive cell path accesses being nice (I've written scripts which take advantage of this myself). Maybe we should flip it around, so that cell path accesses are case-insensitive by default, but adding the |
|
I consider it very similar to optional cell-path syntax. Trying to access a non existent field throws an error, if we want to relax it we just add a To me, it's very similar with case sensitivity. If I mistyped something the error suggests the correct column name and I can fix it or if I don't want to deal with case sensitivity I can just add We can very similarly suggest that "trying to access non existent fields or columns with holes should just return Currently some commands that only read data like
Adding flags to all relevant commands for turning sensitivity on/off is both a lot of clutter, and not granular enough. Whether the default is sensitive or not, there should be way to specify case sensitivity for each column. The result of the current approach of insensitive when reading (sometimes), and sensitive when writing is this: mut value = {}
$value.foo = "Hello"
$value
# => ╭─────┬───────╮
# => │ foo │ Hello │
# => ╰─────┴───────╯
$value.FOO += " World"
$value
# => ╭─────┬─────────────╮
# => │ foo │ Hello │
# => │ FOO │ Hello World │
# => ╰─────┴─────────────╯Making case (in)sensitivity a part of the cell-path itself rather than something the operations choose fixes a lot of inconsistencies at once. |
|
I like the idea of making all cell paths consistent and dropping most of the case sensitivity flags. I never used them myself, so I don't mind seeing them go. On the question of whether we want insensitivity or sensitivity by default, I'd go with sensitivity. Kinda like Not totally sure if |
|
We decided to proceed with this PR in last week's meeting after these changes had taken place |
This reverts commit 05ff3c8.
- examples updated
|
Could have added a deprecation warning whenever the old behavior was expected, would have given users some chance to make changes before submerged in errors. 👍 |
After nushell/nushell#15692, this integration breaks $PATH conversions again as cell-paths are now case-sensitive.
After nushell/nushell#15692, this integration breaks $PATH conversions again as cell-paths are now case-sensitive.
After nushell/nushell#15692, this integration breaks $PATH conversions again as cell-paths are now case-sensitive.
After nushell/nushell#15692, this integration breaks $PATH conversions again as cell-paths are now case-sensitive.
Related:
whereis case insensitive with no sensitive option #15683getbuilt-in is not case sensitive #11527Description
Currently various commands have differing behavior regarding cell-paths
{a: 1, A: 2} | get a A # => ╭───┬───╮ # => │ 0 │ 2 │ # => │ 1 │ 2 │ # => ╰───┴───╯ {a: 1, A: 2} | select a A # => ╭───┬───╮ # => │ a │ 1 │ # => │ A │ 2 │ # => ╰───┴───╯ {A: 1} | update a 2 # => Error: nu::shell::column_not_found # => # => × Cannot find column 'a' # => ╭─[entry #62:1:1] # => 1 │ {A: 1} | update a 2 # => · ───┬── ┬ # => · │ ╰── cannot find column 'a' # => · ╰── value originates here # => ╰────Proposal: making cell-path access case-sensitive by default and adding new syntax for case-insensitive parts, similar to optional (?) parts.
{FOO: BAR}.foo # => Error: nu::shell::name_not_found # => # => × Name not found # => ╭─[entry #60:1:21] # => 1 │ {FOO: BAR}.foo # => · ─┬─ # => · ╰── did you mean 'FOO'? # => ╰──── {FOO: BAR}.foo! # => BARThis would solve the problem of case sensitivity for all commands without causing an explosion of flags and make it more granular
Assigning to a field using a case-insensitive path is case-preserving.
For
update, case-insensitive is case-preserving.{FOO: 1} | update foo! { $in + 1 } # => ╭─────┬───╮ # => │ FOO │ 2 │ # => ╰─────┴───╯insertcan insert values into nested values so accessing into existing columns is case-insensitive, but creating new columns uses the cell-path as it is.So
insert foo! ...andinsert FOO! ...would work exactly as they do without!{FOO: {quox: 0}} # => ╭─────┬──────────────╮ # => │ │ ╭──────┬───╮ │ # => │ FOO │ │ quox │ 0 │ │ # => │ │ ╰──────┴───╯ │ # => ╰─────┴──────────────╯ {FOO: {quox: 0}} | insert foo.bar 1 # => ╭─────┬──────────────╮ # => │ │ ╭──────┬───╮ │ # => │ FOO │ │ quox │ 0 │ │ # => │ │ ╰──────┴───╯ │ # => │ │ ╭─────┬───╮ │ # => │ foo │ │ bar │ 1 │ │ # => │ │ ╰─────┴───╯ │ # => ╰─────┴──────────────╯ {FOO: {quox: 0}} | insert foo!.bar 1 # => ╭─────┬──────────────╮ # => │ │ ╭──────┬───╮ │ # => │ FOO │ │ quox │ 0 │ │ # => │ │ │ bar │ 1 │ │ # => │ │ ╰──────┴───╯ │ # => ╰─────┴──────────────╯upsertis tricky, depending on the input, the data might end up with different column names in rows. We can either forbid case-insensitive cell-paths forupsertor trust the user to keep their data in a sensible shape.This would be a breaking change as it would make existing cell-path accesses case-sensitive, however the case-sensitivity is already inconsistent and any attempt at making it consistent would be a breaking change.
$env's special case, making$envaccesses case-sensitive by default as well.In addition to
from_stringandto_stringadd an optional field to opt into case insensitive/preserving behavior.User-Facing Changes
get,whereand other previously case-insensitive commands are now case-sensitive by default.get's--sensitiveflag removed, similar to--ignore-errorsthere is now an--ignore-caseflag that treats all parts of the cell-path as case-insensitive.--sensitiveis now a no-op and gives a deprecation warning when used. A flag that that makesgettreat all members of the cell-path as case-insensitive will likely be added later.Tests + Formatting
Existing tests required minimal modification. However, new tests are not yet added.
After Submitting