nushell/crates
Christopher Durham b5e09b8a30
Improve registry value return types (#10806)
r? @fdncred
Last one, I hope. At least short of completely redesigning `registry
query`'s interface. (Which I wouldn't implement without asking around
first.)

# Description

User-Facing Changes has the general overview. Inline comments provide a
lot of justification on specific choices. Most of the type conversions
should be reasonably noncontroversial, but expanding `REG_EXPAND_SZ`
needs some justification. First, an example of the behavior there:

```shell
> # release nushell:
> version | select version commit_hash | to md --pretty
| version | commit_hash                              |
| ------- | ---------------------------------------- |
| 0.85.0  | a6f62e05ae |
> registry query --hkcu Environment TEMP | get value
%USERPROFILE%\AppData\Local\Temp

> # with this patch:
> version | select version commit_hash | to md --pretty
| version | commit_hash                              |
| ------- | ---------------------------------------- |
| 0.86.1  | 0c5a4c991f |
> registry query --hkcu Environment TEMP | get value
C:\Users\CAD\AppData\Local\Temp

> # Microsoft CLI tooling behavior:
> ^pwsh -c `(Get-ItemProperty HKCU:\Environment).TEMP`
C:\Users\CAD\AppData\Local\Temp
> ^reg query HKCU\Environment /v TEMP
HKEY_CURRENT_USER\Environment
    TEMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
```

As noted in the inline comments, I'm arguing that it makes more sense to
eagerly expand the %EnvironmentString% placeholders, as none of
Nushell's path functionality will interpret these placeholders. This
makes the behavior of `registry query` match the behavior of pwsh's
`Get-ItemProperty` registry access, and means that paths (the most
common use of `REG_EXPAND_SZ`) are actually usable.

This does *not* break nu_script's
[`update-path`](https://github.com/nushell/nu_scripts/blob/main/sourced/update-path.nu);
it will just be slightly inefficient as it will not find any
`%Placeholder%`s to manually expand anymore. But also, note that
`update-path` is currently *wrong*, as a path including
`%LocalAppData%Low` is perfectly valid and sometimes used (to go to
`Appdata\LocalLow`); expansion isn't done solely on a path segment
basis, as is implemented by `update-path`.

I believe that the type conversions implemented by this patch are
essentially always desired. But if we want to keep `registry query`
"pure", we could easily introduce a `registry get`[^get] which does the
more complete interpretation of registry types, and leave `registry
query` alone as doing the bare minimum. Or we could teach `path expand`
to do `ExpandEnvironmentStringsW`. But REG_EXPAND_SZ being the odd one
out of not getting its registry type semantics decoded by `registry
query` seems wrong.

[^get]: This is the potential redesign I alluded to at the top. One
potential change could be to make `registry get Environment` produce
`record<Path: string, TEMP: string, TMP: string>` instead of `registry
query`'s `table<name: string, value: string, type: string>`, the idea
being to make it feel as native as possible. We could even translate
between Nu's cell-path and registry paths -- cell paths with spaces do
actually work, if a bit awkwardly -- or even introduce lazy records so
the registry can be traversed with normal data manipulation ... but that
all seems a bit much.

# User-Facing Changes

- `registry query`'s produced `value` has changed. Specifically:
-  Rows `where type == REG_EXPAND_SZ` now expand `%EnvironmentVarable%`
placeholders for you. For example, `registry query --hkcu Environment
TEMP | get value` returns `C:\Users\CAD\AppData\Local\Temp` instead of
`%USERPROFILE%\AppData\Local\Temp`.
- You can restore the old behavior and preserve the placeholders by
passing a new `--no-expand` switch.
- Rows `where type == REG_MULTI_SZ` now provide a `list<string>` value.
They previously had that same list, but `| str join "\n"`.
- Rows `where type == REG_DWORD_BIG_ENDIAN` now provide the correct
numeric value instead of a byte-swapped value.
- Rows `where type == REG_QWORD` now provide the correct numeric
value[^sign] instead of the value modulo 2<sup>32</sup>.
- Rows `where type == REG_LINK` now provide a string value of the link
target registry path instead of an internal debug string representation.
(This should never be visible, as links should be transparently
followed.)
- Rows `where type =~ RESOURCE` now provide a binary value instead of an
internal debug string representation.

[^sign]: Nu's `int` is a signed 64-bit integer. As such, values >=
2<sup>63</sup> will be reported as their negative two's compliment
value. This might sometimes be the correct interpretation -- the
registry does not distinguish between signed and unsigned integer values
-- but regedit and pwsh display all values as unsigned.
2023-10-23 07:21:27 -05:00
..
nu_plugin_custom_values Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu_plugin_example Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu_plugin_formats Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu_plugin_gstat Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu_plugin_inc Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu_plugin_python remove vectorize_over_list from python plugin (#9905) 2023-08-03 16:46:48 +02:00
nu_plugin_query Add long options for misc and network (#10753) 2023-10-19 18:16:44 +02:00
nu-cli Bump uuid from 1.4.1 to 1.5.0 (#10810) 2023-10-23 14:14:08 +08:00
nu-cmd-base Allow filesystem commands to access files with glob metachars in name (#10694) 2023-10-18 13:31:15 -05:00
nu-cmd-dataframe Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu-cmd-extra Finish removing profile command and related data (#10807) 2023-10-22 14:06:53 +03:00
nu-cmd-lang deprecate def-env and export def-env (#10715) 2023-10-19 13:50:16 +08:00
nu-color-config Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu-command Improve registry value return types (#10806) 2023-10-23 07:21:27 -05:00
nu-engine remove the $nothing variable (#10567) 2023-10-19 18:41:38 +02:00
nu-explore Finish removing profile command and related data (#10807) 2023-10-22 14:06:53 +03:00
nu-glob Allow filesystem commands to access files with glob metachars in name (#10694) 2023-10-18 13:31:15 -05:00
nu-json Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu-parser remove the $nothing variable (#10567) 2023-10-19 18:41:38 +02:00
nu-path Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu-plugin Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu-pretty-hex Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu-protocol Finish removing profile command and related data (#10807) 2023-10-22 14:06:53 +03:00
nu-std Use long options for string (#10777) 2023-10-19 22:08:09 +02:00
nu-system Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu-table Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu-term-grid Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu-test-support Bump version to 0.86.1 (#10755) 2023-10-18 13:00:51 -05:00
nu-utils Do not use white text in the default light theme (#10796) 2023-10-21 16:31:46 -05:00
README.md Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00

Nushell core libraries and plugins

These sub-crates form both the foundation for Nu and a set of plugins which extend Nu with additional functionality.

Foundational libraries are split into two kinds of crates:

  • Core crates - those crates that work together to build the Nushell language engine
  • Support crates - a set of crates that support the engine with additional features like JSON support, ANSI support, and more.

Plugins are likewise also split into two types:

  • Core plugins - plugins that provide part of the default experience of Nu, including access to the system properties, processes, and web-connectivity features.
  • Extra plugins - these plugins run a wide range of different capabilities like working with different file types, charting, viewing binary data, and more.