nushell/crates
Darren Schroeder 761946c522
add the ability to combine columns with detect columns (#9511)
# Description

This PR adds the ability to manually combine columns in the `detect
columns` command. This is useful when items are close together but want
them to be in one column.

For example, if you want to parse the output of bash's `ls` command, the
output passed into `detect columns` would look similar to this.
```
❯ ^ls -lh
total 242K
-rw-r--r-- 1 dschroeder 197121 3.5K Mar 30 10:10 CODE_OF_CONDUCT.md
-rw-r--r-- 1 dschroeder 197121  11K Jun 21 14:16 CONTRIBUTING.md
-rw-r--r-- 1 dschroeder 197121 153K Jun 21 14:16 Cargo.lock
-rw-r--r-- 1 dschroeder 197121 5.7K Jun 21 08:47 Cargo.toml
-rw-r--r-- 1 dschroeder 197121  371 Mar 30 10:10 Cross.toml
-rw-r--r-- 1 dschroeder 197121 1.1K Apr  3 08:37 LICENSE
-rw-r--r-- 1 dschroeder 197121  13K Jun 21 14:16 README.md
drwxr-xr-x 1 dschroeder 197121    0 May 24 08:06 assets
drwxr-xr-x 1 dschroeder 197121    0 Jun 21 14:16 benches
-rw-r--r-- 1 dschroeder 197121  310 Mar 30 10:10 codecov.yml
drwxr-xr-x 1 dschroeder 197121    0 Jun  1 15:30 crates
drwxr-xr-x 1 dschroeder 197121    0 May  4 07:55 dict
drwxr-xr-x 1 dschroeder 197121    0 Mar 30 10:10 docker
-rw-r--r-- 1 dschroeder 197121 1.1K Jun 12 07:03 rust-toolchain.toml
drwxr-xr-x 1 dschroeder 197121    0 May 26 07:11 scripts
drwxr-xr-x 1 dschroeder 197121    0 Jun 15 07:14 src
drwxr-xr-x 1 dschroeder 197121    0 Jun 21 09:48 target
drwxr-xr-x 1 dschroeder 197121    0 Jun 21 12:30 tests
-rw-r--r-- 1 dschroeder 197121  16K Jun 21 14:16 toolkit.nu
drwxr-xr-x 1 dschroeder 197121    0 Jun  1 15:30 wix
```
Running it through `detect columns` is helpful but notice how the Month,
Day, and Time are in their own columns.
```
❯ ^ls -lh | detect columns --no-headers --skip 1
╭────┬────────────┬─────────┬────────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────────────────╮
│  # │  column0   │ column1 │  column2   │ column3 │ column4 │ column5 │ column6 │ column7 │       column8       │
├────┼────────────┼─────────┼────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────────────────┤
│  0 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 3.5K    │ Mar     │ 30      │ 10:10   │ CODE_OF_CONDUCT.md  │
│  1 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 11K     │ Jun     │ 21      │ 14:16   │ CONTRIBUTING.md     │
│  2 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 153K    │ Jun     │ 21      │ 14:16   │ Cargo.lock          │
│  3 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 5.7K    │ Jun     │ 21      │ 08:47   │ Cargo.toml          │
│  4 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 371     │ Mar     │ 30      │ 10:10   │ Cross.toml          │
│  5 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 1.1K    │ Apr     │ 3       │ 08:37   │ LICENSE             │
│  6 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 13K     │ Jun     │ 21      │ 14:16   │ README.md           │
│  7 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May     │ 24      │ 08:06   │ assets              │
│  8 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 21      │ 14:16   │ benches             │
│  9 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 310     │ Mar     │ 30      │ 10:10   │ codecov.yml         │
│ 10 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 1       │ 15:30   │ crates              │
│ 11 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May     │ 4       │ 07:55   │ dict                │
│ 12 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Mar     │ 30      │ 10:10   │ docker              │
│ 13 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 1.1K    │ Jun     │ 12      │ 07:03   │ rust-toolchain.toml │
│ 14 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May     │ 26      │ 07:11   │ scripts             │
│ 15 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 15      │ 07:14   │ src                 │
│ 16 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 21      │ 09:48   │ target              │
│ 17 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 21      │ 12:30   │ tests               │
│ 18 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 16K     │ Jun     │ 21      │ 14:16   │ toolkit.nu          │
│ 19 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 1       │ 15:30   │ wix                 │
├────┼────────────┼─────────┼────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────────────────┤
│  # │  column0   │ column1 │  column2   │ column3 │ column4 │ column5 │ column6 │ column7 │       column8       │
╰────┴────────────┴─────────┴────────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────────────────╯
```
Now you can add `--combine-columns <range>` and get something like this.
```
❯ ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7
╭────┬────────────┬─────────┬────────────┬─────────┬─────────┬──────────────┬─────────────────────╮
│  # │  column0   │ column1 │  column2   │ column3 │ column4 │   column5    │       column6       │
├────┼────────────┼─────────┼────────────┼─────────┼─────────┼──────────────┼─────────────────────┤
│  0 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 3.5K    │ Mar 30 10:10 │ CODE_OF_CONDUCT.md  │
│  1 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 11K     │ Jun 21 14:16 │ CONTRIBUTING.md     │
│  2 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 153K    │ Jun 21 14:16 │ Cargo.lock          │
│  3 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 5.7K    │ Jun 21 08:47 │ Cargo.toml          │
│  4 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 371     │ Mar 30 10:10 │ Cross.toml          │
│  5 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 1.1K    │ Apr 3 08:37  │ LICENSE             │
│  6 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 13K     │ Jun 21 14:16 │ README.md           │
│  7 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May 24 08:06 │ assets              │
│  8 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 21 14:16 │ benches             │
│  9 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 310     │ Mar 30 10:10 │ codecov.yml         │
│ 10 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 1 15:30  │ crates              │
│ 11 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May 4 07:55  │ dict                │
│ 12 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Mar 30 10:10 │ docker              │
│ 13 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 1.1K    │ Jun 12 07:03 │ rust-toolchain.toml │
│ 14 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May 26 07:11 │ scripts             │
│ 15 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 15 07:14 │ src                 │
│ 16 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 21 09:48 │ target              │
│ 17 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 21 12:30 │ tests               │
│ 18 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 16K     │ Jun 21 14:16 │ toolkit.nu          │
│ 19 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 1 15:30  │ wix                 │
├────┼────────────┼─────────┼────────────┼─────────┼─────────┼──────────────┼─────────────────────┤
│  # │  column0   │ column1 │  column2   │ column3 │ column4 │   column5    │       column6       │
╰────┴────────────┴─────────┴────────────┴─────────┴─────────┴──────────────┴─────────────────────╯
```
Then you can fancy-it-up by tweaking the other columns and renaming
columns.
```
❯ ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7 | update column5 {|r| $r.column5 | into datetime} | into int column1 column3 | into filesize column4 | rename perms links user inode filesize datetime name
╭────┬────────────┬───────┬────────────┬────────┬──────────┬──────────────┬─────────────────────╮
│  # │   perms    │ links │    user    │ inode  │ filesize │   datetime   │        name         │
├────┼────────────┼───────┼────────────┼────────┼──────────┼──────────────┼─────────────────────┤
│  0 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │   3.5 KB │ 2 months ago │ CODE_OF_CONDUCT.md  │
│  1 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │  11.0 KB │ 2 days ago   │ CONTRIBUTING.md     │
│  2 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │ 153.0 KB │ 2 days ago   │ Cargo.lock          │
│  3 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │   5.7 KB │ 2 days ago   │ Cargo.toml          │
│  4 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │    371 B │ 2 months ago │ Cross.toml          │
│  5 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │   1.1 KB │ 2 months ago │ LICENSE             │
│  6 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │  13.0 KB │ 2 days ago   │ README.md           │
│  7 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ a month ago  │ assets              │
│  8 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 days ago   │ benches             │
│  9 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │    310 B │ 2 months ago │ codecov.yml         │
│ 10 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 3 weeks ago  │ crates              │
│ 11 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 months ago │ dict                │
│ 12 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 months ago │ docker              │
│ 13 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │   1.1 KB │ 2 weeks ago  │ rust-toolchain.toml │
│ 14 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 4 weeks ago  │ scripts             │
│ 15 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ a week ago   │ src                 │
│ 16 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 days ago   │ target              │
│ 17 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 days ago   │ tests               │
│ 18 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │  16.0 KB │ 2 days ago   │ toolkit.nu          │
│ 19 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 3 weeks ago  │ wix                 │
├────┼────────────┼───────┼────────────┼────────┼──────────┼──────────────┼─────────────────────┤
│  # │   perms    │ links │    user    │ inode  │ filesize │   datetime   │        name         │
╰────┴────────────┴───────┴────────────┴────────┴──────────┴──────────────┴─────────────────────╯
```
# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-23 16:19:08 -05:00
..
nu_plugin_custom_values Bump to 0.81.1 as development version (#9379) 2023-06-07 15:06:42 +02:00
nu_plugin_example Bump to 0.81.1 as development version (#9379) 2023-06-07 15:06:42 +02:00
nu_plugin_formats update ini dependency (#9426) 2023-06-13 13:33:00 -05:00
nu_plugin_gstat Bump to 0.81.1 as development version (#9379) 2023-06-07 15:06:42 +02:00
nu_plugin_inc Bump to 0.81.1 as development version (#9379) 2023-06-07 15:06:42 +02:00
nu_plugin_python update nu_plugin_python due to signature changes (#8107) 2023-02-18 13:27:24 +00:00
nu_plugin_query revert: move to ahash (#9464) 2023-06-18 15:27:57 +12:00
nu-cli cratification: move the bytes command to nu-cmd-extra (#9509) 2023-06-23 12:23:08 -07:00
nu-cmd-base cratification: move the bytes command to nu-cmd-extra (#9509) 2023-06-23 12:23:08 -07:00
nu-cmd-dataframe revert: move to ahash (#9464) 2023-06-18 15:27:57 +12:00
nu-cmd-extra cratification: move the bytes command to nu-cmd-extra (#9509) 2023-06-23 12:23:08 -07:00
nu-cmd-lang split $nu variable into scope commands and simpler $nu (#9487) 2023-06-21 09:33:01 +12:00
nu-color-config revert: move to ahash (#9464) 2023-06-18 15:27:57 +12:00
nu-command add the ability to combine columns with detect columns (#9511) 2023-06-23 16:19:08 -05:00
nu-engine split $nu variable into scope commands and simpler $nu (#9487) 2023-06-21 09:33:01 +12:00
nu-explore nu-table/ Fix indexing issue for table --expand (#9484) 2023-06-20 20:27:00 +12:00
nu-glob Bump to 0.81.1 as development version (#9379) 2023-06-07 15:06:42 +02:00
nu-json Apply nightly clippy fixes (#9482) 2023-06-20 10:17:33 +02:00
nu-parser revert: move to ahash (#9464) 2023-06-18 15:27:57 +12:00
nu-path make *dots* tests easier to read (#9467) 2023-06-20 20:28:10 +12:00
nu-plugin revert: move to ahash (#9464) 2023-06-18 15:27:57 +12:00
nu-pretty-hex Bump to 0.81.1 as development version (#9379) 2023-06-07 15:06:42 +02:00
nu-protocol Add custom datetime format through strftime strings (#9500) 2023-06-23 15:05:04 -05:00
nu-std split $nu variable into scope commands and simpler $nu (#9487) 2023-06-21 09:33:01 +12:00
nu-system Bump once_cell from 1.17.1 to 1.18.0 (#9474) 2023-06-19 06:16:00 +00:00
nu-table nu-table/ Fix indexing issue for table --expand (#9484) 2023-06-20 20:27:00 +12:00
nu-term-grid Bump to 0.81.1 as development version (#9379) 2023-06-07 15:06:42 +02:00
nu-test-support Bump to 0.81.1 as development version (#9379) 2023-06-07 15:06:42 +02:00
nu-utils Add custom datetime format through strftime strings (#9500) 2023-06-23 15:05:04 -05:00
README.md Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00

Nushell core libraries and plugins

These sub-crates form both the foundation for Nu and a set of plugins which extend Nu with additional functionality.

Foundational libraries are split into two kinds of crates:

  • Core crates - those crates that work together to build the Nushell language engine
  • Support crates - a set of crates that support the engine with additional features like JSON support, ANSI support, and more.

Plugins are likewise also split into two types:

  • Core plugins - plugins that provide part of the default experience of Nu, including access to the system properties, processes, and web-connectivity features.
  • Extra plugins - these plugins run a wide range of different capabilities like working with different file types, charting, viewing binary data, and more.