nushell/crates/nu-command/src
Loïc Riegel 58a8f30a25
small refactoring around units and add tests (#15746)
Closes #14469

# Description
- ~~Implement the ``--unit`` conversion in "into int" command~~
- New ``ShellError::InvalidUnit`` unit if users enter wrong units
- Made ``ShellError::CantConvertToDuration`` more generic: became
``CantConvertToUnit``
- Tried to improve the way we parse units and get the supported units.
It's not complete, though, I will continue this refactoring in another
PR. But I already did some small refactorings in the "format duration"
and "format filesize" commands
- Add tests for "format filesize" and "format duration"

# User-Facing Changes

```nu
~> 1MB | format filesize sec
Error: nu:🐚:invalid_unit

  × Invalid unit
   ╭─[entry #7:1:23]
 1 │ 1MB | format filesize sec
   ·                       ─┬─
   ·                        ╰── encountered here
   ╰────
  help: Supported units are: B, kB, MB, GB, TB, PB, EB, KiB, MiB, GiB, TiB, PiB, EiB

```
2025-05-16 17:41:26 -05:00
..
bytes Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
charting Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
conversions small refactoring around units and add tests (#15746) 2025-05-16 17:41:26 -05:00
database Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
date Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
debug Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
env Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
experimental Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
filesystem Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
filters Add lazy closure evaluation to default (#14160) (#15654) 2025-05-15 10:10:56 -04:00
formats Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
generators Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
hash Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
help Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
math Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
misc Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
network Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
path Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
platform fix duplicate short_name in ansi command (#15767) 2025-05-16 13:56:15 -05:00
random Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
removed refactor: rename subcommand structs (#15309) 2025-03-14 02:00:35 +01:00
shells Jobs (#14883) 2025-02-25 12:09:52 -05:00
stor Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
strings small refactoring around units and add tests (#15746) 2025-05-16 17:41:26 -05:00
system allow powershell scripts in the path to be executed (#15760) 2025-05-14 13:21:02 -05:00
viewers fix: empty tables now respect $env.config.use_ansi_coloring (closes #14896) (#15751) 2025-05-14 06:40:15 -05:00
default_context.rs Inter-Job direct messaging (#15253) 2025-04-26 23:24:35 +08:00
example_test.rs Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
lib.rs Start to Add WASM Support Again (#14418) 2024-11-30 07:57:11 -06:00
progress_bar.rs Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
sort_utils.rs Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00