Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for ints, provide an option to convert all of them to filesizes with the into value command #11797

Merged
merged 1 commit into from Feb 7, 2024

Conversation

fdncred
Copy link
Collaborator

@fdncred fdncred commented Feb 7, 2024

Description

This PR allows into value to recognize ints and change them into file sizes if you prefer.

Before

 free | ^column -t | lines | update 0 {$"type  ($in)"} | to text | ^column -t | detect columns | into value 
╭─#─┬─type──┬──total───┬──used───┬───free───┬shared┬buff/cache┬available─╮
 0  Mem:   24614036  3367680  16196240  3688   5449736  21246356 
 1  Swap:   6291456        0   6291456                           
╰───┴───────┴──────────┴─────────┴──────────┴──────┴──────────┴──────────╯

After

 free | ^column -t | lines | update 0 {$"type  ($in)"} | to text | ^column -t | detect columns | into value --prefer-filesizes
╭─#─┬─type──┬──total──┬──used──┬──free───┬─shared─┬buff/cache┬available╮
 0  Mem:   24.6 MB  3.4 MB  16.2 MB  3.7 KB    5.4 MB  21.2 MB 
 1  Swap:   6.3 MB     0 B   6.3 MB                            
╰───┴───────┴─────────┴────────┴─────────┴────────┴──────────┴─────────╯

User-Facing Changes

Tests + Formatting

After Submitting

@fdncred fdncred changed the title for ints, provide an option to convert all of them to filesizes for ints, provide an option to convert all of them to filesizes with the into value command Feb 7, 2024
@fdncred fdncred merged commit c79432f into nushell:main Feb 7, 2024
19 checks passed
@fdncred fdncred deleted the into_value_prefer_filesize branch February 7, 2024 22:28
@fdncred fdncred added the pr:commands This PR changes our commands in some way label Feb 7, 2024
@fdncred fdncred added this to the v0.91.0 milestone Feb 7, 2024
@sholderbach
Copy link
Member

Looking at how complicated the pipeline necessary to prepare the input I am not quite sure if having this convenience for just one of thousand possibilities how an int should be reinterpreted is really the best way forward. (e.g. what if it is kb instead of bytes, unix times...)

Maybe we can provide better facilities that let you select fields by existing type (and any existing other predicates) to then apply a coercion.

@fdncred
Copy link
Collaborator Author

fdncred commented Feb 14, 2024

The point of into value is to automatically touch every cell and guess at the value. Since these are numbers, it guesses int. So, I wanted an easier way than the below example to guess filesize. If I have to use a separate command and type out every column, it kind of defeats the purpose.

 free | ^column -t | lines | update 0 {$"type  ($in)"} | to text | ^column -t | detect columns | into value | into filesize total used free shared buff/cache availablePM
╭─#─┬─type──┬──total──┬───used───┬──free───┬─shared─┬buff/cache┬available╮
 0  Mem:   24.6 MB  811.2 KB  23.4 MB  3.7 KB  747.9 KB  23.8 MB 
 1  Swap:   6.3 MB       0 B   6.3 MB     0 B       0 B      0 B 
╰───┴───────┴─────────┴──────────┴─────────┴────────┴──────────┴─────────╯

However, if into filesize worked like into value and touched every cell, then that would be easier. I'm just not sure we'd want to make that type of change for every into command.

This also started with, "Wow, update cells is a pain to use.".

I'm open to other ideas.

dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
…ith the `into value` command (nushell#11797)

# Description

This PR allows `into value` to recognize ints and change them into file
sizes if you prefer.
### Before
```nushell
❯ free | ^column -t | lines | update 0 {$"type  ($in)"} | to text | ^column -t | detect columns | into value 
╭─#─┬─type──┬──total───┬──used───┬───free───┬shared┬buff/cache┬available─╮
│ 0 │ Mem:  │ 24614036 │ 3367680 │ 16196240 │ 3688 │  5449736 │ 21246356 │
│ 1 │ Swap: │  6291456 │       0 │  6291456 │      │          │          │
╰───┴───────┴──────────┴─────────┴──────────┴──────┴──────────┴──────────╯
```
### After
```nushell
❯ free | ^column -t | lines | update 0 {$"type  ($in)"} | to text | ^column -t | detect columns | into value --prefer-filesizes
╭─#─┬─type──┬──total──┬──used──┬──free───┬─shared─┬buff/cache┬available╮
│ 0 │ Mem:  │ 24.6 MB │ 3.4 MB │ 16.2 MB │ 3.7 KB │   5.4 MB │ 21.2 MB │
│ 1 │ Swap: │  6.3 MB │    0 B │  6.3 MB │        │          │         │
╰───┴───────┴─────────┴────────┴─────────┴────────┴──────────┴─────────╯
```
# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:commands This PR changes our commands in some way
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants