Skip to content

small refactoring around units and add tests#15746

Merged
fdncred merged 16 commits intonushell:mainfrom
LoicRiegel:feat/into-int-with-units
May 16, 2025
Merged

small refactoring around units and add tests#15746
fdncred merged 16 commits intonushell:mainfrom
LoicRiegel:feat/into-int-with-units

Conversation

@LoicRiegel
Copy link
Copy Markdown
Contributor

@LoicRiegel LoicRiegel commented May 13, 2025

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

~> 1MB | format filesize sec
Error: nu::shell::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

@LoicRiegel LoicRiegel force-pushed the feat/into-int-with-units branch from 4d1fbb9 to 6693116 Compare May 14, 2025 14:42
@LoicRiegel LoicRiegel changed the title Feat: new --unit option for "into int" small refactoring around units and add tests May 14, 2025
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 16, 2025

Seems like a reasonable cleanup to me. Thanks @LoicRiegel

@fdncred fdncred merged commit 58a8f30 into nushell:main May 16, 2025
16 checks passed
@github-actions github-actions bot added this to the v0.105.0 milestone May 16, 2025
@LoicRiegel LoicRiegel deleted the feat/into-int-with-units branch May 17, 2025 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract more information from duration/date/filesize objects

2 participants