nushell/crates/nu-command/src
Douglas 029f3843d3
Add default --empty to handle empty values (#15223)
# Description

Adds a new `--empty/-e` flag to the `default` command.

# User-Facing Changes

Before:

```nushell
$env.FOO = ""
$env.FOO = $env.FOO? | default bar
$env.FOO
# => Empty string
```

After:

```nushell
$env.FOO = ""
$env.FOO = $env.FOO? | default -e bar
$env.FOO
# => bar
```

* Uses `val.is_empty`, which means that empty lists and records are also
replaced
* Empty values in tables (with a column specifier) are also replaced.

# Tests + Formatting

7 tests added and 1 updated + 1 new example

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

# After Submitting

N/A
2025-03-13 19:50:50 +01:00
..
bytes fix range bugs in str substring, str index-of, slice, bytes at (#14863) 2025-01-30 06:50:01 -06:00
charting Add Filesize type (#14369) 2024-11-29 21:24:17 +00:00
conversions Fix improper application of local timezone offset to Unix epochs (#15283) 2025-03-11 11:57:37 -04:00
database Refactor I/O Errors (#14927) 2025-01-28 16:03:31 -06:00
date Remove deprecated commands (#14726) 2025-01-07 07:37:51 +08:00
debug update sysinfo to 0.33.1 (#14982) 2025-02-03 06:33:23 -06:00
env Parse XML documents with DTDs by default, and add --disallow-dtd flag (#15272) 2025-03-12 08:09:55 -05:00
experimental add a helpful msg to indicate a job has been frozen (#15206) 2025-03-06 11:20:58 -05:00
filesystem check signals in nu-glob and ls (#15140) 2025-02-28 19:36:39 +01:00
filters Add default --empty to handle empty values (#15223) 2025-03-13 19:50:50 +01:00
formats Parse XML documents with DTDs by default, and add --disallow-dtd flag (#15272) 2025-03-12 08:09:55 -05:00
generators seq date: generalize to allow any duration for --increment argument (#14903) 2025-01-25 13:24:39 -06:00
hash add binary as input to hash commands (#13923) 2024-09-25 16:47:52 +08:00
help Rework operator type errors (#14429) 2025-02-12 20:03:40 -08:00
math bugfix: math commands now return error with infinite range [#15135] (#15236) 2025-03-11 14:40:26 +01:00
misc More precise ErrorKind::NotFound errors (#15149) 2025-02-22 11:42:44 -05:00
network Bump version to 0.102.0 (#14998) 2025-02-04 10:49:35 -05:00
path Refactor I/O Errors (#14927) 2025-01-28 16:03:31 -06:00
platform Add ansi codes to move cursor position (#15221) 2025-03-01 11:30:00 -06:00
random Respect system locale when formatting file sizes via config (#15271) 2025-03-09 15:43:02 -05:00
removed Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
shells Jobs (#14883) 2025-02-25 12:09:52 -05:00
stor Run-time pipeline input typechecking tweaks (#14922) 2025-02-02 15:51:47 -05:00
strings Respect system locale when formatting file sizes via config (#15271) 2025-03-09 15:43:02 -05:00
system add a helpful msg to indicate a job has been frozen (#15206) 2025-03-06 11:20:58 -05:00
viewers Refactor I/O Errors (#14927) 2025-01-28 16:03:31 -06:00
default_context.rs Remove range command after deprecation (#15038) 2025-03-12 21:42:49 +01:00
example_test.rs Implementing ByteStream interuption on infinite stream (#13552) 2025-01-11 13:28:08 -08:00
lib.rs Start to Add WASM Support Again (#14418) 2024-11-30 07:57:11 -06:00
progress_bar.rs Cut down unnecessary lint allows (#14335) 2024-11-15 19:24:39 +01:00
sort_utils.rs Remove deprecated commands (#14726) 2025-01-07 07:37:51 +08:00