Skip to content

Always populate config record during startup#14435

Merged
WindSoilder merged 3 commits intonushell:mainfrom
NotTheDr01ds:populate-config-record
Nov 27, 2024
Merged

Always populate config record during startup#14435
WindSoilder merged 3 commits intonushell:mainfrom
NotTheDr01ds:populate-config-record

Conversation

@NotTheDr01ds
Copy link
Copy Markdown
Contributor

@NotTheDr01ds NotTheDr01ds commented Nov 25, 2024

Description

As a bit of a follow-on to #13802 and #14249, this (pretty much a "one-line" change) really does always populate the $env.config record with the nu-protocol::config defaults during startup. This means that an $env.config record is value (with defaults) even during:

  • nu -n to suppress loading of config files
  • nu -c <commandstring>
  • nu <script>

User-Facing Changes

There should be no case in which there isn't a valid $env.config.

  • Before:

    nu -c "$env.config"
    # -> Error
  • After:

    nu -c "$env.config"
    # -> Default $env.config record

Startup time impact is negligible (17.072µs from perf! on my system) - Seems well worth it.

Tests + Formatting

Added tests for several -n -c cases.

  • 🟢 toolkit fmt
  • 🟢 toolkit clippy
  • 🟢 toolkit test
  • 🟢 toolkit test stdlib

After Submitting

Config chapter update still in progress.

@NotTheDr01ds NotTheDr01ds changed the title Populate config record Always populate config record during startup Nov 25, 2024
@NotTheDr01ds NotTheDr01ds marked this pull request as draft November 25, 2024 15:41
@NotTheDr01ds NotTheDr01ds marked this pull request as ready for review November 25, 2024 15:44
Copy link
Copy Markdown
Member

@IanManske IanManske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for all the tests as well.

@WindSoilder
Copy link
Copy Markdown
Contributor

WindSoilder commented Nov 27, 2024

Actually I'm a little confused.
When using nu -n, it starts with no config file and no env file, so what's the meaning of $env.config?

@NotTheDr01ds
Copy link
Copy Markdown
Contributor Author

NotTheDr01ds commented Nov 27, 2024

Actually I'm a little confused. When using nu -n, it starts with no config file and no env file, so what's the meaning of $env.config?

It represents all of the internal defaults from nu-protocol::config. So with this PR, a user can still introspect most of the currently "active" settings even when not using a config file (either default or user).

Copy link
Copy Markdown
Contributor

@WindSoilder WindSoilder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I get the idea behind it. LGTM

@WindSoilder WindSoilder merged commit 1c18e37 into nushell:main Nov 27, 2024
@github-actions github-actions bot added this to the v0.101.0 milestone Nov 27, 2024
@fdncred fdncred added the A:configuration Issue related to nu's configuration label Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:configuration Issue related to nu's configuration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants