Skip to content

allow into filesize to take tables as input / output - #9706

Merged
fdncred merged 7 commits into
nushell:mainfrom
amtoine:fix-into-filesize-table-input-output
Jul 16, 2023
Merged

fdncred merged 7 commits into
nushell:mainfrom
amtoine:fix-into-filesize-table-input-output

Conversation

@amtoine

@amtoine amtoine commented Jul 16, 2023 •

Copy link
Copy Markdown
Member

Description

i have the following command that should give a table of all the mounted devices with information about their sizes, etc, etc... a glorified output for the df -h command:

def disk [] {
    df -h
      | str replace "Mounted on" "Mountpoint"
      | detect columns
      | rename filesystem size used avail used% mountpoint
      | into filesize size used avail
      | upsert used% {|it| 100 * (1 - $it.avail / $it.size)}
}

this should work given the first example of into filesize

  Convert string to filesize in table
  > [[bytes]; ['5'] [3.2] [4] [2kb]] | into filesize bytes

before this PR

it does not even parse

Error: nu::parser::input_type_mismatch

  × Command does not support table input.
   ╭─[entry #1:5:1]
 5 │       | rename filesystem size used avail used% mountpoint
 6 │       | into filesize size used avail
   ·         ──────┬──────
   ·               ╰── command doesn't support table input
 7 │       | upsert used% {|it| 100 * (1 - $it.avail / $it.size)}
   ╰────

Note
this was working before the recent input / output type changes

with this PR

it parses again and gives

> disk | where mountpoint == "/" | into record
╭────────────┬───────────────────╮
│ filesystem │ /dev/sda2         │
│ size       │ 217.9 GiB         │
│ used       │ 158.3 GiB         │
│ avail      │ 48.4 GiB          │
│ used%      │ 77.77777777777779 │
│ mountpoint │ /                 │
╰────────────┴───────────────────╯

Note
the two following commands also work now and did not before the PR

ls | insert name_size {|it| $it.name | str length} | into filesize name_size
[[device size]; ["/dev/sda1" 200] ["/dev/loop0" 50]] | into filesize size

User-Facing Changes

into filesize works back with tables and this effectively fixes the doc.

Tests + Formatting

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

this PR gives a result back to the first table example to make sure it works fine.

After Submitting

@amtoine

amtoine commented Jul 16, 2023

Copy link
Copy Markdown
Member Author

thanks @fdncred for pointing out the error in the example test 😌
it's better with the correct expected data 👀

@fdncred
fdncred merged commit 79d9a05 into nushell:main Jul 16, 2023
@fdncred

fdncred commented Jul 16, 2023

Copy link
Copy Markdown
Contributor

thanks. i bet we keep finding these for a while.

@amtoine
amtoine deleted the fix-into-filesize-table-input-output branch July 16, 2023 17:00
@amtoine

amtoine commented Jul 16, 2023

Copy link
Copy Markdown
Member Author

thanks. i bet we keep finding these for a while.

oooh yeah definitely 👍

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.

2 participants