Commit Graph

2202 Commits

Author SHA1 Message Date
Kelvin Samuel
eaea00366b
Fix a bug with us not outputting as µs with the into duration command (#8691)
# Description

Whilst working on [Allow parsing of mu (µ) character for
durations](https://github.com/nushell/nushell/pull/8647), I found a bug
where, if you use `into duration --convert us`, it outputs with the unit
as `us` rather than `µs`

![image](https://user-images.githubusercontent.com/44570273/229141818-37f97071-7f8e-451c-9baa-3c292290e6e7.png)

After this change, it now outputs the correct symbol:

![image](https://user-images.githubusercontent.com/44570273/229142720-6e67d49a-e88f-44a8-a742-92fa5220e54b.png)

# User-Facing Changes

User will now see correct unit when converting into microseconds.

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-utils/standard_library/tests.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-03-31 16:01:48 -05:00
Darren Schroeder
0788fe5e72
fully deprecate str collect (#8680)
# Description

This PR fully deprecates `str collect`. It's been "half-deprecatd" for a
long time. This takes it all the way and disallows the command in favor
of `str join`.

# User-Facing Changes

No more `str collect`

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-utils/standard_library/tests.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-03-31 13:23:22 -05:00
Stefan Holderbach
3bf5999ef4
Remove proptests for nuon writing/parsing (#8688)
# Description

The two tests `to_nuon_from_nuon` and `to_nuon_from_nuon_string` were
taking multiple seconds and have since been superseded by more explicit
unit tests. Compared to the time cost for devs and CI they seldomly
returned explicit problems. One failure only popped up after months, as
a sampled failure (https://github.com/nushell/nushell/pull/7564).


# User-Facing Changes

none

# Tests + Formatting

Fuzzing should move to a separate worker and be removed from the main
test suite.
See #8575 for experimentation around the impact on our test coverage.
2023-03-31 17:15:16 +02:00
Maxim Zhiburt
8a85299575
Fix of a fix of #8671 (#8675)
Hi @fdncred,

I accidentally noticed that your fix tricks wrapping a bit.


![image](https://user-images.githubusercontent.com/20165848/228908201-0d5c7878-739f-43a3-b931-a8dc9df85cd7.png)


It must address it.

PS: I believe the issue was originally caused by a false positive of
clippy. (maybe we shall report it I am not sure)

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-03-31 07:53:57 -05:00
JT
3db0aed9f7
Add rest and ignore-rest patterns (#8681)
# Description

Adds two more patterns when working with lists:

```
[1, ..$remainder]
```
and
```
[1, ..]
```
The first one collects the remaining items and assigns them into the
variable. The second one ignores any remaining values.

# User-Facing Changes

Adds more capability to list pattern matching.

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-utils/standard_library/tests.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-03-31 11:08:53 +13:00
Darren Schroeder
09276db2a5
add a threads parameter to par_each (#8679)
# Description

This PR allows you to control the amount of threads that `par-each` uses
via a `--threads(-t)` parameter. When no threads parameter is specified,
`par-each` uses the default, which is the same number of available CPUs
on your system.


![image](https://user-images.githubusercontent.com/343840/228935152-eca5b06b-4e8d-41be-82c4-ecd49cdf1fe1.png)

closes #4407

# User-Facing Changes

New parameter

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-utils/standard_library/tests.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-03-30 16:39:40 -05:00
Kelvin Samuel
bc6948dc89
Allow parsing of mu (µ) character for durations (issue #8614) (#8647)
# Description
This is to resolve the issue
[8614](https://github.com/nushell/nushell/issues/8614).
It allows the parsing of the mu (µ) character for durations, so you can
type `10µs`, and it correctly outputs, whilst maintaining the current
`us` parsing as well.

It also forces `durations` to be entered in lower case. 


![image](https://user-images.githubusercontent.com/44570273/228217360-57ebc902-cec5-4683-910e-0b18fbe160b1.png)
(The bottom one `1sec | into duration --convert us` looks like an
existing bug, where converting to `us` outputs `us` rather than `µs`)

# User-Facing Changes

Allows the user to parse durations in µs
Forces `durations` to be entered in lower case rather than any case, and
will error if not in lower case.

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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.

---------

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2023-03-30 17:35:35 +02:00
Darren Schroeder
e9c17daecd
fix inspect panic with large tables (#8673)
# Description

This PR fixes a small bug where `inspect` was panicking because the data
returned was larger than that terminal size.

Closes #8671
Closes #8674

# User-Facing Changes

No more panic

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-30 09:54:57 -05:00
Benjamin Lee
53beba7acc
Support passing an empty list to sort, uniq, sort-by, and uniq-by (issue #5957) (#8669)
# Description

Currently, all four of these commands return a (rather-confusing)
spanless error when passed an empty list:

```
> [] | sort
Error: 
  × no values to work with
  help: no values to work with
```

This PR changes these commands to always output `[]` if the input is
`[]`.

```
> [] | sort
╭────────────╮
│ empty list │
╰────────────╯
> [] | uniq-by foo
╭────────────╮
│ empty list │
╰────────────╯
```

I'm not sure what the original logic was here, but in the case of `sort`
and `uniq`, I think the current behavior is straightforwardly wrong.

`sort-by` and `uniq-by` are a bit more complicated, since they currently
try to perform some validation that the specified column name is present
in the input (see #8667 for problems with this validation, where a
possible outcome is removing the validation entirely). When passed `[]`,
it's not possible to do any validation because there are no records.
This opens up the possibility for situations like the following:

```
> [[foo]; [5] [6]] | where foo < 3 | sort-by bar
╭────────────╮
│ empty list │
╰────────────╯
```

I think there's a strong argument that `[]` is the best output for these
commands as well, since it makes pipelines like `$table | filter
$condition | sort-by $column` more predictable. Currently, this pipeline
will throw an error if `filter` evaluates to `[]`, but work fine
otherwise. This makes it difficult to write reliable code, especially
since users are not likely to encounter the `filter -> []` case in
testing (issue #5957). The only workaround is to insert manual checks
for an empty result. IMO, this is significantly worse than the "you can
typo a column name without getting an error" problem shown above.

Other commands that take column arguments (`get`, `select`, `rename`,
etc) already have `[] -> []`, so there's existing precedent for this
behavior.

The core question here is "what columns does `[]` have"? The current
behavior of `sort-by` is "no columns", while the current behavior of
`select` is "all possible columns". Both answers lead to accepting some
likely-buggy code without throwing on error, but in order to do better
here we would need something like `Value::Table` that tracks columns on
empty tables.

If other people disagree with this logic, I'm happy to split out the
`sort-by` and `uniq-by` changes into another PR.

# User-Facing Changes

`sort`, `uniq`, `sort-by`, and `uniq-by` now return `[]` instead of
throwing an error when input is `[]`.

# 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.

The existing behavior was not documented, and the new behavior is what
you would expect by default, so I don't think we need to update
documentation.

---------

Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-03-29 19:55:38 -07:00
Reilly Wood
995603b08c
Fix record-to-JSON conversion for HTTP commands (#8663)
This PR fixes a bug introduced in
https://github.com/nushell/nushell/pull/8571.

We were accidentally converting a `Result<Value, ShellError>` to JSON
instead of converting a `Value`. The upshot was that we were sending
JSON like `{"Ok":{"foo":"bar"}}` instead of `{"foo":"bar"}`.

This was an easy bug to miss, because `ureq::send_json()` accepts any
`impl serde::Serialize`. I've added a test to prevent regression.
2023-03-29 11:55:51 -07:00
JT
97e7d550c8
move 'str substring' to only use ranges (#8660)
# Description

This removes all the old style of quasi-ranges before we had full range
support from `str substring`. Functionality should otherwise work, but
only with the official range syntax.

# User-Facing Changes

Removes the array and string forms of ranges from `str substring`.
Leaves only the official range support for range values.

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-29 20:01:42 +13:00
Reilly Wood
da8cb14f8b
Fix select on empty lists (#8651)
This PR fixes `select` when given an empty list; it used to return
`null` when given an empty list. I also cleaned up other `select` tests
while I was in the area.

### Before:

```
> [] | select a | to nuon
null
```

### After:

```
> [] | select a | to nuon
[]
```

It looks like the previous behaviour was accidentally introduced by
[this PR](https://github.com/nushell/nushell/pull/7639).
2023-03-28 12:40:29 -07:00
JT
90b65018b6
Require that values that look like numbers parse as numberlike (#8635)
# Description

Require that any value that looks like it might be a number (starts with
a digit, or a '-' + digit, or a '+' + digits, or a special form float
like `-inf`, `inf`, or `NaN`) must now be treated as a number-like
value. Number-like syntax can only parse into number-like values.
Number-like values include: durations, ints, floats, ranges, filesizes,
binary data, etc.

# User-Facing Changes

BREAKING CHANGE
BREAKING CHANGE
BREAKING CHANGE
BREAKING CHANGE
BREAKING CHANGE
BREAKING CHANGE
BREAKING CHANGE
BREAKING CHANGE

Just making sure we see this for release notes 😅 

This breaks any and all numberlike values that were treated as strings
before. Example, we used to allow `3,` as a bare word. Anything like
this would now require quotes or backticks to be treated as a string or
bare word, respectively.

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-28 19:31:38 +13:00
JT
7ec5f2f2eb
Add or-patterns, fix var binding scope (#8633)
# Description

Adds `|` patterns to `match`, allowing you to try multiple patterns for
the same case.

Example:

```
match {b: 1} { {a: $b} | {b: $b} => { print $b } }
```

Variables that don't bind are set to `$nothing` so that they can be
later checked.

This PR also:
fixes #8631 

Creates a set of integration tests for pattern matching also

# User-Facing Changes

Adds `|` to `match`. Fixes variable binding scope. 
# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-27 11:31:57 +13:00
WindSoilder
944cad35bf
When running external command, expand tilde when pass back-quoted word (#8561)
# Description

Fixes: #8542

# User-Facing Changes

## Previous
```
❯ cat `~/TE ST/bug`
cat: ~/TE ST/bug: No such file or directory
```

## After
```
❯ cat `~/TE ST/bug`
a
```

This should be ok because We treat back-quoted strings as bare words

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-26 22:17:51 +13:00
JT
5b03bca138
Remove autoprinting of loop block values (#8618)
# Description

This removes autoprinting the final value of a loop, much in the same
spirit as not autoprinting values at the end of statements. As we fix
these corner cases, it becomes more consistent that to print to the
screen in a script, you use the `print` command.

This gives a noticeable performance improvement as a bonus.

Before:
```
C:\Source\nushell〉 for x in 1..10 { $x }
1
2
3
4
5
6
7
8
9
10
```
Now:
```
C:\Source\nushell〉 for x in 1..10 { $x }
C:\Source\nushell〉
```

# User-Facing Changes

**BREAKING CHANGE**

Loops like `for`, `loop`, and `while` will no longer automatically print
loop values to the screen.

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-26 13:23:54 +13:00
Reilly Wood
d409171ba8
Change comparison operators to allow nulls (#8617)
Prior to this PR, the less/greater than operators (`<`, `>`, `<=`, `>=`)
would throw an error if either side was null. After this PR, these
operators return null if either side (or both) is null.

### Examples
```bash 
1 < 3       # true
1 < null    # null
null < 3    # null
null < null # null
```

### Motivation

JT [asked the C#
folks](https://discord.com/channels/601130461678272522/615329862395101194/1086137515053957140)
and this is apparently the approach they would choose for comparison
operators if they could start from scratch.

This PR makes `where` more convenient to use on jagged/missing data. For
example, we can now filter on columns that may not be present in every
row:
```
> [{foo: 123} {}] | where foo? > 10
╭───┬─────╮
│ # │ foo │
├───┼─────┤
│ 0 │ 123 │
╰───┴─────╯
```
2023-03-26 12:10:09 +13:00
JT
6872d2ac2a
Speed up tight loop benchmarks (#8609)
# Description

This does a few speedups for tight loops:
* Caches the DeclId for `table` so we don't look it up. This means users
can't easily replace the default one, we might want to talk about this
tradeoff. The lookup for finding `table` in a tight loop is currently
pretty heavy. Might be another way to speed this up.
* `table` no longer pre-calculates the width. Instead, it only
calculates the width when printing a table or record.
* Use more efficient way of collecting the block of each loop
* When printing output, only get the config when needed

Combined, this drops the runtime from a million loop tight iteration
from 1sec 8ms to 236ms.

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-26 06:12:57 +13:00
JT
c0648a83be
Move variables to var stack (#8604)
# Description

This moves the representation of variables on the stack to a Vec, which
more closely resembles a stack. For small numbers of variables live at
any one point, this tends to be more efficient than a HashMap. Having a
stack-like vector also allows us to remember a stack position,
temporarily push variables on, then quickly drop the stack back to the
original size when we're done. We'll need this capability to allow
matching inside of conditions.

On this mac, a simple run of:

`timeit { mut x = 1; while $x < 1000000 { $x += 1 } }`

Went from 1 sec 86 ms, down to 1 sec 2 ms. Clearly, we have a lot more
ground we can make up in looping speed 😅 but it's nice that for fixing
this to make matching easier, we also get a win in terms of lookup speed
for small numbers of variables.

# User-Facing Changes

Likely users won't (hopefully) see any negative impact and may even see
a small positive impact.

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-25 12:56:45 +13:00
Reilly Wood
b4b68afa17
Make HTTP requests cancellable when trying to connect (#8591)
Closes #8585.

Prior to this change, the `http` commands could get stuck for 30s while
attempting to make a connection to a remote server. After this change,
`ctrl+c` works as expected:


![image](https://user-images.githubusercontent.com/26268125/227395505-c2d5b19d-6228-4eac-836f-c0c3426b0c19.png)

To make this work, we perform blocking `ureq` calls in a background
thread and poll the channel while checking `ctrl+c`.
2023-03-24 12:45:55 -07:00
mike
8cf9bc9993
allow lists to have type annotations (#8529)
this pr refines #8270 and closes #8109

# description
examples:

the original syntax is okay
```nu
def okay [nums: list] {}         # the type of list will be list<any>
```

empty annotations are allowed in any variation
the last two may be caught by a future formatter, 
but do not affect `nu` code currently
```nu
def okay [nums: list<>] {}       # okay

def okay [nums: list<     >] {}  # weird but also okay

def okay [nums: list<
>] {}                            # also weird but okay
```

types are allowed (See [notes](#notes) below)
```nu
def okay [nums: list<int>] {}    # `test [a b c]` will throw an error 

def okay [nums: list< int > {}   # any amount of space within the angle brackets is okay

def err [nums: list <int>] {}    # this is not okay, `nums` and `<int>` will be parsed as
                                 # two separate params, 
```

nested annotations are allowed in many variations
```nu
def okay [items: list<list<int>>] {}

def okay [items: list<list>] {}
```

any unterminated annotation is caught
```nu
Error: nu::parser::unexpected_eof

  × Unexpected end of code.
   ╭─[source:1:1]
 1 │ def err [nums: list<int] {}
   ·                       ▲
   ·                       ╰── expected closing >
   ╰────
```

unknown types are flagged
```nu
Error: nu::parser::unknown_type

  × Unknown type.
   ╭─[source:1:1]
 1 │ def err [nums: list<str>] {}
   ·                     ─┬─
   ·                      ╰── unknown type
   ╰────

Error: nu::parser::unknown_type

  × Unknown type.
   ╭─[source:1:1]
 1 │ def err [nums: list<int, string>] {}
   ·                    ─────┬─────
   ·                          ╰── unknown type
   ╰────
```

# notes
the error message for mismatched types in not as intuitive
```nu
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[source:1:1]
 1 │ def err [nums: list<int>] {}; err [a b c]
   ·                                    ┬
   ·                                    ╰── expected int
   ╰────
```
it should be something like this
```nu
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[source:1:1]
 1 │ def err [nums: list<int>] {}; err [a b c]
   ·                                    ──┬──
   ·                                      ╰── expected list<int>
   ╰────
```
this is currently not implemented
2023-03-24 12:54:06 +01:00
uaeio
d0aa69bfcb
Decode and Encode hex (#8392)
# Description

I need a command that will transform hex string into bytes and into
other direction.

I've implemented `decode hex` command and `encode hex` command. (Based
on `encode base64` and `decode base64` commands
# User-Facing Changes

```
> '010203' | decode hex
0x[01 02 03]
```

and 

```
> 0x[01 02 0a] | encode hex
'01020A'
```

---------

Co-authored-by: whiteand <andrewbeletskiy@gmail.com>
2023-03-24 12:25:26 +01:00
dependabot[bot]
4a1d12462f
Bump miette from 5.5.0 to 5.6.0 (#8531)
Bumps [miette](https://github.com/zkat/miette) from 5.5.0 to 5.6.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/zkat/miette/blob/main/CHANGELOG.md">miette's
changelog</a>.</em></p>
<blockquote>
<h2>5.6.0 (2023-03-14)</h2>
<h3>Bug Fixes</h3>
<ul>
<li><strong>ci:</strong> configure clippy-specific MSRV (<a
href="b658fc020b">b658fc02</a>)</li>
<li><strong>graphical:</strong> Fix wrong severity of related errors (<a
href="https://redirect.github.com/zkat/miette/issues/234">#234</a>) (<a
href="3497508aa9">3497508a</a>)</li>
<li><strong>atty:</strong> Switch out <code>atty</code> for
<code>is-terminal</code> (<a
href="https://redirect.github.com/zkat/miette/issues/229">#229</a>) (<a
href="443d240f49">443d240f</a>)</li>
</ul>
<h3>Features</h3>
<ul>
<li><strong>protocol:</strong> implement <code>Ord</code> for
<code>Severity</code> (<a
href="https://redirect.github.com/zkat/miette/issues/240">#240</a>) (<a
href="ed486c959d">ed486c95</a>)</li>
</ul>
<p><!-- raw HTML omitted --><!-- raw HTML omitted --></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="78fe18e699"><code>78fe18e</code></a>
chore: Release</li>
<li><a
href="2335b25ee7"><code>2335b25</code></a>
docs: update changelog</li>
<li><a
href="443d240f49"><code>443d240</code></a>
fix(atty): Switch out <code>atty</code> for <code>is-terminal</code> (<a
href="https://redirect.github.com/zkat/miette/issues/229">#229</a>)</li>
<li><a
href="ed486c959d"><code>ed486c9</code></a>
feat(protocol): implement <code>Ord</code> for <code>Severity</code> (<a
href="https://redirect.github.com/zkat/miette/issues/240">#240</a>)</li>
<li><a
href="3497508aa9"><code>3497508</code></a>
fix(graphical): Fix wrong severity of related errors (<a
href="https://redirect.github.com/zkat/miette/issues/234">#234</a>)</li>
<li><a
href="b658fc020b"><code>b658fc0</code></a>
fix(ci): configure clippy-specific MSRV</li>
<li><a
href="ebc61b5cf8"><code>ebc61b5</code></a>
docs: Mention miette::miette! macro under &quot;... in application
code&quot; (<a
href="https://redirect.github.com/zkat/miette/issues/233">#233</a>)</li>
<li><a
href="14f952dc91"><code>14f952d</code></a>
(cargo-release) start next development iteration 5.5.1-alpha.0</li>
<li><a
href="128c0a1fae"><code>128c0a1</code></a>
(cargo-release) start next development iteration 5.5.1-alpha.0</li>
<li>See full diff in <a
href="https://github.com/zkat/miette/compare/miette-derive-v5.5.0...miette-derive-v5.6.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=miette&package-manager=cargo&previous-version=5.5.0&new-version=5.6.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-24 22:55:25 +13:00
JT
8d5fbc6fcb
Fix closures that use matches. Move 'collect' to core. (#8596)
# Description

Fix patterns in pattern matching to properly declare their variables
when discovering which variables need to be closed over when creating a
closure.

Also, moves `collect` to core, so that the core language can use `$in`.

Fixes #8595 

# User-Facing Changes

See above

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-24 22:50:23 +13:00
JT
85bfdba1e2
Make timeit work with command calls (#8594)
# Description

Allows `timeit` to also run commands directly, eg) `timeit ls -la`

# User-Facing Changes

Additional capabilities to `timeit`.

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-24 22:34:03 +13:00
JT
546c753d1e
Move timeit to use blocks. Make match vars immutable (#8592)
# Description

This does a couple random changes/fixes:

* Moves `timeit` to use a block instead of a closure. This makes it a
bit more flexible.
* Moves var bindings in patterns to be immutable

# User-Facing Changes

`timeit` now takes a block and no arguments.

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-24 17:33:11 +13:00
JT
2c3aade057
Add pattern matching (#8590)
# Description

This adds `match` and basic pattern matching.

An example:

```
match $x {
  1..10 => { print "Value is between 1 and 10" }
  { foo: $bar } => { print $"Value has a 'foo' field with value ($bar)" }
  [$a, $b] => { print $"Value is a list with two items: ($a) and ($b)" }
  _ => { print "Value is none of the above" }
}
```

Like the recent changes to `if` to allow it to be used as an expression,
`match` can also be used as an expression. This allows you to assign the
result to a variable, eg) `let xyz = match ...`

I've also included a short-hand pattern for matching records, as I think
it might help when doing a lot of record patterns: `{$foo}` which is
equivalent to `{foo: $foo}`.

There are still missing components, so consider this the first step in
full pattern matching support. Currently missing:
* Patterns for strings
* Or-patterns (like the `|` in Rust)
* Patterns for tables (unclear how we want to match a table, so it'll
need some design)
* Patterns for binary values
* And much more

# User-Facing Changes

[see above]

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-24 14:52:01 +13:00
Sygmei
ec5396a352
feat: added multiple options to http commands (#8571)
# Description

All `http` commands now have a `-f` flag which for now contains the
`headers`, `body` and `status` fields (we can later add stuff like
`is-redirect` or `cookies`).


![image](https://user-images.githubusercontent.com/3835355/227048504-6686445d-ad2e-4f5d-905d-e71b3a4b81a6.png)

*Try it yourself*
```
http get http://mockbin.org/bin/630069dc-2c09-483a-a484-672561b7de14
http get -f http://mockbin.org/bin/630069dc-2c09-483a-a484-672561b7de14
```

The `http` commands can also now use the `-e` flag, which stands for
`--allow-errors`. When the status code is `>= 400`, it will still allow
you to interpret it like a normal response.


![image](https://user-images.githubusercontent.com/3835355/227047790-b9f5a25f-2c0d-4741-881f-4189b23e4ef6.png)

*Try it yourself*
```
http get http://mockbin.org/bin/2ebd3d27-bdc2-4ee8-b042-0bc2c0d1ad2a # should fail like usual
http get -e http://mockbin.org/bin/2ebd3d27-bdc2-4ee8-b042-0bc2c0d1ad2a # will return the body
http get -e -f http://mockbin.org/bin/2ebd3d27-bdc2-4ee8-b042-0bc2c0d1ad2a # will let you see the full response
```

# User-Facing Changes

- Adds `-f` (`--full`) to all `http` commands
- Adds `-e` (--allow-errors) to all `http` commands
2023-03-23 13:32:35 -07:00
mike
403bf1a734
unify the run functions of all and any (#8578)
# Description

this pr reduces duplication by making `any` and `all` commands use [one
function](66ad83c15c/crates/nu-command/src/filters/any.rs (LL63-L65C28))
2023-03-23 20:49:52 +01:00
Antoine Stevan
05ff7a9925
FIX: do not allow *start > end* in error make spans (#8570)
This should close #8567.

# Description
this PR throws an error when `start > end` in the most complete branch
of `ErrorMake::run`, i.e. when `$.msg`, `$.label.text`, `$.label.start`
and `$.label.end` are defined.

i've also added a `error_start_bigger_than_end_should_fail` test to
check that it does indeed return the right error.

# User-Facing Changes
no more crash when manipulating span bounds and a clear error, e.g.
```bash
>_ error make {msg: "msg" label: {text: "text" start: 1010 end: 1000}}
Error:
  × invalid error format.
   ╭─[entry #3:1:1]
 1 │ error make {msg: "msg" label: {text: "text" start: 1010 end: 1000}}
   ·                               ──────────────────┬─────────────────
   ·                                                 ╰── `$.label.start` is stricly bigger than `$.label.end`
   ╰────
  help: 1010 > 1000
```
or
```bash
>_ error make {
:::     msg: "msg"
:::     label: {
:::         text: "text"
:::         start: ($nu.scope.engine_state.source_bytes - 90)
:::         end: ($nu.scope.engine_state.source_bytes - 100)
:::     }
::: }
Error:
  × invalid error format.
   ╭─[entry #4:2:1]
 2 │         msg: "msg"
 3 │ ╭─▶     label: {
 4 │ │           text: "text"
 5 │ │           start: ($nu.scope.engine_state.source_bytes - 90)
 6 │ │           end: ($nu.scope.engine_state.source_bytes - 100)
 7 │ ├─▶     }
   · ╰──── `$.label.start` is stricly bigger than `$.label.end`
 8 │     }
   ╰────
  help: 204525 > 204515
```

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🔴 `toolkit test`

# After Submitting
```
$nothing
```
2023-03-23 20:31:06 +01:00
Reilly Wood
5c2a767987
Better error message for mv when file not found (#8586)
Closes #8546.

### Before:
```
> mv foo.txt bar.txt
Error:
  × Invalid file or pattern
   ╭─[entry #2:1:1]
 1 │ mv foo.txt bar.txt
   ·    ───┬───
   ·       ╰── invalid file or pattern
   ╰────
```

### After:
```
> mv foo.txt bar.txt
Error:
  × File(s) not found
   ╭─[entry #2:1:1]
 1 │ mv foo.txt bar.txt
   ·    ───┬───
   ·       ╰── could not find any files matching this glob pattern
   ╰────
```
2023-03-23 11:31:49 -07:00
Christian Friedow
66ad83c15c
from ssv --aligned-columns should separate lines by character index instead of byte index (#8558)
# Description

## Symptom
Lines which are input into `from ssv --aligned-columns` are split
incorrectly of they contain utf-8 characters which have the length of
multiple bytes. Notice how the values of the `Bars` column bleeds into
the `Security` column in the following output (the big grey areas are
censored data ;) ):

![before-patch](https://user-images.githubusercontent.com/17351844/226757737-be7ca493-5c64-4a91-9153-984df515bb8c.png)

## Problem
The function behind `from ssv --aligned-columns` splits lines into
fields by byte index (which is default behavior of str.get(...) in Rust)
instead of character index. If the header row has a different length in
bytes than the remaining table rows, the split is executed incorrectly.

## Solution
The function behind `from ssv --aligned-columns1 now separates lines by
character index instead of byte index. This productes the following
(correct) output (the big grey areas are censored data ;) ):

![after-patch](https://user-images.githubusercontent.com/17351844/226757850-7acaebf3-2d40-4f85-b76e-64e465254bda.png)
2023-03-22 17:54:18 -05:00
Jakub Žádník
c48e9cdf5b
Disable alias recursion (for real) (#8557) 2023-03-22 23:16:06 +02:00
JT
2f8a52d256
Switch let/let-env family to init with math expressions (#8545)
# Description

This is an experiment to see what switching the `let/let-env` family to
math expressions for initialisers would be like.

# User-Facing Changes

This would require any commands you call from `let x = <command here>`
(and similar family) to call the command in parentheses. `let x = (foo)`
to call `foo`.

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-23 09:14:10 +13:00
dependabot[bot]
a193b85123
Bump alphanumeric-sort from 1.4.4 to 1.5.0 (#8532) 2023-03-22 13:02:45 +00:00
dependabot[bot]
0f40c44ed2
Bump windows from 0.44.0 to 0.46.0 (#8535) 2023-03-22 13:02:03 +00:00
Sygmei
a1840e9d20
fix: fixed typo and improved Value TypeMismatch exceptions (#8324)
# Description

This PR aims to improve `TypeMismatch` exception that occurs when
comparing two values with `<`, `>`, `<=` or `>=` operators.

*Before*

![image](https://user-images.githubusercontent.com/3835355/222980803-8cb0f945-5a82-4512-9989-5df0ec4e4969.png)

*After*

![image](https://user-images.githubusercontent.com/3835355/226754903-68e56344-065d-42ee-b184-ab968e91c6de.png)

This PR also bundles a small refactor for histogram forbidden column
names exception, previous implementation forgot a column name in the
message, to avoid this, I'm re-using the same array for checking and
error display

# User-Facing Changes

Not much changes except a better and more readable exception for the
user

# Tests + Formatting

Does not break any tests, formatting passes as well :)
2023-03-22 09:47:40 +01:00
mike
e89c796b41
fix: bytes length example description typo (#8550)
this pr fixes a typo
2023-03-21 11:41:37 -05:00
Antoine Stevan
758351c732
FEATURE: add --raw. --tabs and --indent to to nuon as in to json (#8366)
Should close #7255.

# Description
**TL;DR**: this PR adds `--indent <int>`, `--tabs <int>` and `--raw` to
control a bit more the `string` output of `to nuon`, as done in `to
json` already, the goal being to promote the `NUON` format through easy
to read and formatted output `.nuon` files 😋

### outside of `crates/nu-command/src/formats/to/nuon.rs`
as the signature of `value_to_string` has changed, the single call to it
outside of its module definition has been changed to use default values
=> `value_to_string(&value, Span::unknown(), 0, &None)` in
`crates/nu-command/src/filters/uniq.rs`

### changes to `ToNuon` in `crates/nu-command/src/formats/to/nuon.rs`
- the signature now features `--raw`, `--indent <int>` and `--tabs
<int>`
- the structure of the `run` method is inspired from the one in `to
json`
  - we get the values of the arguments
  - we convert the input to a usable `Value`
- depending on whether the user raised `--raw`, `--indent` or `--tabs`,
we call the conversion to `string` with different values of the
indentation, starting at depth 0
- finally, we return `Ok` or a `ShellError::CantConvert` depending on
the conversion result
- some tool functions
- `get_true_indentation` gives the full indentation => `indent` repeated
`depth` times
- `get_true_separators` gives the line and field separators => a `("\n",
"")` when using some formatting or `("", " ")` when converting as pure
string on a single line

the meat of `nuon.rs` is now the `value_to_string` recursive function:
- takes the depth and the indent string
- adds correct newlines, space separators and indentation to the output
- calls itself with the same indent string but `depth + 1` to increase
the indentation by one level
- i used the `nl`, `idt`, `idt_po` (**i**n**d**en**t** **p**lus **o**ne)
and `idt_pt` (**i**n**d**en**t** **p**lus **t**wo) to make the
`format!`s easier to read

# User-Facing Changes
users can now
- control the amount and nature of NUON string output indentation with
  - `--indent <number of " " per level>`
  - `--tabs <number of "\t" per level>` 
- use the previous behaviour of `to nuon` with the `--raw` option
- have new examples with `help to nuon`

> **Note**
> the priority order of the options is the following
> 1. `--raw`
> 2. `--tabs`
> 3. `--indent`
>
> the default is `--indent 2`

# Tests + Formatting
### new tests
- tests involving the string output of `to nuon`, i.e. tests not of the
form `... | to nuon | from nuon ...`, now use the `to nuon --raw`
command => this is the smallest change to have the tests pass, as the
new `to nuon --raw` is equivalent to the old `to nuon`
- in `crates/nu-command/src/formats/to/nuon.rs`, the previous example
has been replaced with three examples
  - `[1 2 3] | to nuon` to show the default behaviour
  - `[1 2 3] | to nuon --raw` to show the not-formatted output
- a more complex example with `{date: 2000-01-01, data: [1 [2 3] 4.56]}
| to nuon`
  - the result values have been defined and the `examples` tests pass
 
### dev
- 🟢 `cargo fmt --all`
- 🟢 `cargo clippy --workspace -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect`
- 🟢 `cargo test --workspace` ~~passes but without
`to_nuon_errs_on_closure`~~ fixed in
0b4fad7eff

# After Submitting
the `to nuon` page would have to be regenerated at some point due to the
new tests
2023-03-20 15:47:18 -05:00
dependabot[bot]
b0be6c3013
Bump quick-xml from 0.27.1 to 0.28.1 (#8533) 2023-03-20 17:46:28 +00:00
dependabot[bot]
9c6bfc0be9
Bump rstest from 0.16.0 to 0.17.0 (#8534) 2023-03-20 17:27:29 +00:00
Steven Xu
1d3f6105f5
feat: add a command_not_found hook (#8314)
# Description
Add a `command_not_found` function to `$env.config.hooks`. If this
function outputs a string, then it's included in the `help`.

An example hook on *Arch Linux*, to find packages that contain the
binary, looks like:

```nushell
let-env config = {
  # ...
  hooks: {
    command_not_found: {
      |cmd_name| (
        try {
          let pkgs = (pkgfile --binaries --verbose $cmd_name)
          (
            $"(ansi $env.config.color_config.shape_external)($cmd_name)(ansi reset) " +
            $"may be found in the following packages:\n($pkgs)"
          )
        } catch {
          null
        }
      )
    }
    # ...
```

# User-Facing Changes
- Add a `command_not_found` function to `$env.config.hooks`.

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# 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-03-20 17:05:22 +13:00
Artemiy
491a9c019c
Revert "Hide 7925" (#8500)
Revert nushell/nushell#8359
Turn `[empty list]` on by default again
2023-03-18 08:58:13 +13:00
JT
0ca49091c0
Add rest and glob support to 'open' (#8506)
# Description

This adds two different features to `open`:
* The ability to pass more than one file to `open`.
* Support for using globs in the filenames

`open` will create a list stream and stream the output if there is more
than one file opened

Examples:

```
open file1.csv file2.csv file3.csv
```

```
open *.nu | where $it =~ "echo"
```

# User-Facing Changes

Multi-file and glob support in `open`. Original `open` functionality
should continue as before.

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-18 08:51:39 +13:00
Darren Schroeder
ef7fbf4bf9
Revert "Allow NU_LIBS_DIR and friends to be const" (#8501)
Reverts nushell/nushell#8310

In anticipation that we may want to revert this PR. I'm starting the
process because of this issue.

This stopped working
```
let-env NU_LIB_DIRS = [
    ($nu.config-path | path dirname | path join 'scripts')
    'C:\Users\username\source\repos\forks\nu_scripts'
    ($nu.config-path | path dirname)
]
```
You have to do this now instead.
```
const NU_LIB_DIRS = [
    'C:\Users\username\AppData\Roaming\nushell\scripts'
    'C:\Users\username\source\repos\forks\nu_scripts'
    'C:\Users\username\AppData\Roaming\nushell'
]
```

In talking with @kubouch, he was saying that the `let-env` version
should keep working. Hopefully it's a small change.
2023-03-17 09:33:24 -05:00
WindSoilder
a8eef9af33
Restrict closure expression to be something like {|| ...} (#8290)
# Description

As title, closes: #7921 closes: #8273

# User-Facing Changes

when define a closure without pipe, nushell will raise error for now:
```
❯ let x = {ss ss}
Error: nu::parser::closure_missing_pipe

  × Missing || inside closure
   ╭─[entry #2:1:1]
 1 │ let x = {ss ss}
   ·         ───┬───
   ·            ╰── Parsing as a closure, but || is missing
   ╰────
  help: Try add || to the beginning of closure
```

`any`, `each`, `all`, `where` command accepts closure, it forces user
input closure like `{||`, or parse error will returned.
```
❯ {major:2, minor:1, patch:4} | values | each { into string }
Error: nu::parser::closure_missing_pipe

  × Missing || inside closure
   ╭─[entry #4:1:1]
 1 │ {major:2, minor:1, patch:4} | values | each { into string }
   ·                                             ───────┬───────
   ·                                                    ╰── Parsing as a closure, but || is missing
   ╰────
  help: Try add || to the beginning of closure
```

`with-env`, `do`, `def`, `try` are special, they still remain the same,
although it says that it accepts a closure, but they don't need to be
written like `{||`, it's more likely a block but can capture variable
outside of scope:
```
❯ def test [input] { echo [0 1 2] | do { do { echo $input } } }; test aaa
aaa
```

Just realize that It's a big breaking change, we need to update config
and scripts...

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# 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-03-17 07:36:28 -05:00
StevenDoesStuffs
400a9d3b1e
Allow NU_LIBS_DIR and friends to be const (#8310)
# Description

Allow NU_LIBS_DIR and friends to be const they can be updated within the
same parse pass. This will allow us to remove having multiple config
files eventually.

Small implementation detail: I've changed `call.parser_info` to a
hashmap with string keys, so the information can have names rather than
indices, and we don't have to worry too much about the order in which we
put things into it.

Closes https://github.com/nushell/nushell/issues/8422

# User-Facing Changes

In a single file, users can now do stuff like
```
const NU_LIBS_DIR = ['/some/path/here']
source script.nu
```
and the source statement will use the value of NU_LIBS_DIR declared the
line before.

Currently, if there is no `NU_LIBS_DIR` const, then we fallback to using
the value of the `NU_LIBS_DIR` env-var, so there are no breaking changes
(unless someone named a const NU_LIBS_DIR for some reason).


![2023-03-04-014103_hyprshot](https://user-images.githubusercontent.com/13265529/222885263-135cdd0d-7884-438b-b2ed-c3979fa44463.png)

# Tests + Formatting

~~TODO: write tests~~ Done

# After Submitting

~~TODO: update docs~~ Will do when we update default_env.nu/merge
default_env.nu into default_config.nu.
2023-03-17 07:23:29 -05:00
Luc Perkins
7095d8994e
Add char --list example to char command docs (#8474)
# Description

When using `char`, I somehow missed the `--list` flag (even though it's
of course displayed in the help output). While it's maybe a bit
redundant to have a usage of the flag in the examples, I suspect that I
may not be alone in needing an extra nudge on getting that info 😄

# User-Facing Changes

Just an extra example in the `char` help output.
2023-03-17 10:15:41 +01:00
JT
2d41613039
bump to 0.77.2 (#8496)
# Description

_(Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.)_

_(Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.)_

# 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` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

> **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-03-17 21:29:15 +13:00
Dan Davison
7625aed200
SQL-style join command for Nushell tables (#8424)
This PR adds a command `join` for performing SQL-style joins on Nushell
tables:

```
〉join -h
Join two tables

Usage:
  > join {flags} <right-table> <left-on> (right-on)

Flags:
  -h, --help - Display the help message for this command
  -i, --inner - Inner join (default)
  -l, --left - Left-outer join
  -r, --right - Right-outer join
  -o, --outer - Outer join

Signatures:
  <table> | join list<any>, <string>, <string?> -> <table>

Parameters:
  right-table <list<any>>: The right table in the join
  left-on <string>: Name of column in input (left) table to join on
  (optional) right-on <string>: Name of column in right table to join on. Defaults to same column as left table.

Examples:
  Join two tables
  > [{a: 1 b: 2}] | join [{a: 1 c: 3}] a
  ╭───┬───┬───╮
  │ a │ b │ c │
  ├───┼───┼───┤
  │ 1 │ 2 │ 3 │
  ╰───┴───┴───╯
```

<table>
    <tbody>
        <tr>
<td><img width="400" alt="image"
src="https://user-images.githubusercontent.com/52205/224578744-eb9d133e-2510-4a3d-bd0a-d615f07a06b7.png"></td>
        </tr>
    </tbody>
  </table>


# User-Facing Changes

Adds a new command `join`

# Tests + Formatting

```
cargo test -p nu-command commands::join
```

Don't forget to add tests that cover your changes.

- [x] `cargo fmt --all -- --check` to check standard code formatting
(`cargo fmt --all` applies these changes)
- [x] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- [x] `cargo test --workspace` to check that all tests pass

# 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.

---------

Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-03-16 16:57:20 -07:00