nushell/crates/nu-std/std/mod.nu
Douglas 4c8b09eb97
Load env when importing with use std * (#14012)
# Description

After a `use std *`, the environment variables exported from the
submodules' `export-env` blocks are not available because of #13403.
This causes failures in `log` (currently) and will cause issues in
`dirs` once we stop autoloading it separately.

When the submodules are loaded separately (e.g., `use std/log`),
everything already worked correctly. While this is the preferred way of
doing it, we also want `use std *` to work properly.

This is a workaround for the standard library submodules. It is
definitely not ideal, but it can be removed when and if #13403 is fixed.

For now, we need to duplicate any environment settings in both the
submodules (when loaded with `use std/log`) and in the standard library
itself (when loaded with `use std *`). Again, this should not be
necessary, but currently is because of #13403.

# User-Facing Changes

Bug fix

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2024-10-07 09:34:47 +03:00

39 lines
908 B
Text

# std.nu, `used` to load all standard library components
# Top-level commands: ellie, repeat, null-device, and "path add"
export use lib *
# std submodules
export module ./assert
export module ./bench
export module ./dt
export module ./formats
export module ./help
export module ./input
export module ./iter
export module ./log
export module ./math
export module ./xml
# Load main dirs command and all subcommands
export use ./dirs main
export module ./dirs {
export use ./dirs [
add
drop
next
prev
goto
]
}
# Workaround for #13403 to load export-env blocks from submodules
export-env {
# log
$env.NU_LOG_FORMAT = $env.NU_LOG_FORMAT? | default "%ANSI_START%%DATE%|%LEVEL%|%MSG%%ANSI_STOP%"
$env.NU_LOG_DATE_FORMAT = $env.NU_LOG_DATE_FORMAT? | default "%Y-%m-%dT%H:%M:%S%.3f"
# dirs
$env.DIRS_POSITION = 0
$env.DIRS_LIST = [($env.PWD | path expand)]
}