Compare commits

...

148 Commits

Author SHA1 Message Date
2ec2028637 Bump version to 0.78.0 (#8715)
# Description

Version bump for the `0.78.0`

Start to include the version with our `default_config.nu` and
`default_env.nu`

# Checklist

- [x] reedline
- [ ] release notes
2023-04-04 20:47:00 +02:00
b84a01cb1d Pin reedline to 0.18.0 release (#8728)
# Description

see release notes:

https://github.com/nushell/reedline/releases/tag/v0.18.0
2023-04-04 00:23:08 +02:00
ca4d8008d4 Fix rest of license year ranges (#8727)
# Description

In theory we don't need to include the end of the year range for a
proper MIT license.
2023-04-04 09:03:29 +12:00
JT
a256f6d0d1 Update LICENSE 2023-04-03 08:23:19 +12:00
0aa6954f33 Update .gitignore (#8717)
# Description

Ignore the files from JetBrain's Fleet IDE

# User-Facing Changes
2023-04-02 21:28:42 +02:00
68d98fcf24 Remove unused atty dep in nu-table (#8716)
# Description

nfm
2023-04-02 20:30:36 +02:00
87086262f3 make bytes at use ranges (#8710)
# Description

follow up to #8660 

# User-Facing Changes

**BREAKING CHANGE**
any scripts using the previous string or list syntax will BREAK
2023-04-03 04:28:36 +12:00
3fab427383 Fix(tests/nu-command): remove unnecessary cwd() and pipeline(), etc (#8711)
# Description

This PR aims to cover the tests under nu-command as part of this issue
#8670 to clean up any unnecessary wrapping funcs like `cwd(".")` or
`pipeline()`, etc.

This PR is still WIP and opening as draft to get first impressions and
feedback on a few tests before I go on changing more.


# User-Facing Changes

None

# Tests + Formatting

None

# After Submitting

None

---------

Signed-off-by: Harshal Chaudhari <harshal.chaudhary@gmail.com>
Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-04-02 08:25:05 -07:00
61fa826159 Fix two stable clippy lints (#8712)
# Description

Unnecessary calls to `.into_iter()`


# User-Facing Changes

None

# Tests + Formatting

Only visible on stable toolchain
2023-04-02 16:23:19 +02:00
JT
0b9fc4ff3a give better error when a numberlike is used for strings (#8706)
# Description

Before:
```
  × Type mismatch during operation.
   ╭─[source:1:1]
 1 │               def 7zup [] {} 
   ·                   ──┬─
   ·                     ╰── expected string
   ╰────
```

Now:
```
  × Type mismatch during operation.
   ╭─[source:1:1]
 1 │               def 7zup [] {} 
   ·                   ──┬─
   ·                     ╰── expected string, found number-like value (hint: use quotes or backticks)
   ╰────
```

# 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
- `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-04-02 07:48:45 +12:00
JT
1817d5e01e prevent redefining fields in a record (#8705)
# Description

Prevents redefining fields in a record, for example `{a: 1, a: 2}` would
now error.

fixes https://github.com/nushell/nushell/issues/8699

# User-Facing Changes

Is technically a breaking change. If you relied on this behaviour to
give you the last value, your code will now error.

# 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-04-02 06:09:33 +12:00
0ca0f8ec17 move the show_banner config field to the top (#8702)
Should close https://github.com/nushell/nushell/issues/8698 and similar
issues.

# Description
simply moves the `show_banner` field and its comment to the top of the
default config file.

# User-Facing Changes
this should make the setting easier to see and encourage people to
modify the line instead of adding another line before the default
`show_banner: true`, which would overwrite the setting.

# Tests + Formatting
```
$nothing
```

# After Submitting
the default banner links to
https://www.nushell.sh/book/configuration.html#remove-welcome-message,
which does not mention this issue => this will have to be updated
2023-04-01 07:30:20 -05:00
6be5631477 Add math exp command (issue #8661) (#8700)
# Description
I copied the `math ln` command and replaced the relevant parts to
implement `math exp`.

# User-Facing Changes

The `math exp` command was added. Now one can do `[1, 2, 3] | math exp`
to get e to the power of these numbers.

# Tests + Formatting
I only wrote example tests, same as for `math ln`, which also does not
have special tests. I have ran into an issue with the tests but it seems
completely unrelated (see #8687)

# After Submitting

This PR was done in order to make the documentation complete, so I'm not
adding any documentation except `math ln`.
2023-04-01 12:53:58 +02:00
678e942bd8 Remove -t/--threads flag from nu (#8686)
### What?

This PR removes the `--threads` flag from nu.exe:


![image](https://user-images.githubusercontent.com/26268125/229021408-bf78ce64-11f7-4354-a410-ed905b96bb5a.png)

### Why?

Darren added a `--threads` flag to `par-each` in
https://github.com/nushell/nushell/pull/8679, so it no longer respects
the global `--threads` flag. Now the only place `rayon` is used is [the
`table`
renderer](3db0aed9f7/crates/nu-command/src/viewers/table.rs (L15)).

I don't think anyone will actually want to specify the number of threads
used in `table`, and it would be confusing to leave this flag around
when it no longer does anything useful.

### Notes

Relevant `rayon` docs:
https://docs.rs/rayon/latest/rayon/struct.ThreadPoolBuilder.html#method.build_global
2023-04-01 20:47:56 +13:00
83ddf0ebe2 Make optional cell paths work with reject (#8697)
This PR makes `?` work with `reject`. For example:

```bash
> {} | reject foo
Error: nu:🐚:column_not_found

  × Cannot find column
   ╭─[entry #2:1:1]
 1 │ {} | reject foo
   ·      ───┬── ─┬─
   ·         │    ╰── cannot find column 'foo'
   ·         ╰── value originates here
   ╰────

> {} | reject foo?
╭──────────────╮
│ empty record │
╰──────────────╯
```

This was prompted by [a user
question](https://discord.com/channels/601130461678272522/614593951969574961/1091466428546306078).
I would like to get this in for 0.78, I think it's low-risk and I want
the `?` feature to be as polished as possible for its debut.
2023-03-31 16:40:19 -07:00
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
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
b2257a5ca3 fix test_default_config_path test after pr 8653 (#8690)
# Description

This PR fixes a testing bug that @rgwood found and PR #8653 introduced,
mentioned
[here](https://github.com/nushell/nushell/pull/8653#issuecomment-1491263657).
Since 8653 returns canonicalizes config paths now, the tests need to
return canonicalized paths as well. Without this PR, if you have your
nushell config dir symlinked, this test will fail. This PR fixes that
test.

# User-Facing 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
- `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:17:37 -05:00
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
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
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
JT
0e496f900d Remove CI coverage until we can figure out why it's broken (#8677)
# Description

The coverage testing on CI has been broken for at least a week. It looks
like we might have to do some work, but for now, disabling it so we
don't give bad stability info to contributors.

# 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
- `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 06:49:26 +13:00
1ed645c6c2 feature: add the standard library tests to the PR template and the toolkit (#8629)
Related to #8525.

# Description
With #8525, the tests for the standard library have been enabled in the
CI.
The only places where these tests are missing are
- the PR template
- the toolkit

This PR adds
- `cargo run -- crates/nu-utils/standard_library/tests.nu` to the PR
template
- the same command as `toolkit test stdlib`
- the `test stdlib` command to `toolkit check pr`

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
the new output of `toolkit check pr`, with the same color code:
> - 🟢 `toolkit fmt`
> - 🟢 `toolkit clippy`
> - 🟢 `toolkit test`
> - 🟢 `toolkit test stdlib`

# After Submitting
```
$nothing
```
2023-03-30 19:25:42 +02:00
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
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
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
ed0fce9aa6 REFACTOR: remove the redundant path expand from the tests of the standard library (#8666)
Related to #8653.

# Description
This PR removes the redundant `path expand`s introduced in #8552 and
#8576.

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
the tests still pass on linux.

# After Submitting
```
$nothing
```
2023-03-29 16:17:00 -05:00
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
a49e5b30ff auto-expand paths in the $nu variable (#8653)
# Description

I recently ran into an issue where one of the $nu paths was not expanded
and was causing issue because $env.PWD did not equal $nu.temp-path, even
though I was in $nu.temp-path. The reason it didn't match was because my
temp path was symlinked. This PR fixes that issue by expanding the paths
with canonicalize_with().

# User-Facing 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-29 13:23:58 -05: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
bc54930bc6 one more try on readme (#8659)
# Description

Take 2...

_(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-28 22:19:33 -07:00
0d6e43097d Add the showcase repo to Readme.md to give it more exposure to our developers (#8658)
# Description

The showcase repo has some cool material in it that I think is valuable
for our readers developers. Giving it a bit more exposure by putting it
our Readme will allow more folks to know this is yet another valuable
resource. I learned about this today from Darren and thought it would be
good to allow others the same opportunity to find it easier as well...

_(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-28 22:12:07 -07:00
JT
393717dbb4 Improve inferred record types and type compat (#8649)
# Description

This allows for type inference to infer record types in more cases. The
only time we will now fall back to `Any` is when one of the fields has a
computed value.

I also updated the type mismatch error and highlighting to be in-line
with other errors.

# User-Facing Changes

This may result in stricter type checking. Previously `{}` had the
inferred type `Any` but will now have the correct inferred type of
`Record<>`.

# 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 10:23:10 +13:00
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
9f01cf333c stdlib: fix the assert equal tests (#8650)
Related to #8150, #8635 and #8632.

# Description
i've introduced a bad set of tests for the `assert equal` command in
#8150...

they should not compare `1 + 2` and `4)` or `3)` but the ints.

in this PR, i remove this spurious parentheses that were not planned at
all 😬 👀


# User-Facing Changes
```
$nothing
```

# Tests + Formatting
```
>_ nu crates/nu-utils/standard_library/tests.nu
INF|2023-03-28T20:18:13.022|Running tests in test_asserts
INF|2023-03-28T20:18:13.173|Running tests in test_dirs
INF|2023-03-28T20:18:13.247|Running tests in test_logger
INF|2023-03-28T20:18:13.473|Running tests in test_std
```

# After Submitting
```
$nothing
```
2023-03-28 13:34:26 -05:00
d391e912ff stdlib: Add back recursive lookup for tests (#8632)
@amtoine during the refactor the test runner lost the ability for
looking up for test modules in subdirectories. I just added it back now.
2023-03-28 13:17:46 -05:00
JT
8b185a4008 Improve number-like error if expecting a string (#8645)
# Description

This should give a slightly better error if a position expects a string
and the user writes a number-like value.

# 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-28 21:25:35 +13: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
332f1192a6 stdlib: optimize test search and add better errors (#8626)
the first part of this PR comes from a request from @presidento in
#8525.
the second one is an improvement of the error support.

# Description
this PR
- computes `module_search_pattern` to only `ls` the selected modules =>
the goal is to save search time in the future with more tests
- gives better errors when
  - the `--path` is invalid
  - the `--module` does not exist
  - the search is too strict

### examples
```bash
>_ nu crates/nu-utils/standard_library/tests.nu --path does-not-exist
Error: 
  × directory_not_found
   ╭─[<commandline>:1:1]
 1 │ main --path does-not-exist
   ·             ───────┬──────
   ·                    ╰── no such directory
   ╰────
```

```bash
>_ nu crates/nu-utils/standard_library/tests.nu --module does-not-exist
Error: 
  × module_not_found
   ╭─[<commandline>:1:1]
 1 │ main --module does-not-exist
   ·               ───────┬──────
   ·                      ╰── no such module in /home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/
   ╰────
```

```bash
>_ nu crates/nu-utils/standard_library/tests.nu --command does_not_exist
Error: 
  × no test to run
```

instead of the previous

```bash
>_ nu crates/nu-utils/standard_library/tests.nu --path does-not-exist
Error: 
  × No matches found for /home/amtoine/.local/share/git/store/github.com/amtoine/nushell/does-not-exist/test_*.nu
    ╭─[/home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/tests.nu:32:1]
 32 │     let tests = (
 33 │         ls ($path | default $env.FILE_PWD | path join "test_*.nu")
    ·            ───────────────────────────┬───────────────────────────
    ·                                       ╰── Pattern, file or folder not found
 34 │         | each {|row| {file: $row.name name: ($row.name | path parse | get stem)}}
    ╰────
  help: no matches found
```

```bash
>_ nu crates/nu-utils/standard_library/tests.nu --module does-not-exist
Error: 
  × expected table from pipeline
    ╭─[/home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/tests.nu:59:1]
 59 │         $tests_to_run
 60 │         | group-by module
    ·           ────┬───
    ·               ╰── requires a table input
 61 │         | transpose name tests
    ╰────
```

```bash
>_ nu crates/nu-utils/standard_library/tests.nu --command does-not-exist
Error: 
  × expected table from pipeline
    ╭─[/home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/tests.nu:59:1]
 59 │         $tests_to_run
 60 │         | group-by module
    ·           ────┬───
    ·               ╰── requires a table input
 61 │         | transpose name tests
    ╰────
```

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
```
$nothing
```

# After Submitting
```
$nothing
```
2023-03-26 08:09:26 -05:00
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
86ae27b0c1 fix unhelpful error message with extra characters in list annotations (#8619)
# Description

with such a line
```nu
def err [list: list<>extra] {}
```
this pr changes the error message from 
```nu
Error: nu::parser::unclosed_delimiter

  × Unclosed delimiter.
   ╭─[entry #69:1:1]
 1 │ def err [list: list<>extra] {}
   ·                ─────┬─────
   ·                      ╰── unclosed >
   ╰────
```
to
```nu
  × Extra characters in the parameter name.
   ╭─[entry #69:1:1]
 1 │ def err [list: list<>extra] {}
   ·                      ──┬──
   ·                        ╰── extra characters
   ╰────
```
2023-03-26 10:59:47 +02:00
d9a888528a fix unhelpful error message with '@' custom completion (#8620)
# Description

with such a line 
```nu
extern err [--flag: string@]
```
this pr changes the error message from
```nu
Error: nu::parser::unknown_command

  × Unknown command.
   ╭─[entry #69:1:1]
 1 │ extern err [--flag: string@]
   ·                            ▲
   ·                            ╰── unknown command
   ╰────
```
to
```nu
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[entry #69:1:1]
 1 │ extern err [--flag: string@]
   ·                            ▲
   ·                            ╰── expected command name
   ╰────
```
2023-03-26 10:58:33 +02:00
05f1b41275 remove match from the standard library (#8625)
Should close #8616.
Related to #8590.

# Description
With the new builtin `match` command introduced in the `rust` source in
#8590, there is no need to have a custom `match` in the standard
library.
This PR removes the `match` command from `std.nu` and the associated
test.

# User-Facing Changes
Users can not access `match` from `std.nu`.

# Tests + Formatting
```
nu crates/nu-utils/standard_library/tests.nu  --path crates/nu-utils/standard_library/ out+err> /dev/null; ($env.LAST_EXIT_CODE == 0)
```
gives `true`

# After Submitting
```
$nothing
```
2023-03-26 10:57:41 +02: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
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
0567407f85 standard library: bring the tests into the main CI (#8525)
Should close one of the tasks in #8450.

# Description
> **Note**
> in order of appearance in the global diff

- 1b7497c419 adds the `std-tests` job to
the CI which
  1. installs `nushell` in the runner
  2. run the `tests.nu` module
> see `open .github/workflows/ci.yml | get jobs.std-tests | to yaml`

-
[`ec85b6fd`..`9c122115`](ec85b6fd3fc004cd94e3fada5c8e5fe2714fd629..9c12211564ca8ee90ed65ae45776dccb8f8e4ef1)
is where all the magic happens => see below
- 🧪 799c7eb7fd introduces some
bugs and failing test to see how the CI behaves => see how the [tests
failed](https://github.com/nushell/nushell/actions/runs/4460098237/jobs/7833018256)
as expected 
- 🧪 and c3de1fafb5 reverts the
failing tests, i.e. the previous commit, leaving a standard library
whose tests all pass 🎉 => see the [tests
passing](https://github.com/nushell/nushell/actions/runs/4460153434/jobs/7833110719?pr=8525#step:5:1)
now ✔️

## the changes to the runner
> see
[`ec85b6fd`..`9c122115`](ec85b6fd3fc004cd94e3fada5c8e5fe2714fd629..9c12211564ca8ee90ed65ae45776dccb8f8e4ef1)

the issue with the previous runner was the following: the clever trick
of using `nu -c "use ...; test"` did print the errors when occuring but
they did not capture the true "failure", i.e. in all cases the
`$env.LAST_EXIT_CODE` was set to `0`, never stopping the CI when a test
failed 🤔

i first tried to `try` / `catch` the error in
ec85b6fd3f which kinda worked but only
throw a single error, the first one

i thought it was not the best and started thinking about a solution to
have a complete report of all failing tests, at once, to avoid running
the CI multiple times!

the easiest solution i found was the one i implemented in
9c12211564
> **Warning**
> this changes the structure of the runner quite a bit, but the `for`
loops where annoying to manipulate structured data and allow the runner
to draw a complete report...

now the runner does the following
- compute the list of all available tests in a table with the `file`,
`module` and `name` columns (first part of the pipe until `flatten` and
`rename`)
- run the tests one by one computing the new `pass` column
  - with a `log info`
- captures the failing ones => puts `true` in `pass` if the test passes,
`false` otherwise
- if at least one test has failed, throw a single error with the list of
failing tests

### hope you'll like it 😌 

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
the standard tests now return a true error that will stop the CI

# After Submitting
```
$nothing
```
2023-03-25 19:29:08 +01: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
ad4450f9e8 Bump openssl from 0.10.45 to 0.10.48 (#8606) 2023-03-25 09:41:11 +00:00
d8478ca690 Clean up unnecessary macro use (#8607)
Some minor code cleanup.

We've accumulated a few macros over the years that arguably don't need
to be macros. This PR removes 4 macros by either:
1. Inlining the macro
2. Replacing the macro with a local function
3. Replacing the macro with a closure
2023-03-25 20:17:20 +13:00
JT
aab31833a2 Add more pattern types to matcher (#8605)
# Description

Add float, string, and date patterns to matcher.

This could probably use some tests 😅 

# 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-25 17:30:35 +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
744a28b31d type-check default values of list annotations (#8600)
# Description

@fdncred noticed an
[issue](https://github.com/nushell/nushell/pull/8529#issuecomment-1482770636)
with list annotations that while i was trying to find a fix found
another issue.

innitially, this was accepted by the parser
```nu
def err [list: list<int> = ['a' 'b' 'c']] {}
```

but now an error is raised
```nu
Error: nu::parser::assignment_mismatch

  × Default value wrong type
   ╭─[entry #1:1:1]
 1 │ def err [list: list<int> = ['a' 'b' 'c']] {}
   ·                            ──────┬────
   ·                                   ╰── expected default value to be `list<int>`
   ╰────
```

# User-Facing Changes

none

# Tests + Formatting

done
2023-03-25 08:57:18 +13:00
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
dd22647fcd Fix mode tests which use sh to not run on windows (#8601)
See
https://github.com/nushell/nushell/pull/8306#issuecomment-1483111380.
2023-03-24 10:10:15 -07:00
f66136bc86 allow startup-time to be captured when starting nushell with nu -c (#8599)
# Description

This PR fixes a small bug where `$nu.startup-time` wasn't being stored
when nushell was launched with `nu -c`.

# User-Facing 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-24 10:41:33 -05:00
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
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
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
be52f7fb07 tweak logging format (#8588)
# Description

This PR just tweaks the std.nu logging a bit. It looks like this after
this PR. I like the ability to have a parse-able file, which is why
there are pipes, and I like to have a pretty granular time date stamp in
order to get rough performance metrics.
```
nu crates\nu-utils\standard_library\tests.nu
INF|2023-03-23T15:02:00.284|Run test test_asserts test_assert
INF|2023-03-23T15:02:00.372|Run test test_asserts test_assert_equal
INF|2023-03-23T15:02:00.461|Run test test_asserts test_assert_error
INF|2023-03-23T15:02:00.585|Run test test_asserts test_assert_greater
INF|2023-03-23T15:02:00.674|Run test test_asserts test_assert_greater_or_equal
INF|2023-03-23T15:02:00.762|Run test test_asserts test_assert_length
INF|2023-03-23T15:02:00.847|Run test test_asserts test_assert_less
INF|2023-03-23T15:02:00.933|Run test test_asserts test_assert_less_or_equal
INF|2023-03-23T15:02:01.021|Run test test_asserts test_assert_not_equal
INF|2023-03-23T15:02:01.110|Run test test_dirs test_dirs_command
INF|2023-03-23T15:02:01.300|Run test test_logger test_critical
INF|2023-03-23T15:02:01.558|Run test test_logger test_debug
INF|2023-03-23T15:02:01.818|Run test test_logger test_error
INF|2023-03-23T15:02:02.074|Run test test_logger test_info
INF|2023-03-23T15:02:02.331|Run test test_logger test_warning
INF|2023-03-23T15:02:02.573|Run test test_std test_match
INF|2023-03-23T15:02:02.678|Run test test_std test_path_add
```

# 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-23 15:59:49 -05:00
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
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
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
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
35798ce0cc Clarify how register works (#8583)
# Description

This PR changes some help text to try and clarify how `register` works
when using from `nu -c`.


# 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-23 13:02:22 -05:00
47d6a66fbf use reedline main branch (#8580)
# Description

This PR forces nushell to use the reedline main branch instead of the
published crate so that we can test the changes in the latest reedline
main branch.

# 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-23 08:30:33 -05:00
616f065324 make std.nu tests work on mac (#8576)
# Description

This PR is to make test_dirs.nu work better on macos.

closes #8528

# 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-23 07:08:01 -05:00
1e39a1a7a3 fixes the ability to have multiple modifiers on keybindings (#8579)
# Description

This PR fixes a bug that prevented you from having multiple modifiers on
your keybindings.

TODO:
- The docs need to be fixed too
https://www.nushell.sh/book/line_editor.html#keybindings.
(https://github.com/nushell/nushell.github.io/pull/840)
- I think reedline needs to be changed to show this too since it
provides the list of available modifiers.
(https://github.com/nushell/reedline/pull/559)

Now you can do something like this where `shift` and `alt` are combined
with an underscore.
```
  {
    name: fuzzy_history_fzf
    modifier: shift_alt
    keycode: char_r
    mode: [emacs , vi_normal, vi_insert]
    event: {
blah
}
```
Here's the list of available combinations
```rust
        "control" => KeyModifiers::CONTROL,
        "shift" => KeyModifiers::SHIFT,
        "alt" => KeyModifiers::ALT,
        "none" => KeyModifiers::NONE,
        "shift_alt" | "alt_shift" => KeyModifiers::SHIFT | KeyModifiers::ALT,
        "control_shift" | "shift_control" => KeyModifiers::CONTROL | KeyModifiers::SHIFT,
        "control_alt" | "alt_control" => KeyModifiers::CONTROL | KeyModifiers::ALT,
        "control_alt_shift" | "control_shift_alt" => {
            KeyModifiers::CONTROL | KeyModifiers::ALT | KeyModifiers::SHIFT
        }
```

# 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-23 07:07:14 -05:00
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
c48e9cdf5b Disable alias recursion (for real) (#8557) 2023-03-22 23:16:06 +02:00
6a274b860a Cell paths: make optional path members short-circuit (#8554)
This is a follow-up to https://github.com/nushell/nushell/pull/8379 and
https://github.com/nushell/nushell/discussions/8502.

This PR makes it so that the new `?` syntax for marking a path member as
optional short-circuits, as voted on in the
[8502](https://github.com/nushell/nushell/discussions/8502) poll.
Previously, `{ foo: 123 }.bar?.baz` would raise an error:

```
> { foo: 123 }.bar?.baz
  × Data cannot be accessed with a cell path
   ╭─[entry #15:1:1]
 1 │ { foo: 123 }.bar?.baz
   ·                   ─┬─
   ·                    ╰── nothing doesn't support cell paths
   ╰────
   ```

Here's what was happening:

1. The `bar?` path member access returns `nothing` because there is no field named `bar` on the record
2. The `baz` path member access fails when trying to access a `baz` field on that `nothing` value

After this change, `{ foo: 123 }.bar?.baz` returns `nothing`; the failed `bar?` access immediately returns `nothing` and the `baz` access never runs.
2023-03-23 09:54:19 +13: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
0f4a073eaf Remove once_cell dependency from nu-test-support create. (#8568)
I was looking where we could remove the usage of once-cell dependency.
As for now, I only found one place. Not a terrible improvement, but at
least, it removes a dependency nu-test-support crate.

Relies on `Mutex::new` constified in Rust 1.63.0
2023-03-22 19:36:52 +01:00
626410b2aa FEATURE: write better errors for error make and complete the doc (#8511)
# Description
this PR
- refactors `ErrorMake::run` to avoid duplicate branches depending on
the value of `--unspanned`
- completes the examples
1. show a really simple `error make` call, without any command
definition
  2. show a complete error format with all possible fields
3. the command definition but with indentation and slightly better
description
- adds results to the first two examples
- gives meaningful error messages for all known "bad" error formats,
using the span of the error format or the span of `$format.label` to
better explain why the format is bad

# User-Facing Changes
users have now the following help
```bash
Examples:
  Create a simple custom error
  > error make {msg: "my custom error message"}

  Create a more complex custom error
  > error make {
        msg: "my custom error message"
        label: {
            text: "my custom label text"  # not mandatory unless $.label exists
            start: 123  # not mandatory unless $.label.end is set
            end: 456  # not mandatory unless $.label.start is set
        }
    }

  Create a custom error for a custom command that shows the span of the argument
  > def foo [x] {
        let span = (metadata $x).span;
        error make {
            msg: "this is fishy"
            label: {
                text: "fish right here"
                start: $span.start
                end: $span.end
            }
        }
    }
```
and the following error messages when the error format is bad
https://asciinema.org/a/568107 🥳

# Tests + Formatting
- 🟢 `cargo fmt --all`
- 🟢 `cargo clippy --workspace -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect`
- 🔴 `cargo test --workspace`
=> the tests do not pass but they do not pass on latest `main` either =>
i should `cargo clean`, but that's an expensive operation on my
machine...

# After Submitting
the documentation would have to be regenerated over on the website
2023-03-22 08:06:47 -05:00
a193b85123 Bump alphanumeric-sort from 1.4.4 to 1.5.0 (#8532) 2023-03-22 13:02:45 +00:00
0f40c44ed2 Bump windows from 0.44.0 to 0.46.0 (#8535) 2023-03-22 13:02:03 +00:00
cd6f86052d better error message if plugin name doesn't starts with nu_plugin_ (#8562)
# Description

Fixes: #8548 

# User-Facing Changes
```
❯ register target/debug/formats
Error:
  × Register plugin failed
   ╭─[entry #1:1:1]
 1 │ register target/debug/formats
   ·          ──────────┬─────────
   ·                    ╰── plugin name must starts with nu_plugin_
   ╰────

```
# 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-22 07:02:28 -05:00
b9858ea8f8 fix: set repl_buffer_state to the REPL buffer after the `pre_execut… (#8560)
…ion` hook


# Description

Previously when a `executehostcommand` shortcut calls `commandline`, to
get the current command line, it's incorrectly set to the value of
`executehostcommand` `cmd`.

This fixes the regression (due to #8207), so it's correctly set to
what's in the REPL buffer.

# User-Facing 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-22 06:43:25 -05:00
cb1eefd24a FIX: expand all the base_paths in std::test_dirs (#8552)
Related to #8525.

# Description

this should close #8528.

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
```
$nothing
```

# After Submitting
```
$nothing
```
2023-03-22 09:50:01 +01:00
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
b01cbf82c3 Fix nu build script since for loops are stateful now (#8559)
Need to get back to the src top directory after each `cd`.


# 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-22 17:13:07 +13:00
e89c796b41 fix: bytes length example description typo (#8550)
this pr fixes a typo
2023-03-21 11:41:37 -05:00
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
77d33766f1 std lib: extend test runner capabilities (#8499)
I am implementing a nu plugin, and want to unit test that it works well.

# Basic usage (unchanged)


![image](https://user-images.githubusercontent.com/282320/225895139-f1ea0088-22e1-4778-b27e-c1868af48753.png)

# Select the folder to run tests within (subfolders included)


![image](https://user-images.githubusercontent.com/282320/225894283-4c6ac739-afde-44ef-bf7e-362d5118e83f.png)

# Select module to run tests within


![image](https://user-images.githubusercontent.com/282320/225894438-f39690db-955d-4d66-818f-17a179b00c66.png)

# Select test command to run


![image](https://user-images.githubusercontent.com/282320/225894534-edb15b9c-d3ef-4368-9108-2d220ef75dcf.png)

# Complex usage


![image](https://user-images.githubusercontent.com/282320/225894827-03f2e937-3984-4b33-b206-c155c723feac.png)

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-03-20 18:48:48 +01:00
b0be6c3013 Bump quick-xml from 0.27.1 to 0.28.1 (#8533) 2023-03-20 17:46:28 +00:00
93e5d8edc9 Bump actions-rust-lang/setup-rust-toolchain from 1.4.3 to 1.4.4 (#8536) 2023-03-20 17:28:45 +00:00
9c6bfc0be9 Bump rstest from 0.16.0 to 0.17.0 (#8534) 2023-03-20 17:27:29 +00:00
77e73cef66 Ls symlink fix (#8276)
# Description

Fixes #6706.

I took a look at this issue and it seems that the issue is because the
path is canonicalized and thus derives to the target. I've tested it
locally by checking if the path is a symlink and acting accordingly to
not canonicalize it and it seems fine.

In current release if the target is deleted but the symlink remains and
one `ls`'s it, it throws a `directory not found` error. But with the fix
it still shows the symlink (with red background, indicating missing
target).

The change I've applied only triggers when `ls` is done on a symlink, on
all other counts it should basically do the same as before.

# 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

## List existing symlink and target

Current
```
ls a_symlink                                                                                                                                                                                ╭───┬────────┬──────┬──────┬──────────────╮
│ # │  name  │ type │ size │   modified   │
├───┼────────┼──────┼──────┼──────────────┤
│ 0 │ a_file │ file │  0 B │ 20 hours ago │
╰───┴────────┴──────┴──────┴──────────────╯
```
With fix
```
ls a_symlink                                                                                                                                                                                ╭───┬───────────┬─────────┬──────┬──────────────╮
│ # │   name    │  type   │ size │   modified   │
├───┼───────────┼─────────┼──────┼──────────────┤
│ 0 │ a_symlink │ symlink │  6 B │ 20 hours ago │
╰───┴───────────┴─────────┴──────┴──────────────╯
```

## List existing symlink with missing target

Current
```
ls symfile_x                                                                                                                                                                          
Error: nu:🐚:directory_not_found (link)

  × Directory not found
   ╭─[entry #13:1:1]
 1 │ ls symfile_x
   ·    ────┬────
   ·        ╰── directory not found
   ╰────
```

With fix
```
ls symfile_x                                                                                                                                                                          ╭───┬───────────┬─────────┬──────┬─────────────╮
│ # │   name    │  type   │ size │  modified   │
├───┼───────────┼─────────┼──────┼─────────────┤
│ 0 │ symfile_x │ symlink │  6 B │ 2 hours ago │
╰───┴───────────┴─────────┴──────┴─────────────╯
```
2023-03-20 11:04:47 -05:00
7d963776a0 stdlib: Implement common assert commands (#8515)
Implement common assert commands with tests.
Fixes #8419.

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-03-20 08:57:28 -05:00
JT
ecc153cbef Fix command missing hook default config (#8540)
# Description

Unbreak unit tests by updating default config for the new hook that
landed after the syntax change but didn't get its tests re-run.

# 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-20 11:18:30 +01:00
d1309a36b2 standard library: fix the readme (#8526)
# Description
as we now want to put all the library in `std.nu` alone, this PR removes
the mentions to "creating a separate submodule from `std.nu`" from the
`README` of the standard library and adds a few clarifications about the
structure of the library.

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
```
$nothing
```

# After Submitting
```
$nothing
```
2023-03-20 17:05:49 +13:00
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
e36a2947b9 Add CONTRIBUTING section on PRs and git (#8521)
# Description

I describe the status quo (e.g. squashing) which came up as a FAQ.
Further more I add some opinionated best practices.

Feel free to correct me if I am overzealous or imprecise. As it is
already quite long I don't want to expand the text if possible.

# Developer-Facing Changes

Added devdocs to have more guidelines/FAQs addressed
2023-03-19 20:11:20 +01:00
64f50a179e remove unused imports: Deserialize, Serialize compiler warning for nu-protocol/src/example.rs (#8514)
when running the tests inside nu-protocol we were getting a compiler
warning...
this PR removes the compiler warning from nu-protocol.
by adding
```rust
#[allow(unused_imports)]
```
2023-03-18 11:45:12 -07:00
f9cf1d943c standard library: use the standard assert and fix test output (#8509)
# Description
## in the `test_dirs` test module
- use the `std assert` function in the `test_dirs` module instead of
`myassert`
- refactor the "test cleaning" in the `clean` command
- allows to clean the tests and then throw a real error in the `catch`
block in case there is an error
- the test still "try"s to `clean` the test directory after the `catch`,
like in a "finally" block
- parse the `catch` error and `error make` a proper one instead of
`debug`ging it => because the `catch` will be triggered as soon as one
error occurs, there will always only be a single error in the tests, so
this does not change the behaviour of failing `dirs` tests!

> **Note**
> i'm not particularly happy with the parsing stage in the `catch`
block.
> however that's the simplest i found to both keep the `try` / `catch`
construct that allows to clean the test directory and have a proper
error at the same time!

## in the global `tests` module
- use `print` instead of `echo` to make sure the log statements show up
during the tests

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
```bash
nu crates/nu-utils/standard_library/tests.nu
```
passes but now with
- proper log statements
- proper error when a `dirs` error occurs => try with `sd 'assert \(1'
"assert (10" crates/nu-utils/standard_library/test_dirs.nu` 😉

# After Submitting
```
$nothing
```
2023-03-18 09:23:41 -05:00
10a42de64f standard library: add log commands (#8448)
# Description

```nushell
log critical "this is a critical message"
log error "this is an error message"
log warning "this is a warning message"
log info "this is an info message"
log debug "this is a debug message"
```


![image](https://user-images.githubusercontent.com/282320/225071852-1ddf0e87-d12b-452d-9598-5122df7123ab.png)

# Tests + Formatting

Tests are written. To run automatically, #8443 needs to be merged before
or after this PR.

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-03-18 08:19:54 -05:00
c66bd5e809 FEATURE: add a pretty output to toolkit check pr (#8416)
when i write a PR, i run the tests and i like to have a pretty output to
make extra clear which one of the tests did run, which one did not, etc,
etc...

this always end up a variation of the template
> - `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

but with emojis and without the descriptions

> - 🟢 `cargo fmt --all`
> - 🔴 `cargo clippy --workspace -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect`
> - 🟡 `cargo test --workspace`
>
> and a  (``) when i did not have the time
or the resources to run the check stage

in this PR, i came up with a way to do that automatically with the
`toolkit` introduced in #8152 😋

# Description
this PR
- adds `toolkit::pretty-print-command` to print the command names being
run with backticks and some colors
- adds `toolkit::report` to return a "report" of the PR check stages =>
see `help toolkit check pr`
- adds the `--pretty` option to `toolkit check pr` to return a
list-with-emojis version of the check report, i.e. a *GitHub*-friendly
list to drop in place in the "Tests + Formatting" section
- adds a clear mention to `toolkit check pr --pretty` in the PR template
to make it easily visible to anyone

hope you'll like it, that's not a huge deal but that's my attempt to
encourage developers to show that they run the tests, what stages did
pass and which one did not 😌 👋

# User-Facing Changes
the developer can now use `toolkit check pr --pretty` to have a
ready-to-use output for *GitHub*

# Tests + Formatting
```
$nothing
```

# After Submitting
```
$nothing
```
2023-03-18 07:58:21 -05:00
3f224db990 Make assert eq, assert ne consistent with ==, != operators (#8473)
fixes #8418

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-03-18 08:59:27 +13:00
491a9c019c Revert "Hide 7925" (#8500)
Revert nushell/nushell#8359
Turn `[empty list]` on by default again
2023-03-18 08:58:13 +13:00
77e9f8d7df Short redirection syntax (#8503)
This one's pretty clear from the diff! It's more of a language design
discussion.
2023-03-18 08:57:37 +13:00
14bf0b000e standard library: fix the tests for the new closure parsing of 0.77.2 (#8504)
# Description
as closures now need to have explicit parameters, this PR adds the empty
`||` to the two closure of the `std match` test.

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
```
nu crates/nu-utils/standard_library/tests.nu
```
does not give the following anymore
```
Error: nu::parser::closure_missing_pipe

  × Missing || inside closure
    ╭─[/home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/test_std.nu:29:1]
 29 │     let branches = {
 30 │         1: { -1 }
    ·            ───┬──
    ·               ╰── Parsing as a closure, but || is missing
 31 │         2: { -2 }
    ╰────
  help: Try add || to the beginning of closure

Error: nu:🐚:only_supports_this_input_type

  × Input type not supported.
    ╭─[/home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/tests.nu:7:1]
  7 │             nu -c $'use ($test_file) *; $nu.scope.commands | to nuon'
  8 │             | from nuon
    ·               ────┬────
    ·                   ╰── input type: nothing
  9 │             | where module_name == $module_name
    ·               ──┬──
    ·                 ╰── only list, binary, raw data or range input data is supported
 10 │             | where ($it.name | str starts-with "test_")
    ╰────
```

# After Submitting
```
$nothing
```
2023-03-18 08:52:08 +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
bb8949f2b2 REFACTOR: put all the standard library in std.nu (#8489)
> **Warning**
> this PR is the result of a demand from the core team, to have the
simplest structure for the standard library, at least for now 👍

# Description
this PR mainly
- moved the `dirs.nu` module to the end of `std.nu`
- fixed the imports in `test_dirs.nu`

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
with the new runner from #8443, we get as expected 👌 
```
>_ nu crates/nu-utils/standard_library/tests.nu
INFO  Run tests in test_dirs
DEBUG Run test test_dirs/test_dirs_command
INFO  Run tests in test_std
DEBUG Run test test_std/test_assert
DEBUG Run test test_std/test_match
DEBUG Run test test_std/test_path_add
```

# After Submitting
```
$nothing
```
2023-03-17 12:30:35 -05:00
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
eb2e2e6370 make else if generate helpful error when condition have an issue (#8274)
# Description

Fixes: #7575

# User-Facing Changes

Previously:
```
if❯ if false { "aaa" } else if $a { 'a' }
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[entry #10:1:1]
 1 │ if false { "aaa" } else if $a { 'a' }
   ·                         ─┬
   ·                          ╰── expected block, closure or record
   ╰────

```

After:
```
❯ if false { "aaa" } else if $a { 'a' }
Error: nu::parser::variable_not_found

  × Variable not found.
   ╭─[entry #1:1:1]
 1 │ if false { "aaa" } else if $a { 'a' }
   ·                            ─┬
   ·                             ╰── variable not found
   ╰────

```


# 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:37:59 -05:00
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
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
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
JT
1552eb921a parser: Add cell path literal syntax (#8493)
# Description

This adds a new cell path literal syntax for use in any value position,
not just in a context where we expect a cell path.

This can be used to assign to a variable and then later use that
variable as a cell path.

Example:
```
> let cell_path = $.a.b
> {a: {b: 3}} | get $cell_path
3
```
# User-Facing Changes

This adds the syntax `$.a.b` to universally mean the cell path `a.b`,
even in a context that doesn't expect a cell path.

# 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 15:19:41 +13:00
JT
0ac3f7a1c8 parser: Fix panic that happens when you type a single { (#8492)
# Description

Fix the recent parser panic with a single `{`

Introduced by https://github.com/nushell/nushell/pull/8470

# 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 15:19:23 +13:00
JT
bddb63ccb5 Fix CI tests that landed after no-implicit-echo (#8491)
# Description

Turning off implicit echo got tested before some of these changes, so
bring a few tests in-line with that functionality.

# 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 13:43:13 +13:00
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
19beafa865 Disable pipeline echo (#8292)
# Description

Change behavior of block evaluation to not print result of intermediate
commands.
Previously result of every but last pipeline in a block was printed to
stdout, and last one was returned

![image](https://user-images.githubusercontent.com/17511668/222550110-3f62fbed-432c-4b46-b9b1-4cb45a1f893e.png)
With this change results of intermediate pipelines are discarded after
they finish and the last one is returned as before:

![image](https://user-images.githubusercontent.com/17511668/222550346-f1e74f80-f6b6-4aa3-98d6-888ea4cb4915.png)
Now one should use `print` explicitly to print something to stdout

![image](https://user-images.githubusercontent.com/17511668/222923955-fda0d77b-41b4-4f91-a80f-12b0a1880c05.png)

**Note, that this behavior is not limited to functions!** The scope of
this change are all blocks. All of the below are executed as blocks and
thus exibited this behavior in the same way:

![image](https://user-images.githubusercontent.com/17511668/222924062-342c15de-4273-4bf5-8b39-fe6e3aa96076.png)

With this change outputs for all types of blocks are cleaned:

![image](https://user-images.githubusercontent.com/17511668/222924118-7d51c27e-04bb-43e5-8efe-38b484683bfe.png)


# User-Facing Changes

All types of blocks (function bodies, closures, `if` branches, `for` and
`loop` bodies e.t.c.) no longer print result of intermediate pipelines.

# 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 11:53:46 +13:00
8543b0789d Additional flags for commands from csv and from tsv (#8398)
# Description

Resolves issue #8370

Adds the following flags to commands `from csv` and `from tsv`:
- `--flexible`: allow the number of fields in records to be variable
- `-c --comment`: a comment character to ignore lines starting with it
- `-q --quote`: a quote character to ignore separators in strings,
defaults to '\"'
- `-e --escape`: an escape character for strings containing the quote
character

Internally, the `Value` struct has an additional helper function
`as_char` which converts it to a single `char`

# User-Facing Changes

The single quoted string `'\t'` can no longer be used as a parameter for
the flag `--separator '\t'` as it is interpreted as a two-character
string. One needs to use from now on the flag with a double quoted
string like so: `-s "\t"` which correctly interprets the string as a
single `char`.
2023-03-16 17:49:46 -05:00
bdaa01165e enable error reporting from enable_vt_processing (#8373)
# Description

This PR tweaks the enable_vt_processing() function with more verbose
error handling. This is related to #8344.

# 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

# 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-16 17:48:21 -05:00
b2a557d4ed fix: fix commandline when called with no arguments (#8207)
# Description

This fixes the `commandline` command when it's run with no arguments, so
it outputs the command being run. New line characters are included.

This allows for:

- [A way to get current command inside pre_execution hook · Issue #6264
· nushell/nushell](https://github.com/nushell/nushell/issues/6264)
- The possibility of *Atuin* to work work *Nushell*. *Atuin* hooks need
to know the current repl input before it is run.

# User-Facing 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

# 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-16 17:45:35 -05:00
JT
0903a891e4 Fix parse of def with paren params (#8490)
# Description

This adds back support for parens around params, eg `def foo (x: int) {
... }`

# User-Facing Changes

returns to the original support before the recent parser refactor

# 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 09:08:41 +13:00
1b2916988e Add -i flag back to get and select (#8488)
https://github.com/nushell/nushell/pull/8379 removed the `-i` flag from
`get` and `select` because the new `?` functionality covers most of the
same use cases. However, https://github.com/nushell/nushell/issues/8480
made me realize that `-i` is still useful when dealing with cell paths
in variables.

This PR re-adds the `-i` flag to `get` and `select`. It works by just
marking every member in the cell path as optional, which will behave
_slightly_ differently than `-i` used to (previously it would suppress
any errors, even type errors) but IMO that's OK.
2023-03-16 11:50:04 -07:00
d74a260883 stdlib: add test discovery, extract test files (#8443)
# Description

Was original asked here:
https://github.com/nushell/nushell/pull/8405#issuecomment-1465062652
Make it easier to extend standard library with submodules.
(For a new submodule called `xx.nu` the tests can be written in
`test_xx.nu`).
Test discovery is implemented.

# User-Facing Changes

There are no user-facing changes.

# Tests + Formatting

Tests are updated.
There is no `nufmt` now.

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-03-16 13:23:29 -05:00
31d9c0889c Revert "Throw out error if external command in subexpression is failed to run (#8204)" (#8475)
This reverts commit dec0a2517f.

It breaks programs like `fzf`

# Description

Fixes: #8472 
Fixes:  #8313
Reopen: #7690 

# 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 07:07:32 +13:00
JT
222c0f11c3 Escape will now escape paths with '=' in them (#8485)
# Description

Fixes the issue where there is no way to escape `FOO=BAR` in a way that
treats it as a file path/executable name. Previously `^FOO=BAR` would be
handled as an environment shorthand. Now, environment shorthands are not
allowed to start with `^`. To create an environment shorthand value that
uses `^` as the first character of the environment variable name, use
quotes, eg `"^FOO"=BAR`

# User-Facing Changes

This should enable `=` being in paths and external command names in
command position.

# 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 07:05:08 +13:00
106ca65c58 Added fix for bug #8278 to read tag values from YAML files (#8354)
# Description

This PR adds a fix for reading tag values from YAML file.

A tag in YAML file is denoted by using the exclamation point ("!")
symbol.

For example - Key: !Value

Additional passing test has also been added supporting the bug fix - 
- `test_convert_yaml_value_to_nu_value_for_tagged_values`

The fix passes all the below required tests suites locally - 

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

---------

Co-authored-by: Nitin Londhe <nitin.londhe@genmills.com>
2023-03-16 09:50:30 -05:00
4c97b3dd28 Exit successfully from nu --help for compatibility with halp (#8478)
https://github.com/orhun/halp finds the correct help command
by checking if `cmd --help` succeeds.

All standard utilities I've tried exit successfully on `--help`,
but not nushell.
2023-03-16 13:03:29 +01:00
e672689a76 Fix docs building error caused by missing end tag (#8477) 2023-03-16 19:41:19 +08:00
2579a827fc Bump mockito from 0.32.5 to 1.0.0 (#8426)
Bumps [mockito](https://github.com/lipanski/mockito) from 0.32.5 to
1.0.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/lipanski/mockito/releases">mockito's
releases</a>.</em></p>
<blockquote>
<h2>1.0.0</h2>
<p>🎈 7 years and 63 releases later, it's finally time for the
1.0 🎈</p>
<h2>Changes</h2>
<ul>
<li><strong>[Breaking]</strong> The legacy interface was removed in this
version</li>
<li><strong>[Breaking]</strong> <code>Mock::with_body_from_fn</code> was
renamed to <code>Mock::with_chunked_body</code> - the former is still
supported with a deprecation warning</li>
<li>Mocks are only cleared when the server is dropped, not when the mock
is dropped - this means you <strong>don't have to assign mocks to
variables any more</strong> (unless you want to call other methods on
them)</li>
<li>Introduced the <code>Mock::remove</code> and
<code>Mock::remove_async</code> methods to remove mocks on demand</li>
</ul>
<h2>Major changes since 0.31</h2>
<ul>
<li>Tests can now run in parallel</li>
<li>Support for HTTP2</li>
<li>An async interface for all actions (though the sync interface is
also available)</li>
<li>Mock multiple server/hosts at the same time</li>
</ul>
<p>For a list of all the changes please check the <a
href="https://github.com/lipanski/mockito/releases">release log</a>.</p>
<h2>Migrating to the new API</h2>
<p>Legacy API:</p>
<pre lang="rust"><code>let m1 = mockito::mock(&quot;GET&quot;,
&quot;/hello&quot;).with_body(&quot;hello&quot;).create();
let m2 = mockito::mock(&quot;GET&quot;,
&quot;/bye&quot;).with_body(&quot;bye&quot;).create();
<p>// Use one of these to configure your client
let host = mockito:server_address();
let url = mockito::server_url();
</code></pre></p>
<p>New API:</p>
<pre lang="rust"><code>let mut server = mockito::Server::new();
server.mock(&quot;GET&quot;,
&quot;/hello&quot;).with_body(&quot;hello&quot;).create();
server.mock(&quot;GET&quot;,
&quot;/bye&quot;).with_body(&quot;bye&quot;).create();
<p>// Use one of these to configure your client
let host = server.host_with_port();
let url = server.url();
</code></pre></p>
<blockquote>
<p>If you can't migrate to the new API in one go, consider using version
0.32.5, which supports both the legacy API as well as the new API.</p>
</blockquote>
<h2>Migrating to the async API</h2>
<p>In order to write async tests, you'll need to use the
<code>_async</code> methods:</p>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="9a07811955"><code>9a07811</code></a>
Bump to 1.0.0</li>
<li><a
href="000c435f0e"><code>000c435</code></a>
Merge pull request <a
href="https://redirect.github.com/lipanski/mockito/issues/165">#165</a>
from lipanski/one-zero</li>
<li><a
href="68c56290a1"><code>68c5629</code></a>
Remove mocks when the server is dropped, not when the mock is
dropped</li>
<li><a
href="ac9042d022"><code>ac9042d</code></a>
Add the Windows line-ending fix to the test runner</li>
<li><a
href="0ce9788e00"><code>0ce9788</code></a>
Disable color tests on Windows</li>
<li><a
href="ad2ebcbaab"><code>ad2ebcb</code></a>
Fine-tuning the Windows test runner</li>
<li><a
href="abb9e91d71"><code>abb9e91</code></a>
Run Windows tests on Github Actions</li>
<li><a
href="5a7c96eaec"><code>5a7c96e</code></a>
Rename Mock::with_body_from_fn to Mock::with_chunked_body</li>
<li><a
href="ed338faedf"><code>ed338fa</code></a>
Uncomment threads tests</li>
<li><a
href="6e2064de95"><code>6e2064d</code></a>
Drop legacy interface</li>
<li>Additional commits viewable in <a
href="https://github.com/lipanski/mockito/compare/0.32.5...1.0.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=mockito&package-manager=cargo&previous-version=0.32.5&new-version=1.0.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-16 11:40:49 +01:00
8c487edf62 docs: Use capital letters for CSV and JSON acronyms (#8459)
Capital letters matter! 😉 
<img width="927" alt="Screenshot 2023-03-15 at 06 54 22"
src="https://user-images.githubusercontent.com/3862051/225219635-cfde7c3b-66c1-40a5-87f5-0d1a5d41955e.png">

See https://github.com/nushell/nushell.github.io/pull/827/files that was
created before this one.
2023-03-15 21:52:13 -07:00
0b97f52a8b make better usage of error value in catch block (#8460)
# Description

Fixes: #8402  #8391

The cause of these issue if when we want to evaluate a expression with
`Value::Error`, nushell show error immediately. To fix the issue, we can
wrap the `Value::Error` into a `Value::Record`. So user can see the
message he want.

# User-Facing Changes

Before
```
❯ try { 1 / 0 } catch {|e| echo $"error is ($e)"}
Error: nu:🐚:division_by_zero

  × Division by zero.
   ╭─[entry #2:1:1]
 1 │ try { 1 / 0 } catch {|e| echo $"error is ($e)"}
   ·         ┬
   ·         ╰── division by zero
   ╰────
```

After
```
❯ try { 1 / 0 } catch {|e| echo $"error is ($e)"}
error is {msg: Division by zero., debug: DivisionByZero { span: Span { start: 43104, end: 43105 } }, raw: DivisionByZero { sp
an: Span { start: 43104, end: 43105 } }}
```

As we can see, error becomes a record with `msg`, `debug`, `raw`
columns.
1. msg column is a user friendly message.
2. debug column is more about `Value::Error` information as a string.
3. raw column is a `Value::Error` itself, if user want to re-raise the
error, just use `$e | get raw`

# 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-15 20:56:18 -07:00
21b84a6d65 Optional members in cell paths: Attempt 2 (#8379)
This is a follow up from https://github.com/nushell/nushell/pull/7540.
Please provide feedback if you have the time!

## Summary

This PR lets you use `?` to indicate that a member in a cell path is
optional and Nushell should return `null` if that member cannot be
accessed.

Unlike the previous PR, `?` is now a _postfix_ modifier for cell path
members. A cell path of `.foo?.bar` means that `foo` is optional and
`bar` is not.

`?` does _not_ suppress all errors; it is intended to help in situations
where data has "holes", i.e. the data types are correct but something is
missing. Type mismatches (like trying to do a string path access on a
date) will still fail.

### Record Examples

```bash

{ foo: 123 }.foo # returns 123

{ foo: 123 }.bar # errors
{ foo: 123 }.bar? # returns null

{ foo: 123 } | get bar # errors
{ foo: 123 } | get bar? # returns null

{ foo: 123 }.bar.baz # errors
{ foo: 123 }.bar?.baz # errors because `baz` is not present on the result from `bar?`
{ foo: 123 }.bar.baz? # errors
{ foo: 123 }.bar?.baz? # returns null
```

### List Examples
```
〉[{foo: 1} {foo: 2} {}].foo
Error: nu:🐚:column_not_found

  × Cannot find column
   ╭─[entry #30:1:1]
 1 │ [{foo: 1} {foo: 2} {}].foo
   ·                    ─┬  ─┬─
   ·                     │   ╰── cannot find column 'foo'
   ·                     ╰── value originates here
   ╰────
〉[{foo: 1} {foo: 2} {}].foo?
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │   │
╰───┴───╯
〉[{foo: 1} {foo: 2} {}].foo?.2 | describe
nothing

〉[a b c].4? | describe
nothing

〉[{foo: 1} {foo: 2} {}] | where foo? == 1
╭───┬─────╮
│ # │ foo │
├───┼─────┤
│ 0 │   1 │
╰───┴─────╯
```

# Breaking changes

1. Column names with `?` in them now need to be quoted.
2. The `-i`/`--ignore-errors` flag has been removed from `get` and
`select`
1. After this PR, most `get` error handling can be done with `?` and/or
`try`/`catch`.
4. Cell path accesses like this no longer work without a `?`:
```bash
〉[{a:1 b:2} {a:3}].b.0
2
```
We had some clever code that was able to recognize that since we only
want row `0`, it's OK if other rows are missing column `b`. I removed
that because it's tricky to maintain, and now that query needs to be
written like:


```bash
〉[{a:1 b:2} {a:3}].b?.0
2
```

I think the regression is acceptable for now. I plan to do more work in
the future to enable streaming of cell path accesses, and when that
happens I'll be able to make `.b.0` work again.
2023-03-15 20:50:58 -07:00
d3be5ec750 DOC: make the README of the standard library clearer (#8465)
Should close #8444.

# Description
as asked by @presidento, i've used a generic command to run the tests.

i've also transformed the "a concrete example" sections into quote
blocks to make them stand out less.
not sure about that one, please tell me what you think 😋 

i think a small example is always helpfull, maybe some work has to be
done to make it better 💪

# User-Facing Changes
hopefully a slightly clearer README for the standard library

# Tests + Formatting
```
$nothing
```

# After Submitting
```
$nothing
```
2023-03-15 20:13:09 -07:00
4b16406050 Add proptest regression (#8396)
# Description

I found this when I was checking out my commits. It must have happened
during one of the random test failures that I've been getting quite
often recently.

# User-Facing Changes

None?

# 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-15 20:08:02 -07:00
JT
b0ce602e4b Start grouping parsing of values better (#8470)
# Description

This starts working on refactoring the parser to no longer use
SyntaxShape when making parsing decisions about values. This PR covers
grouping a few of the steps in `parse_value` to key off the first
character for what group of parsing steps it should use.

# User-Facing Changes

Hopefully none.

# 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-16 16:06:43 +13:00
aa876ce24f Bump lru from 0.9.0 to 0.10.0 (#8425) 2023-03-15 18:47:40 +00:00
71fdf717a8 Bump open from 3.4.0 to 4.0.0 (#8427) 2023-03-15 18:41:39 +00:00
4de0347fdc Added help externs command (#8403)
# Description

`help externs` - command, which list external commands

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

# User-Facing Changes

```nu
$ help externs
╭───┬──────────────┬─────────────┬───────────────────────────────────────────────────╮
│ # │     name     │ module_name │                       usage                       │
├───┼──────────────┼─────────────┼───────────────────────────────────────────────────┤
│ 0 │ git push     │ completions │ Push changes                                      │
│   │              │             │                                                   │
│ 1 │ git fetch    │ completions │ Download objects and refs from another repository │
│   │              │             │                                                   │
│ 2 │ git checkout │ completions │ Check out git branches and files                  │
│   │              │             │                                                   │
╰───┴──────────────┴─────────────┴───────────────────────────────────────────────────╯
```

# 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-15 18:40:27 +01:00
f34ac9be62 Bump sqlparser from 0.30.0 to 0.32.0 (#8428)
Bumps [sqlparser](https://github.com/sqlparser-rs/sqlparser-rs) from
0.30.0 to 0.32.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/sqlparser-rs/sqlparser-rs/blob/main/CHANGELOG.md">sqlparser's
changelog</a>.</em></p>
<blockquote>
<h2>[0.32.0] 2023-03-6</h2>
<h3>Added</h3>
<ul>
<li>Support ClickHouse <code>CREATE TABLE</code> with <code>ORDER
BY</code> (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/824">#824</a>)
- Thanks <a
href="https://github.com/ankrgyl"><code>@​ankrgyl</code></a></li>
<li>Support PostgreSQL exponentiation <code>^</code> operator (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/813">#813</a>)
- Thanks <a
href="https://github.com/michael-2956"><code>@​michael-2956</code></a></li>
<li>Support <code>BIGNUMERIC</code> type in BigQuery (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/811">#811</a>)
- Thanks <a
href="https://github.com/togami2864"><code>@​togami2864</code></a></li>
<li>Support for optional trailing commas (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/810">#810</a>)
- Thanks <a
href="https://github.com/ankrgyl"><code>@​ankrgyl</code></a></li>
</ul>
<h3>Fixed</h3>
<ul>
<li>Fix table alias parsing regression by backing out redshift column
definition list (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/827">#827</a>)
- Thanks <a
href="https://github.com/alamb"><code>@​alamb</code></a></li>
<li>Fix typo in <code>ReplaceSelectElement</code>
<code>colum_name</code> --&gt; <code>column_name</code> (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/822">#822</a>)
- Thanks <a
href="https://github.com/togami2864"><code>@​togami2864</code></a></li>
</ul>
<h2>[0.31.0] 2023-03-1</h2>
<h3>Added</h3>
<ul>
<li>Support raw string literals for BigQuery dialect (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/812">#812</a>)
- Thanks <a
href="https://github.com/togami2864"><code>@​togami2864</code></a></li>
<li>Support <code>SELECT * REPLACE &lt;Expr&gt; AS
&lt;Identifier&gt;</code> in BigQuery dialect (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/798">#798</a>)
- Thanks <a
href="https://github.com/togami2864"><code>@​togami2864</code></a></li>
<li>Support byte string literals for BigQuery dialect (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/802">#802</a>)
- Thanks <a
href="https://github.com/togami2864"><code>@​togami2864</code></a></li>
<li>Support columns definition list for system information functions in
RedShift dialect (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/769">#769</a>)
- Thanks <a
href="https://github.com/mskrzypkows"><code>@​mskrzypkows</code></a></li>
<li>Support <code>TRANSIENT</code> keyword in Snowflake dialect (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/807">#807</a>)
- Thanks <a
href="https://github.com/mobuchowski"><code>@​mobuchowski</code></a></li>
<li>Support <code>JSON</code> keyword (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/799">#799</a>)
- Thanks <a
href="https://github.com/togami2864"><code>@​togami2864</code></a></li>
<li>Support MySQL Character Set Introducers (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/788">#788</a>)
- Thanks <a
href="https://github.com/mskrzypkows"><code>@​mskrzypkows</code></a></li>
</ul>
<h3>Fixed</h3>
<ul>
<li>Fix clippy error in ci (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/803">#803</a>)
- Thanks <a
href="https://github.com/togami2864"><code>@​togami2864</code></a></li>
<li>Handle offset in map key in BigQuery dialect (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/797">#797</a>)
- Thanks <a
href="https://github.com/Ziinc"><code>@​Ziinc</code></a></li>
<li>Fix a typo (precendence -&gt; precedence) (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/794">#794</a>)
- Thanks <a
href="https://github.com/SARDONYX-sard"><code>@​SARDONYX-sard</code></a></li>
<li>use post_* visitors for mutable visits (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/789">#789</a>)
- Thanks <a
href="https://github.com/lovasoa"><code>@​lovasoa</code></a></li>
</ul>
<h3>Changed</h3>
<ul>
<li>Add another known user (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/787">#787</a>)
- Thanks <a
href="https://github.com/joocer"><code>@​joocer</code></a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="5f815c2b08"><code>5f815c2</code></a>
(cargo-release) version 0.32.0</li>
<li><a
href="1d358592ab"><code>1d35859</code></a>
Changelog for 0.32.0 (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/830">#830</a>)</li>
<li><a
href="7f4c9132d7"><code>7f4c913</code></a>
Fix table alias parsing regression in 0.31.0 by backing out redshift
column d...</li>
<li><a
href="d69b875367"><code>d69b875</code></a>
ClickHouse CREATE TABLE Fixes: add ORDER BY and fix clause ordering (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/824">#824</a>)</li>
<li><a
href="1cf913e717"><code>1cf913e</code></a>
feat: Support PostgreSQL exponentiation. (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/813">#813</a>)</li>
<li><a
href="fbbf1a4e84"><code>fbbf1a4</code></a>
feat: support <code>BIGNUMERIC</code> of bigquery (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/811">#811</a>)</li>
<li><a
href="b45306819c"><code>b453068</code></a>
Add support for trailing commas (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/810">#810</a>)</li>
<li><a
href="2285bb44ba"><code>2285bb4</code></a>
chore: fix typo (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/822">#822</a>)</li>
<li><a
href="b838415276"><code>b838415</code></a>
(cargo-release) version 0.31.0</li>
<li><a
href="66ec634c67"><code>66ec634</code></a>
Update CHANGELOG for version 0.31 (<a
href="https://redirect.github.com/sqlparser-rs/sqlparser-rs/issues/820">#820</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/sqlparser-rs/sqlparser-rs/compare/v0.30.0...v0.32.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=sqlparser&package-manager=cargo&previous-version=0.30.0&new-version=0.32.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)

---

**Note:** Dependabot was ignoring updates to this dependency, but since
you've updated it yourself we've started tracking it for you again. 🤖

<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-15 18:33:09 +01:00
12652f897a std.nu: Rewrite assert method (#8405)
It is a common pattern to add message to assert.
Also the error message was not so helpful. (See the difference in the
documentation)

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-03-15 18:19:38 +01:00
24ee381fea Fix xml docs (#8462)
See https://github.com/nushell/nushell.github.io/pull/828
2023-03-15 07:21:48 -05:00
494a07f6f3 docs: Add missing space in Filesystem/start's usage (#8458)
In order to fix the selected text, below, in the documentation: 
<img width="1252" alt="Screenshot 2023-03-15 at 06 50 25"
src="https://user-images.githubusercontent.com/3862051/225218941-7654803f-7b85-490a-9fb0-3de7d666935b.png">

PS: see https://github.com/nushell/nushell.github.io/pull/826 that was
created before this pull request.
2023-03-15 07:16:41 -05:00
JT
61455b457d Fix warnings and old names (#8457)
# Description

This fixes up some clippy warnings and removes some old names/info from
our unit tests

# User-Facing Changes

Internal changes only

# 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-15 18:54:55 +13:00
57ce6a7c66 Fix ls behaviour when directory is empty (#8439)
Prior to this PR, `ls` would return `nothing` in an empty directory.
After this PR, it returns an empty `List`. This makes the behaviour of
`ls` more consistent and easier to reason about (IMO).

This was prompted by a user noticing that `ls | where size == 0KB and
type == file` breaks when run in an empty directory:

```
  × Input type not supported.
   ╭─[entry #12:1:1]
 1 │ ls | where size == 0KB and type == file
   · ─┬   ──┬──
   ·  │     ╰── only list, binary, raw data or range input data is supported
   ·  ╰── input type: nothing
   ╰────
```

If people agree with this change, let's wait until after the 0.77
release so we have a bit more time to test it.
2023-03-15 18:31:07 +13:00
0bd4d27e8d Modify reject algorithm for identical elements (#8446)
# Description

The correction made here concerns the issue #8431. Indeed, the algorithm
initially proposed to remove elements of a `vector` performed a loop
with `remove` and an incident therefore appeared when several values
were equal because the deletion was done outside the length of the
vector:
```rust
let mut found = false;
for (i, col) in cols.clone().iter().enumerate() {
    if col == col_name {
        cols.remove(i);
        vals.remove(i);
        found = true;
    }
}

```

Then, `[[a, a]; [1, 2]] | reject a: ` gave `thread 'main' panicked at
'removal index (is 1) should be < len (is 1)',
crates/nu-protocol/src/value/mod.rs:1213:54`.

The proposed correction is therefore the implementation of the
`retain_mut` utility dedicated to this functionality.

```rust
let mut found = false;
let mut index = 0;
cols.retain_mut(|col| {
    if col == col_name {
        found = true;
        vals.remove(index);
        false
    } else {
        index += 1;
        true
    }
});
```
2023-03-14 23:26:48 +01:00
1701303279 Bump to 0.77.1 development version (#8453)
# Description

Either to be used in an emergency point release or to indicate
development builds in the `version` command
2023-03-14 23:26:08 +01:00
304 changed files with 9448 additions and 3970 deletions

View File

@ -18,6 +18,7 @@ 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

View File

@ -40,7 +40,7 @@ jobs:
- uses: actions/checkout@v3
- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.4.3
uses: actions-rust-lang/setup-rust-toolchain@v1.4.4
- name: cargo fmt
run: cargo fmt --all -- --check
@ -77,14 +77,14 @@ jobs:
- uses: actions/checkout@v3
- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.4.3
uses: actions-rust-lang/setup-rust-toolchain@v1.4.4
- name: Tests
run: cargo test --workspace --profile ci --exclude nu_plugin_* ${{ matrix.flags }}
python-virtualenv:
std-lib-and-python-virtualenv:
env:
NUSHELL_CARGO_TARGET: ci
NU_LOG_LEVEL: DEBUG
strategy:
fail-fast: true
@ -101,10 +101,22 @@ jobs:
- uses: actions/checkout@v3
- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.4.3
uses: actions-rust-lang/setup-rust-toolchain@v1.4.4
- name: Install Nushell
run: cargo install --locked --path=. --profile ci --no-default-features
# prior to [*standard library: bring the tests into the main CI*](#8525)
# there was a `--profile ci` here in the `cargo install`, as well as
# `NUSHELL_CARGO_TARGET: ci` in the prelude above.
#
# this caused a "stackoverflow" error in the CI on windows,
# see [this failing job](https://github.com/nushell/nushell/actions/runs/4512034615/jobs/7944945590)
#
# the CI profile has been removed in 00b820de9021227d1910a9ea388297ee7aee308e
# as part of #8525.
run: cargo install --path . --locked --no-default-features
- name: Standard library tests
run: nu crates/nu-utils/standard_library/tests.nu
- name: Setup Python
uses: actions/setup-python@v4
@ -148,7 +160,7 @@ jobs:
- uses: actions/checkout@v3
- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.4.3
uses: actions-rust-lang/setup-rust-toolchain@v1.4.4
- name: Clippy
run: cargo clippy --package nu_plugin_* ${{ matrix.flags }} -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect
@ -157,40 +169,40 @@ jobs:
run: cargo test --profile ci --package nu_plugin_*
nu-coverage:
needs: nu-tests
env:
NUSHELL_CARGO_TARGET: ci
# nu-coverage:
# needs: nu-tests
# env:
# NUSHELL_CARGO_TARGET: ci
strategy:
fail-fast: true
matrix:
# disabled mac due to problems with merging coverage and similarity to linux
# disabled windows due to running out of disk space when having too many crates or tests
platform: [ubuntu-20.04] # windows-latest
rust:
- stable
# strategy:
# fail-fast: true
# matrix:
# # disabled mac due to problems with merging coverage and similarity to linux
# # disabled windows due to running out of disk space when having too many crates or tests
# platform: [ubuntu-20.04] # windows-latest
# rust:
# - stable
runs-on: ${{ matrix.platform }}
# runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
# steps:
# - uses: actions/checkout@v3
- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.4.3
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
# - name: Setup Rust toolchain and cache
# uses: actions-rust-lang/setup-rust-toolchain@v1.4.4
# - name: Install cargo-llvm-cov
# uses: taiki-e/install-action@cargo-llvm-cov
- name: Tests
shell: bash
run: |
source <(cargo llvm-cov show-env --export-prefix) # Set the environment variables needed to get coverage.
cargo llvm-cov clean --workspace # Remove artifacts that may affect the coverage results.
cargo build --workspace --profile ci
cargo test --workspace --profile ci
cargo llvm-cov report --profile ci --lcov --output-path lcov.info
# - name: Tests
# shell: bash
# run: |
# source <(cargo llvm-cov show-env --export-prefix) # Set the environment variables needed to get coverage.
# cargo llvm-cov clean --workspace # Remove artifacts that may affect the coverage results.
# cargo build --workspace --profile ci
# cargo test --workspace --profile ci
# cargo llvm-cov report --profile ci --lcov --output-path lcov.info
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
files: lcov.info
# - name: Upload coverage reports to Codecov with GitHub Action
# uses: codecov/codecov-action@v3
# with:
# files: lcov.info

View File

@ -70,7 +70,7 @@ jobs:
echo "targets = ['${{matrix.target}}']" >> rust-toolchain.toml
- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.4.3
uses: actions-rust-lang/setup-rust-toolchain@v1.4.4
- name: Setup Nushell
uses: hustcer/setup-nu@v3

3
.gitignore vendored
View File

@ -22,6 +22,9 @@ debian/nu/
# VSCode's IDE items
.vscode/*
# JetBrains' Fleet IDE
.fleet/*
# Visual Studio Extension SourceGear Rust items
VSWorkspaceSettings.json
unstable_cargo_features.txt

View File

@ -99,3 +99,90 @@ The most comprehensive test suite we have is the `nu-test-support` crate. For te
cargo run --release -- --log-level trace --log-target file
open $"($nu.temp-path)/nu-($nu.pid).log"
```
## Git etiquette
As nushell thrives on its broad base of volunteer contributors and maintainers with different backgrounds we have a few guidelines for how we best utilize git and GitHub for our contributions. We strive to balance three goals with those recommendations:
1. The **volunteer maintainers and contributors** can easily follow the changes you propose, gauge the impact, and come to help you or make a decision.
2. **You as a contributor** can focus most of your time on improving the quality of the nushell project and contributing your expertise to the code or documentation.
3. Making sure we can trace back *why* decisions were made in the past.
This includes discarded approaches. Also we want to quickly identify regressions and fix when something broke.
### How we merge PRs
In general the maintainers **squash** all changes of your PR into a single commit when merging.
This keeps a clean enough linear history, while not forcing you to conform to a too strict style while iterating in your PR or fixing small problems. As an added benefit the commits on the `main` branch are tied to the discussion that happened in the PR through their `#1234` issue number.
> **Note**
> **Pro advice:** In some circumstances, we can agree on rebase-merging a particularly large but connected PR as a series of atomic commits onto the `main` branch to ensure we can more easily revert or bisect particular aspects.
### A good PR makes a change!
As a result of this PR-centric strategy and the general goal that the reviewers should easily understand your change, the **PR title and description matters** a great deal!
Make sure your description is **concise** but contains all relevant information and context.
This means demonstrating what changes, ideally through nushell code or output **examples**.
Furthermore links to technical documentation or instructions for folks that want to play with your change make the review process much easier.
> **Note**
> Try to follow the suggestions in our PR message template to make sure we can quickly focus on the technical merits and impact on the users.
#### A PR should limit itself to a single functional change or related set of same changes.
Mixing different changes in the same PR will make the review process much harder. A PR might get stuck on one aspect while we would actually like to land another change. Furthermore, if we are forced to revert a change, mixing and matching different aspects makes fixing bugs or regressions much harder.
Thus, please try to **separate out unrelated changes**!
**Don't** mix unrelated refactors with a potentially contested change.
Stylistic fixes and housekeeping can be bundled up into singular PRs.
#### Guidelines for the PR title
The PR title should be concise but contain everything for a contributor to know if they should help out in the review of this particular change.
**DON'T**
- `Update file/in/some/deeply/nested/path.rs`
- Why are you making this change?
- `Fix 2134`
- What has to be fixed?
- Hard to follow when not online on GitHub.
- ``Ignore `~` expansion``
- In what context should this change take effect?
- `[feature] refactor the whole parser and also make nushell indentation-sensitive, upgrade to using Cpython. Let me know what you think!`
- Be concise
- Maybe break up into smaller commits or PRs if the title already appears too long?
**DO**
- Mention the nushell feature or command that is affected.
- ``Fix URL parsing in `http get` (issue #1234)``
- You can mention the issue number if other context is there.
- In general, mention all related issues in the description to crosslink (e.g. `Fixes #1234`, `Closes #6789`)
- For internal changes mention the area or symbols affected if it helps to clarify
- ``Factor out `quote_string()` from parser to reuse in `explore` ``
### Review process / Merge conflicts
> **Note**
> Keep in mind that the maintainers are volunteers that need to allocate their attention to several different areas and active PRs. We will try to get back to you as soon as possible.
You can help us to make the review process a smooth experience:
- Testing:
- We generally review in detail after all the tests pass. Let us know if there is a problem you want to discuss to fix a test failure or forces us to accept a breaking change.
- If you fix a bug, it is highly recommended that you add a test that reproduces the original issue/panic in a minimal form.
- In general, added tests help us to understand which assumptions go into a particular addition/change.
- Try to also test corner cases where those assumptions might break. This can be more valuable than simply adding many similar tests.
- Commit history inside a PR during code review:
- Good **atomic commits** can help follow larger changes, but we are not pedantic.
- We don't shame fixup commits while you try to figure out a problem. They can help others see what you tried and what didn't work. (see our [squash policy](#how-we-merge-prs))
- During active review constant **force pushing** just to amend changes can be confusing!
- GitHub's UI presents reviewers with less options to compare diffs
- fetched branches for experimentation become invalid!
- the notification a maintainer receives has a low signal-to-noise ratio
- Git pros *can* use their judgement to rebase/squash to clean up the history *if it aids the understanding* of a larger change during review
- Merge conflicts:
- In general you should take care of resolving merge conflicts.
- Use your judgement whether to `git merge main` or to `git rebase main`
- Choose what simplifies having confidence in the conflict resolution and the review. **Merge commits in your branch are OK** in the squash model.
- Feel free to notify your reviewers or affected PR authors if your change might cause larger conflicts with another change.
- During the rollup of multiple PRs, we may choose to resolve merge conflicts and CI failures ourselves. (Allow maintainers to push to your branch to enable us to do this quickly.)

246
Cargo.lock generated
View File

@ -68,9 +68,9 @@ dependencies = [
[[package]]
name = "alphanumeric-sort"
version = "1.4.4"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77e9c9abb82613923ec78d7a461595d52491ba7240f3c64c0bbe0e6d98e0fce0"
checksum = "5e972aa01d34ded9a7fd0d838a1b6f73e70daf78ff77221c82bd411afa1f3fa9"
[[package]]
name = "android_system_properties"
@ -1739,6 +1739,12 @@ dependencies = [
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
[[package]]
name = "hex"
version = "0.4.3"
@ -1963,6 +1969,18 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "is-terminal"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e"
dependencies = [
"hermit-abi 0.3.1",
"io-lifetimes",
"rustix",
"windows-sys 0.45.0",
]
[[package]]
name = "is_ci"
version = "1.1.1"
@ -2266,9 +2284,9 @@ dependencies = [
[[package]]
name = "lru"
version = "0.9.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71e7d46de488603ffdd5f30afbc64fbba2378214a2c3a2fb83abf3d33126df17"
checksum = "03f1160296536f10c833a82dca22267d5486734230d47bf00bf435885814ba1e"
dependencies = [
"hashbrown 0.13.2",
]
@ -2381,11 +2399,11 @@ dependencies = [
[[package]]
name = "miette"
version = "5.5.0"
version = "5.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4afd9b301defa984bbdbe112b4763e093ed191750a0d914a78c1106b2d0fe703"
checksum = "07749fb52853e739208049fb513287c6f448de9103dfa78b05ae01f2fc5809bb"
dependencies = [
"atty",
"is-terminal",
"miette-derive",
"once_cell",
"owo-colors",
@ -2400,9 +2418,9 @@ dependencies = [
[[package]]
name = "miette-derive"
version = "5.5.0"
version = "5.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97c2401ab7ac5282ca5c8b518a87635b1a93762b0b90b9990c509888eeccba29"
checksum = "2a07ad93a80d1b92bb44cb42d7c49b49c9aab1778befefad49cceb5e4c5bf460"
dependencies = [
"proc-macro2",
"quote",
@ -2497,9 +2515,9 @@ dependencies = [
[[package]]
name = "mockito"
version = "0.32.5"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "406f43768da5a859ce19bb0978fd8dc2167a7d9a52f3935c6a187242e1a4ff9f"
checksum = "8c1eecc3baf782e3c8d6803cc8780268da1f32df6eb88c016c1d80b0df7944cf"
dependencies = [
"assert-json-diff",
"colored",
@ -2649,7 +2667,7 @@ dependencies = [
[[package]]
name = "nu"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"assert_cmd",
"atty",
@ -2704,7 +2722,7 @@ dependencies = [
[[package]]
name = "nu-cli"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"atty",
"chrono",
@ -2733,7 +2751,7 @@ dependencies = [
[[package]]
name = "nu-cmd-lang"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"fancy-regex",
"itertools",
@ -2746,11 +2764,12 @@ dependencies = [
"nu-test-support",
"nu-utils",
"shadow-rs",
"unicode-segmentation",
]
[[package]]
name = "nu-color-config"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"nu-ansi-term",
"nu-engine",
@ -2764,7 +2783,7 @@ dependencies = [
[[package]]
name = "nu-command"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"Inflector",
"alphanumeric-sort",
@ -2797,6 +2816,7 @@ dependencies = [
"log",
"lscolors",
"md-5",
"miette",
"mime",
"mime_guess",
"mockito",
@ -2828,8 +2848,7 @@ dependencies = [
"polars",
"powierza-coefficient",
"print-positions",
"proptest",
"quick-xml 0.27.1",
"quick-xml 0.28.1",
"quickcheck",
"quickcheck_macros",
"rand 0.8.5",
@ -2862,13 +2881,13 @@ dependencies = [
"uuid",
"wax",
"which",
"windows",
"windows 0.46.0",
"winreg",
]
[[package]]
name = "nu-engine"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"chrono",
"nu-glob",
@ -2881,7 +2900,7 @@ dependencies = [
[[package]]
name = "nu-explore"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"ansi-str 0.7.2",
"crossterm 0.24.0",
@ -2901,14 +2920,14 @@ dependencies = [
[[package]]
name = "nu-glob"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"doc-comment",
]
[[package]]
name = "nu-json"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"linked-hash-map",
"num-traits",
@ -2917,7 +2936,7 @@ dependencies = [
[[package]]
name = "nu-parser"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"bytesize",
"chrono",
@ -2934,7 +2953,7 @@ dependencies = [
[[package]]
name = "nu-path"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"dirs-next",
"omnipath",
@ -2943,7 +2962,7 @@ dependencies = [
[[package]]
name = "nu-plugin"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"bincode",
"nu-engine",
@ -2956,7 +2975,7 @@ dependencies = [
[[package]]
name = "nu-pretty-hex"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"heapless",
"nu-ansi-term",
@ -2965,7 +2984,7 @@ dependencies = [
[[package]]
name = "nu-protocol"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"byte-unit",
"chrono",
@ -2988,7 +3007,7 @@ dependencies = [
[[package]]
name = "nu-system"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"atty",
"chrono",
@ -3006,9 +3025,8 @@ dependencies = [
[[package]]
name = "nu-table"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"atty",
"json_to_table",
"nu-ansi-term",
"nu-color-config",
@ -3021,7 +3039,7 @@ dependencies = [
[[package]]
name = "nu-term-grid"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"nu-utils",
"unicode-width",
@ -3029,7 +3047,7 @@ dependencies = [
[[package]]
name = "nu-test-support"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"getset",
"hamcrest2",
@ -3037,14 +3055,13 @@ dependencies = [
"nu-path",
"nu-utils",
"num-format",
"once_cell",
"tempfile",
"which",
]
[[package]]
name = "nu-utils"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"crossterm_winapi",
"log",
@ -3066,7 +3083,7 @@ dependencies = [
[[package]]
name = "nu_plugin_example"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"nu-plugin",
"nu-protocol",
@ -3074,7 +3091,7 @@ dependencies = [
[[package]]
name = "nu_plugin_formats"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"eml-parser",
"ical",
@ -3087,7 +3104,7 @@ dependencies = [
[[package]]
name = "nu_plugin_gstat"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"git2",
"nu-engine",
@ -3097,7 +3114,7 @@ dependencies = [
[[package]]
name = "nu_plugin_inc"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"nu-plugin",
"nu-protocol",
@ -3106,7 +3123,7 @@ dependencies = [
[[package]]
name = "nu_plugin_query"
version = "0.77.0"
version = "0.78.0"
dependencies = [
"gjson",
"nu-engine",
@ -3305,18 +3322,18 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
[[package]]
name = "open"
version = "3.4.0"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21ecf2487e799604735754d2c5896106785987b441b5aee58f242e4d4963179a"
checksum = "bd61e3bf9d78956c72ee864bba52431f7f43994b21a17e9e72596a81bd61075b"
dependencies = [
"pathdiff",
]
[[package]]
name = "openssl"
version = "0.10.45"
version = "0.10.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1"
checksum = "518915b97df115dd36109bfa429a48b8f737bd05508cf9588977b599648926d2"
dependencies = [
"bitflags",
"cfg-if 1.0.0",
@ -3355,9 +3372,9 @@ dependencies = [
[[package]]
name = "openssl-sys"
version = "0.9.80"
version = "0.9.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7"
checksum = "666416d899cf077260dac8698d60a60b435a46d57e82acb1be3d0dad87284e5b"
dependencies = [
"autocfg",
"cc",
@ -4034,27 +4051,6 @@ dependencies = [
"rustix",
]
[[package]]
name = "proptest"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29f1b898011ce9595050a68e60f90bad083ff2987a695a42357134c8381fba70"
dependencies = [
"bit-set",
"bitflags",
"byteorder",
"lazy_static",
"num-traits",
"quick-error 2.0.1",
"rand 0.8.5",
"rand_chacha 0.3.1",
"rand_xorshift",
"regex-syntax",
"rusty-fork",
"tempfile",
"unarray",
]
[[package]]
name = "pure-rust-locales"
version = "0.5.6"
@ -4077,12 +4073,6 @@ version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quick-error"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
[[package]]
name = "quick-xml"
version = "0.25.0"
@ -4095,9 +4085,9 @@ dependencies = [
[[package]]
name = "quick-xml"
version = "0.27.1"
version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffc053f057dd768a56f62cd7e434c42c831d296968997e9ac1f76ea7c2d14c41"
checksum = "e5c1a97b1bc42b1d550bfb48d4262153fe400a12bab1511821736f7eac76d7e2"
dependencies = [
"memchr",
]
@ -4224,15 +4214,6 @@ dependencies = [
"rand_core 0.5.1",
]
[[package]]
name = "rand_xorshift"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
dependencies = [
"rand_core 0.6.4",
]
[[package]]
name = "rayon"
version = "1.7.0"
@ -4277,9 +4258,9 @@ dependencies = [
[[package]]
name = "reedline"
version = "0.17.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3afcd7fc553d129e9a03d17f15c4b4748baa589570f01a372caae2de81989b8"
checksum = "8df9be1b4ddfacccf35ea8b4a8d3f7ec9e494ea22969c4156d4b2a393c1b9cef"
dependencies = [
"chrono",
"crossterm 0.24.0",
@ -4353,9 +4334,9 @@ dependencies = [
[[package]]
name = "rstest"
version = "0.16.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b07f2d176c472198ec1e6551dc7da28f1c089652f66a7b722676c2238ebc0edf"
checksum = "de1bb486a691878cd320c2f0d319ba91eeaa2e894066d8b5f8f117c000e9d962"
dependencies = [
"rstest_macros",
"rustc_version",
@ -4363,9 +4344,9 @@ dependencies = [
[[package]]
name = "rstest_macros"
version = "0.16.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7229b505ae0706e64f37ffc54a9c163e11022a6636d58fe1f3f52018257ff9f7"
checksum = "290ca1a1c8ca7edb7c3283bd44dc35dd54fdec6253a3912e201ba1072018fca8"
dependencies = [
"cfg-if 1.0.0",
"proc-macro2",
@ -4478,18 +4459,6 @@ version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06"
[[package]]
name = "rusty-fork"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f"
dependencies = [
"fnv",
"quick-error 1.2.3",
"tempfile",
"wait-timeout",
]
[[package]]
name = "ryu"
version = "1.0.13"
@ -4860,9 +4829,9 @@ dependencies = [
[[package]]
name = "sqlparser"
version = "0.30.0"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db67dc6ef36edb658196c3fef0464a80b53dbbc194a904e81f9bd4190f9ecc5b"
checksum = "0366f270dbabb5cc2e4c88427dc4c08bba144f81e32fbd459a013f26a4d16aa0"
dependencies = [
"log",
"serde",
@ -4957,30 +4926,30 @@ dependencies = [
[[package]]
name = "supports-color"
version = "1.3.1"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ba6faf2ca7ee42fdd458f4347ae0a9bd6bcc445ad7cb57ad82b383f18870d6f"
checksum = "4950e7174bffabe99455511c39707310e7e9b440364a2fcb1cc21521be57b354"
dependencies = [
"atty",
"is-terminal",
"is_ci",
]
[[package]]
name = "supports-hyperlinks"
version = "1.2.0"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "590b34f7c5f01ecc9d78dba4b3f445f31df750a67621cf31626f3b7441ce6406"
checksum = "4b4806e0b03b9906e76b018a5d821ebf198c8e9dc0829ed3328eeeb5094aed60"
dependencies = [
"atty",
"is-terminal",
]
[[package]]
name = "supports-unicode"
version = "1.0.2"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8b945e45b417b125a8ec51f1b7df2f8df7920367700d1f98aedd21e5735f8b2"
checksum = "4b6c2cb240ab5dd21ed4906895ee23fe5a48acdbd15a3ce388e7b62a9b66baf7"
dependencies = [
"atty",
"is-terminal",
]
[[package]]
@ -5000,7 +4969,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36e39da5d30887b5690e29de4c5ebb8ddff64ebd9933f98a01daaa4fd11b36ea"
dependencies = [
"peresil",
"quick-error 1.2.3",
"quick-error",
"sxd-document",
]
@ -5400,7 +5369,7 @@ dependencies = [
"once_cell",
"scopeguard",
"url",
"windows",
"windows 0.44.0",
]
[[package]]
@ -5464,12 +5433,6 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46b0c16eadfb312c7acd6970fc97d1f3152eb536714a2ff72ca09a92cae6fa67"
[[package]]
name = "unarray"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
[[package]]
name = "unicase"
version = "2.6.0"
@ -5874,6 +5837,15 @@ dependencies = [
"windows-targets",
]
[[package]]
name = "windows"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-sys"
version = "0.42.0"
@ -5900,9 +5872,9 @@ dependencies = [
[[package]]
name = "windows-targets"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
@ -5915,45 +5887,45 @@ dependencies = [
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
[[package]]
name = "windows_i686_gnu"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
[[package]]
name = "windows_i686_msvc"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
[[package]]
name = "winnow"

View File

@ -10,7 +10,7 @@ license = "MIT"
name = "nu"
repository = "https://github.com/nushell/nushell"
rust-version = "1.60"
version = "0.77.0"
version = "0.78.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -45,25 +45,25 @@ chrono = { version = "0.4.23", features = ["serde"] }
crossterm = "0.24.0"
ctrlc = "3.2.1"
log = "0.4"
miette = { version = "5.5.0", features = ["fancy-no-backtrace"] }
nu-cli = { path = "./crates/nu-cli", version = "0.77.0" }
nu-color-config = { path = "./crates/nu-color-config", version = "0.77.0" }
nu-cmd-lang = { path = "./crates/nu-cmd-lang", version = "0.77.0" }
nu-command = { path = "./crates/nu-command", version = "0.77.0" }
nu-engine = { path = "./crates/nu-engine", version = "0.77.0" }
nu-json = { path = "./crates/nu-json", version = "0.77.0" }
nu-parser = { path = "./crates/nu-parser", version = "0.77.0" }
nu-path = { path = "./crates/nu-path", version = "0.77.0" }
nu-plugin = { path = "./crates/nu-plugin", optional = true, version = "0.77.0" }
nu-pretty-hex = { path = "./crates/nu-pretty-hex", version = "0.77.0" }
nu-protocol = { path = "./crates/nu-protocol", version = "0.77.0" }
nu-system = { path = "./crates/nu-system", version = "0.77.0" }
nu-table = { path = "./crates/nu-table", version = "0.77.0" }
nu-term-grid = { path = "./crates/nu-term-grid", version = "0.77.0" }
nu-utils = { path = "./crates/nu-utils", version = "0.77.0" }
miette = { version = "5.6.0", features = ["fancy-no-backtrace"] }
nu-cli = { path = "./crates/nu-cli", version = "0.78.0" }
nu-color-config = { path = "./crates/nu-color-config", version = "0.78.0" }
nu-cmd-lang = { path = "./crates/nu-cmd-lang", version = "0.78.0" }
nu-command = { path = "./crates/nu-command", version = "0.78.0" }
nu-engine = { path = "./crates/nu-engine", version = "0.78.0" }
nu-json = { path = "./crates/nu-json", version = "0.78.0" }
nu-parser = { path = "./crates/nu-parser", version = "0.78.0" }
nu-path = { path = "./crates/nu-path", version = "0.78.0" }
nu-plugin = { path = "./crates/nu-plugin", optional = true, version = "0.78.0" }
nu-pretty-hex = { path = "./crates/nu-pretty-hex", version = "0.78.0" }
nu-protocol = { path = "./crates/nu-protocol", version = "0.78.0" }
nu-system = { path = "./crates/nu-system", version = "0.78.0" }
nu-table = { path = "./crates/nu-table", version = "0.78.0" }
nu-term-grid = { path = "./crates/nu-term-grid", version = "0.78.0" }
nu-utils = { path = "./crates/nu-utils", version = "0.78.0" }
nu-ansi-term = "0.47.0"
reedline = { version = "0.17.0", features = ["bashisms", "sqlite"] }
reedline = { version = "0.18.0", features = ["bashisms", "sqlite"] }
rayon = "1.7.0"
is_executable = "1.0.1"
@ -72,7 +72,7 @@ time = "0.3.12"
[target.'cfg(not(target_os = "windows"))'.dependencies]
# Our dependencies don't use OpenSSL on Windows
openssl = { version = "0.10.38", features = ["vendored"], optional = true }
openssl = { version = "0.10.48", features = ["vendored"], optional = true }
signal-hook = { version = "0.3.14", default-features = false }
@ -89,14 +89,14 @@ nix = { version = "0.26", default-features = false, features = [
atty = "0.2"
[dev-dependencies]
nu-test-support = { path = "./crates/nu-test-support", version = "0.77.0" }
nu-test-support = { path = "./crates/nu-test-support", version = "0.78.0" }
tempfile = "3.4.0"
assert_cmd = "2.0.2"
criterion = "0.4"
pretty_assertions = "1.0.0"
serial_test = "1.0.0"
hamcrest2 = "0.3.0"
rstest = { version = "0.16.0", default-features = false }
rstest = { version = "0.17.0", default-features = false }
itertools = "0.10.3"
[features]

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2019 - 2022 The Nushell Project Developers
Copyright (c) 2019 - 2023 The Nushell Project Developers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -6,7 +6,7 @@
[![@nu_shell](https://img.shields.io/badge/twitter-@nu_shell-1DA1F3?style=flat-square)](https://twitter.com/nu_shell)
[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/nushell/nushell)](https://github.com/nushell/nushell/graphs/commit-activity)
[![GitHub contributors](https://img.shields.io/github/contributors/nushell/nushell)](https://github.com/nushell/nushell/graphs/contributors)
[![codecov](https://codecov.io/gh/nushell/nushell/branch/main/graph/badge.svg?token=JheS8qu2II)](https://codecov.io/gh/nushell/nushell)
<!-- [![codecov](https://codecov.io/gh/nushell/nushell/branch/main/graph/badge.svg?token=JheS8qu2II)](https://codecov.io/gh/nushell/nushell) -->
A new type of shell.
@ -175,7 +175,8 @@ These binaries interact with nu via a simple JSON-RPC protocol where the command
If the plugin is a filter, data streams to it one element at a time, and it can stream data back in return via stdin/stdout.
If the plugin is a sink, it is given the full vector of final data and is given free reign over stdin/stdout to use as it pleases.
The [awesome-nu repo](https://github.com/nushell/awesome-nu#plugins) lists a variety of nu-plugins.
The [awesome-nu repo](https://github.com/nushell/awesome-nu#plugins) lists a variety of nu-plugins while the [showcase repo](https://github.com/nushell/showcase) *shows* off informative blog posts that have been written about Nushell along with videos that highlight technical
topics that have been presented.
## Goals

View File

@ -20,5 +20,6 @@ for plugin in $plugins {
'----------------------------'
cd $'crates/($plugin)'
cargo build
cd ../../
ignore
}

View File

@ -5,26 +5,26 @@ repository = "https://github.com/nushell/nushell/tree/main/crates/nu-cli"
edition = "2021"
license = "MIT"
name = "nu-cli"
version = "0.77.0"
version = "0.78.0"
[lib]
bench = false
[dev-dependencies]
nu-test-support = { path = "../nu-test-support", version = "0.77.0" }
nu-command = { path = "../nu-command", version = "0.77.0" }
rstest = { version = "0.16.0", default-features = false }
nu-test-support = { path = "../nu-test-support", version = "0.78.0" }
rstest = { version = "0.17.0", default-features = false }
[dependencies]
nu-engine = { path = "../nu-engine", version = "0.77.0" }
nu-path = { path = "../nu-path", version = "0.77.0" }
nu-parser = { path = "../nu-parser", version = "0.77.0" }
nu-protocol = { path = "../nu-protocol", version = "0.77.0" }
nu-utils = { path = "../nu-utils", version = "0.77.0" }
nu-color-config = { path = "../nu-color-config", version = "0.77.0" }
nu-command = { path = "../nu-command", version = "0.78.0" }
nu-engine = { path = "../nu-engine", version = "0.78.0" }
nu-path = { path = "../nu-path", version = "0.78.0" }
nu-parser = { path = "../nu-parser", version = "0.78.0" }
nu-protocol = { path = "../nu-protocol", version = "0.78.0" }
nu-utils = { path = "../nu-utils", version = "0.78.0" }
nu-color-config = { path = "../nu-color-config", version = "0.78.0" }
nu-ansi-term = "0.47.0"
reedline = { version = "0.17.0", features = ["bashisms", "sqlite"] }
reedline = { version = "0.18.0", features = ["bashisms", "sqlite"] }
atty = "0.2.14"
chrono = { default-features = false, features = ["std"], version = "0.4.23" }
@ -34,7 +34,7 @@ fuzzy-matcher = "0.3.7"
is_executable = "1.0.1"
once_cell = "1.17.0"
log = "0.4"
miette = { version = "5.5.0", features = ["fancy-no-backtrace"] }
miette = { version = "5.6.0", features = ["fancy-no-backtrace"] }
percent-encoding = "2"
sysinfo = "0.28.2"
thiserror = "1.0.31"

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2019 - 2022 The Nushell Project Developers
Copyright (c) 2019 - 2023 The Nushell Project Developers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,6 +1,6 @@
use crate::util::report_error;
use log::info;
use miette::Result;
use nu_command::util::report_error;
use nu_engine::{convert_env_values, eval_block};
use nu_parser::parse;
use nu_protocol::engine::Stack;

View File

@ -1,4 +1,5 @@
use crate::util::{eval_source, report_error};
use crate::util::eval_source;
use nu_command::util::report_error;
#[cfg(feature = "plugin")]
use nu_parser::ParseError;
#[cfg(feature = "plugin")]

View File

@ -1,7 +1,8 @@
use crate::util::{eval_source, report_error};
use crate::util::eval_source;
use log::info;
use log::trace;
use miette::{IntoDiagnostic, Result};
use nu_command::util::report_error;
use nu_engine::{convert_env_values, current_dir};
use nu_parser::parse;
use nu_path::canonicalize_with;

View File

@ -18,13 +18,13 @@ pub use completions::{FileCompletion, NuCompleter};
pub use config_files::eval_config_contents;
pub use eval_file::evaluate_file;
pub use menus::{DescriptionMenu, NuHelpCompleter};
pub use nu_command::util::{get_init_cwd, report_error, report_error_new};
pub use nu_highlight::NuHighlight;
pub use print::Print;
pub use prompt::NushellPrompt;
pub use repl::evaluate_repl;
pub use repl::{eval_env_change_hook, eval_hook};
pub use syntax_highlight::NuHighlighter;
pub use util::{eval_source, gather_parent_env_vars, get_init_cwd, report_error, report_error_new};
pub use util::{eval_source, gather_parent_env_vars};
pub use validation::NuValidator;
#[cfg(feature = "plugin")]

View File

@ -1,6 +1,6 @@
use crate::util::report_error;
use crate::NushellPrompt;
use log::trace;
use nu_command::util::report_error;
use nu_engine::eval_subexpression;
use nu_protocol::{
engine::{EngineState, Stack, StateWorkingSet},

View File

@ -626,9 +626,12 @@ fn add_parsed_keybinding(
"shift" => KeyModifiers::SHIFT,
"alt" => KeyModifiers::ALT,
"none" => KeyModifiers::NONE,
"control | shift" => KeyModifiers::CONTROL | KeyModifiers::SHIFT,
"control | alt" => KeyModifiers::CONTROL | KeyModifiers::ALT,
"control | alt | shift" => KeyModifiers::CONTROL | KeyModifiers::ALT | KeyModifiers::SHIFT,
"shift_alt" | "alt_shift" => KeyModifiers::SHIFT | KeyModifiers::ALT,
"control_shift" | "shift_control" => KeyModifiers::CONTROL | KeyModifiers::SHIFT,
"control_alt" | "alt_control" => KeyModifiers::CONTROL | KeyModifiers::ALT,
"control_alt_shift" | "control_shift_alt" => {
KeyModifiers::CONTROL | KeyModifiers::ALT | KeyModifiers::SHIFT
}
_ => {
return Err(ShellError::UnsupportedConfigValue(
"CONTROL, SHIFT, ALT or NONE".to_string(),

View File

@ -2,21 +2,21 @@ use crate::{
completions::NuCompleter,
prompt_update,
reedline_config::{add_menus, create_keybindings, KeybindingsMode},
util::{eval_source, get_guaranteed_cwd, report_error, report_error_new},
util::eval_source,
NuHighlighter, NuValidator, NushellPrompt,
};
use crossterm::cursor::CursorShape;
use log::{trace, warn};
use miette::{IntoDiagnostic, Result};
use nu_color_config::StyleComputer;
use nu_engine::{convert_env_values, eval_block, eval_block_with_early_return};
use nu_command::hook::eval_hook;
use nu_command::util::{get_guaranteed_cwd, report_error, report_error_new};
use nu_engine::{convert_env_values, eval_block};
use nu_parser::{lex, parse, trim_quotes_str};
use nu_protocol::{
ast::PathMember,
config::NuCursorShape,
engine::{EngineState, ReplOperation, Stack, StateWorkingSet},
format_duration, BlockId, HistoryFileFormat, PipelineData, PositionalArg, ShellError, Span,
Spanned, Type, Value, VarId,
engine::{EngineState, Stack, StateWorkingSet},
format_duration, HistoryFileFormat, PipelineData, ShellError, Span, Spanned, Value,
};
use nu_utils::utils::perf;
use reedline::{CursorConfig, DefaultHinter, EditCommand, Emacs, SqliteBackedHistory, Vi};
@ -44,6 +44,7 @@ pub fn evaluate_repl(
prerun_command: Option<Spanned<String>>,
entire_start_time: Instant,
) -> Result<()> {
use nu_command::hook;
use reedline::{FileBackedHistory, Reedline, Signal};
let use_color = engine_state.get_config().use_ansi_coloring;
@ -400,7 +401,7 @@ pub fn evaluate_repl(
// fire the "env_change" hook
let config = engine_state.get_config();
if let Err(error) =
eval_env_change_hook(config.hooks.env_change.clone(), engine_state, stack)
hook::eval_env_change_hook(config.hooks.env_change.clone(), engine_state, stack)
{
report_error_new(engine_state, &error)
}
@ -459,20 +460,29 @@ pub fn evaluate_repl(
.into_diagnostic()?; // todo: don't stop repl if error here?
}
engine_state
// Right before we start running the code the user gave us, fire the `pre_execution`
// hook
if let Some(hook) = config.hooks.pre_execution.clone() {
// Set the REPL buffer to the current command for the "pre_execution" hook
let mut repl_buffer = engine_state
.repl_buffer_state
.lock()
.expect("repl buffer state mutex")
.replace(line_editor.current_buffer_contents().to_string());
.expect("repl buffer state mutex");
*repl_buffer = s.to_string();
drop(repl_buffer);
// Right before we start running the code the user gave us,
// fire the "pre_execution" hook
if let Some(hook) = config.hooks.pre_execution.clone() {
if let Err(err) = eval_hook(engine_state, stack, None, vec![], &hook) {
report_error_new(engine_state, &err);
}
}
let mut repl_buffer = engine_state
.repl_buffer_state
.lock()
.expect("repl buffer state mutex");
*repl_buffer = line_editor.current_buffer_contents().to_string();
drop(repl_buffer);
if shell_integration {
run_ansi_sequence(PRE_EXECUTE_MARKER)?;
}
@ -628,23 +638,23 @@ pub fn evaluate_repl(
run_ansi_sequence(RESET_APPLICATION_MODE)?;
}
let mut ops = engine_state
.repl_operation_queue
let mut repl_buffer = engine_state
.repl_buffer_state
.lock()
.expect("repl op queue mutex");
while let Some(op) = ops.pop_front() {
match op {
ReplOperation::Append(s) => line_editor.run_edit_commands(&[
EditCommand::MoveToEnd,
EditCommand::InsertString(s),
]),
ReplOperation::Insert(s) => {
line_editor.run_edit_commands(&[EditCommand::InsertString(s)])
}
ReplOperation::Replace(s) => line_editor
.run_edit_commands(&[EditCommand::Clear, EditCommand::InsertString(s)]),
}
}
.expect("repl buffer state mutex");
let mut repl_cursor_pos = engine_state
.repl_cursor_pos
.lock()
.expect("repl cursor pos mutex");
line_editor.run_edit_commands(&[
EditCommand::Clear,
EditCommand::InsertString(repl_buffer.to_string()),
EditCommand::MoveToPosition(*repl_cursor_pos),
]);
*repl_buffer = "".to_string();
drop(repl_buffer);
*repl_cursor_pos = 0;
drop(repl_cursor_pos);
}
Ok(Signal::CtrlC) => {
// `Reedline` clears the line content. New prompt is shown
@ -810,341 +820,6 @@ pub fn get_command_finished_marker(stack: &Stack, engine_state: &EngineState) ->
format!("\x1b]133;D;{}\x1b\\", exit_code.unwrap_or(0))
}
pub fn eval_env_change_hook(
env_change_hook: Option<Value>,
engine_state: &mut EngineState,
stack: &mut Stack,
) -> Result<(), ShellError> {
if let Some(hook) = env_change_hook {
match hook {
Value::Record {
cols: env_names,
vals: hook_values,
..
} => {
for (env_name, hook_value) in env_names.iter().zip(hook_values.iter()) {
let before = engine_state
.previous_env_vars
.get(env_name)
.cloned()
.unwrap_or_default();
let after = stack
.get_env_var(engine_state, env_name)
.unwrap_or_default();
if before != after {
eval_hook(
engine_state,
stack,
None,
vec![("$before".into(), before), ("$after".into(), after.clone())],
hook_value,
)?;
engine_state
.previous_env_vars
.insert(env_name.to_string(), after);
}
}
}
x => {
return Err(ShellError::TypeMismatch {
err_message: "record for the 'env_change' hook".to_string(),
span: x.span()?,
});
}
}
}
Ok(())
}
pub fn eval_hook(
engine_state: &mut EngineState,
stack: &mut Stack,
input: Option<PipelineData>,
arguments: Vec<(String, Value)>,
value: &Value,
) -> Result<PipelineData, ShellError> {
let value_span = value.span()?;
// Hooks can optionally be a record in this form:
// {
// condition: {|before, after| ... } # block that evaluates to true/false
// code: # block or a string
// }
// The condition block will be run to check whether the main hook (in `code`) should be run.
// If it returns true (the default if a condition block is not specified), the hook should be run.
let condition_path = PathMember::String {
val: "condition".to_string(),
span: value_span,
};
let mut output = PipelineData::empty();
let code_path = PathMember::String {
val: "code".to_string(),
span: value_span,
};
match value {
Value::List { vals, .. } => {
for val in vals {
eval_hook(engine_state, stack, None, arguments.clone(), val)?;
}
}
Value::Record { .. } => {
let do_run_hook = if let Ok(condition) =
value
.clone()
.follow_cell_path(&[condition_path], false, false)
{
match condition {
Value::Block {
val: block_id,
span: block_span,
..
}
| Value::Closure {
val: block_id,
span: block_span,
..
} => {
match run_hook_block(
engine_state,
stack,
block_id,
None,
arguments.clone(),
block_span,
) {
Ok(pipeline_data) => {
if let PipelineData::Value(Value::Bool { val, .. }, ..) =
pipeline_data
{
val
} else {
return Err(ShellError::UnsupportedConfigValue(
"boolean output".to_string(),
"other PipelineData variant".to_string(),
block_span,
));
}
}
Err(err) => {
return Err(err);
}
}
}
other => {
return Err(ShellError::UnsupportedConfigValue(
"block".to_string(),
format!("{}", other.get_type()),
other.span()?,
));
}
}
} else {
// always run the hook
true
};
if do_run_hook {
match value.clone().follow_cell_path(&[code_path], false, false)? {
Value::String {
val,
span: source_span,
} => {
let (block, delta, vars) = {
let mut working_set = StateWorkingSet::new(engine_state);
let mut vars: Vec<(VarId, Value)> = vec![];
for (name, val) in arguments {
let var_id = working_set.add_variable(
name.as_bytes().to_vec(),
val.span()?,
Type::Any,
false,
);
vars.push((var_id, val));
}
let (output, err) =
parse(&mut working_set, Some("hook"), val.as_bytes(), false, &[]);
if let Some(err) = err {
report_error(&working_set, &err);
return Err(ShellError::UnsupportedConfigValue(
"valid source code".into(),
"source code with syntax errors".into(),
source_span,
));
}
(output, working_set.render(), vars)
};
engine_state.merge_delta(delta)?;
let input = PipelineData::empty();
let var_ids: Vec<VarId> = vars
.into_iter()
.map(|(var_id, val)| {
stack.add_var(var_id, val);
var_id
})
.collect();
match eval_block(engine_state, stack, &block, input, false, false) {
Ok(pipeline_data) => {
output = pipeline_data;
}
Err(err) => {
report_error_new(engine_state, &err);
}
}
for var_id in var_ids.iter() {
stack.vars.remove(var_id);
}
}
Value::Block {
val: block_id,
span: block_span,
..
} => {
run_hook_block(
engine_state,
stack,
block_id,
input,
arguments,
block_span,
)?;
}
Value::Closure {
val: block_id,
span: block_span,
..
} => {
run_hook_block(
engine_state,
stack,
block_id,
input,
arguments,
block_span,
)?;
}
other => {
return Err(ShellError::UnsupportedConfigValue(
"block or string".to_string(),
format!("{}", other.get_type()),
other.span()?,
));
}
}
}
}
Value::Block {
val: block_id,
span: block_span,
..
} => {
output = run_hook_block(
engine_state,
stack,
*block_id,
input,
arguments,
*block_span,
)?;
}
Value::Closure {
val: block_id,
span: block_span,
..
} => {
output = run_hook_block(
engine_state,
stack,
*block_id,
input,
arguments,
*block_span,
)?;
}
other => {
return Err(ShellError::UnsupportedConfigValue(
"block, record, or list of records".into(),
format!("{}", other.get_type()),
other.span()?,
));
}
}
let cwd = get_guaranteed_cwd(engine_state, stack);
engine_state.merge_env(stack, cwd)?;
Ok(output)
}
fn run_hook_block(
engine_state: &EngineState,
stack: &mut Stack,
block_id: BlockId,
optional_input: Option<PipelineData>,
arguments: Vec<(String, Value)>,
span: Span,
) -> Result<PipelineData, ShellError> {
let block = engine_state.get_block(block_id);
let input = optional_input.unwrap_or_else(PipelineData::empty);
let mut callee_stack = stack.gather_captures(&block.captures);
for (idx, PositionalArg { var_id, .. }) in
block.signature.required_positional.iter().enumerate()
{
if let Some(var_id) = var_id {
if let Some(arg) = arguments.get(idx) {
callee_stack.add_var(*var_id, arg.1.clone())
} else {
return Err(ShellError::IncompatibleParametersSingle {
msg: "This hook block has too many parameters".into(),
span,
});
}
}
}
let pipeline_data =
eval_block_with_early_return(engine_state, &mut callee_stack, block, input, false, false)?;
if let PipelineData::Value(Value::Error { error }, _) = pipeline_data {
return Err(*error);
}
// If all went fine, preserve the environment of the called block
let caller_env_vars = stack.get_env_var_names(engine_state);
// remove env vars that are present in the caller but not in the callee
// (the callee hid them)
for var in caller_env_vars.iter() {
if !callee_stack.has_env_var(engine_state, var) {
stack.remove_env_var(engine_state, var);
}
}
// add new env vars from callee to caller
for (var, value) in callee_stack.get_stack_env_vars() {
stack.add_env_var(var, value);
}
Ok(pipeline_data)
}
fn run_ansi_sequence(seq: &str) -> Result<(), ShellError> {
io::stdout().write_all(seq.as_bytes()).map_err(|e| {
ShellError::GenericError(

View File

@ -79,29 +79,27 @@ impl Highlighter for NuHighlighter {
}};
}
macro_rules! add_colored_token {
($shape:expr, $text:expr) => {
output.push((get_shape_color($shape.to_string(), &self.config), $text))
let mut add_colored_token = |shape: &FlatShape, text: String| {
output.push((get_shape_color(shape.to_string(), &self.config), text));
};
}
match shape.1 {
FlatShape::Garbage => add_colored_token!(shape.1, next_token),
FlatShape::Nothing => add_colored_token!(shape.1, next_token),
FlatShape::Binary => add_colored_token!(shape.1, next_token),
FlatShape::Bool => add_colored_token!(shape.1, next_token),
FlatShape::Int => add_colored_token!(shape.1, next_token),
FlatShape::Float => add_colored_token!(shape.1, next_token),
FlatShape::Range => add_colored_token!(shape.1, next_token),
FlatShape::InternalCall => add_colored_token!(shape.1, next_token),
FlatShape::External => add_colored_token!(shape.1, next_token),
FlatShape::ExternalArg => add_colored_token!(shape.1, next_token),
FlatShape::Literal => add_colored_token!(shape.1, next_token),
FlatShape::Operator => add_colored_token!(shape.1, next_token),
FlatShape::Signature => add_colored_token!(shape.1, next_token),
FlatShape::String => add_colored_token!(shape.1, next_token),
FlatShape::StringInterpolation => add_colored_token!(shape.1, next_token),
FlatShape::DateTime => add_colored_token!(shape.1, next_token),
FlatShape::Garbage => add_colored_token(&shape.1, next_token),
FlatShape::Nothing => add_colored_token(&shape.1, next_token),
FlatShape::Binary => add_colored_token(&shape.1, next_token),
FlatShape::Bool => add_colored_token(&shape.1, next_token),
FlatShape::Int => add_colored_token(&shape.1, next_token),
FlatShape::Float => add_colored_token(&shape.1, next_token),
FlatShape::Range => add_colored_token(&shape.1, next_token),
FlatShape::InternalCall => add_colored_token(&shape.1, next_token),
FlatShape::External => add_colored_token(&shape.1, next_token),
FlatShape::ExternalArg => add_colored_token(&shape.1, next_token),
FlatShape::Literal => add_colored_token(&shape.1, next_token),
FlatShape::Operator => add_colored_token(&shape.1, next_token),
FlatShape::Signature => add_colored_token(&shape.1, next_token),
FlatShape::String => add_colored_token(&shape.1, next_token),
FlatShape::StringInterpolation => add_colored_token(&shape.1, next_token),
FlatShape::DateTime => add_colored_token(&shape.1, next_token),
FlatShape::List => {
add_colored_token_with_bracket_highlight!(shape.1, shape.0, next_token)
}
@ -116,16 +114,17 @@ impl Highlighter for NuHighlighter {
add_colored_token_with_bracket_highlight!(shape.1, shape.0, next_token)
}
FlatShape::Filepath => add_colored_token!(shape.1, next_token),
FlatShape::Directory => add_colored_token!(shape.1, next_token),
FlatShape::GlobPattern => add_colored_token!(shape.1, next_token),
FlatShape::Variable => add_colored_token!(shape.1, next_token),
FlatShape::Flag => add_colored_token!(shape.1, next_token),
FlatShape::Pipe => add_colored_token!(shape.1, next_token),
FlatShape::And => add_colored_token!(shape.1, next_token),
FlatShape::Or => add_colored_token!(shape.1, next_token),
FlatShape::Redirection => add_colored_token!(shape.1, next_token),
FlatShape::Custom(..) => add_colored_token!(shape.1, next_token),
FlatShape::Filepath => add_colored_token(&shape.1, next_token),
FlatShape::Directory => add_colored_token(&shape.1, next_token),
FlatShape::GlobPattern => add_colored_token(&shape.1, next_token),
FlatShape::Variable => add_colored_token(&shape.1, next_token),
FlatShape::Flag => add_colored_token(&shape.1, next_token),
FlatShape::Pipe => add_colored_token(&shape.1, next_token),
FlatShape::And => add_colored_token(&shape.1, next_token),
FlatShape::Or => add_colored_token(&shape.1, next_token),
FlatShape::Redirection => add_colored_token(&shape.1, next_token),
FlatShape::Custom(..) => add_colored_token(&shape.1, next_token),
FlatShape::MatchPattern => add_colored_token(&shape.1, next_token),
}
last_seen_span = shape.0.end;
}
@ -308,6 +307,8 @@ fn find_matching_block_end_in_expr(
Expr::ImportPattern(_) => None,
Expr::Overlay(_) => None,
Expr::Signature(_) => None,
Expr::MatchPattern(_) => None,
Expr::MatchBlock(_) => None,
Expr::Nothing => None,
Expr::Garbage => None,

View File

@ -1,8 +1,8 @@
use crate::repl::eval_hook;
use nu_command::hook::eval_hook;
use nu_command::util::{report_error, report_error_new};
use nu_engine::{eval_block, eval_block_with_early_return};
use nu_parser::{escape_quote_string, lex, parse, unescape_unquote_string, Token, TokenContents};
use nu_protocol::engine::StateWorkingSet;
use nu_protocol::CliError;
use nu_protocol::{
engine::{EngineState, Stack},
print_if_stream, PipelineData, ShellError, Span, Value,
@ -10,7 +10,7 @@ use nu_protocol::{
#[cfg(windows)]
use nu_utils::enable_vt_processing;
use nu_utils::utils::perf;
use std::path::{Path, PathBuf};
use std::path::Path;
// This will collect environment variables from std::env and adds them to a stack.
//
@ -310,43 +310,6 @@ fn set_last_exit_code(stack: &mut Stack, exit_code: i64) {
);
}
pub fn report_error(
working_set: &StateWorkingSet,
error: &(dyn miette::Diagnostic + Send + Sync + 'static),
) {
eprintln!("Error: {:?}", CliError(error, working_set));
// reset vt processing, aka ansi because illbehaved externals can break it
#[cfg(windows)]
{
let _ = nu_utils::enable_vt_processing();
}
}
pub fn report_error_new(
engine_state: &EngineState,
error: &(dyn miette::Diagnostic + Send + Sync + 'static),
) {
let working_set = StateWorkingSet::new(engine_state);
report_error(&working_set, error);
}
pub fn get_init_cwd() -> PathBuf {
std::env::current_dir().unwrap_or_else(|_| {
std::env::var("PWD")
.map(Into::into)
.unwrap_or_else(|_| nu_path::home_dir().unwrap_or_default())
})
}
pub fn get_guaranteed_cwd(engine_state: &EngineState, stack: &Stack) -> PathBuf {
nu_engine::env::current_dir(engine_state, stack).unwrap_or_else(|e| {
let working_set = StateWorkingSet::new(engine_state);
report_error(&working_set, &e);
get_init_cwd()
})
}
#[cfg(test)]
mod test {
use super::*;

View File

@ -6,17 +6,17 @@ repository = "https://github.com/nushell/nushell/tree/main/crates/nu-cmd-lang"
edition = "2021"
license = "MIT"
name = "nu-cmd-lang"
version = "0.77.0"
version = "0.78.0"
[lib]
bench = false
[dependencies]
nu-color-config = { path = "../nu-color-config", version = "0.77.0" }
nu-engine = { path = "../nu-engine", version = "0.77.0" }
nu-parser = { path = "../nu-parser", version = "0.77.0" }
nu-protocol = { path = "../nu-protocol", version = "0.77.0" }
nu-utils = { path = "../nu-utils", version = "0.77.0" }
nu-color-config = { path = "../nu-color-config", version = "0.78.0" }
nu-engine = { path = "../nu-engine", version = "0.78.0" }
nu-parser = { path = "../nu-parser", version = "0.78.0" }
nu-protocol = { path = "../nu-protocol", version = "0.78.0" }
nu-utils = { path = "../nu-utils", version = "0.78.0" }
nu-ansi-term = "0.47.0"
@ -24,9 +24,10 @@ fancy-regex = "0.11.0"
itertools = "0.10.0"
log = "0.4.14"
shadow-rs = { version = "0.21.0", default-features = false }
unicode-segmentation = "1.10.0"
[build-dependencies]
shadow-rs = { version = "0.21.0", default-features = false }
[dev-dependencies]
nu-test-support = { path="../nu-test-support", version = "0.77.0" }
nu-test-support = { path="../nu-test-support", version = "0.78.0" }

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2019 - 2022 The Nushell Project Developers
Copyright (c) 2019 - 2023 The Nushell Project Developers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -72,10 +72,10 @@ impl Command for Collect {
// for when we support `data | let x = $in;`
// remove the variables added earlier
for var_id in capture_block.captures.keys() {
stack_captures.vars.remove(var_id);
stack_captures.remove_var(*var_id);
}
if let Some(u) = saved_positional {
stack_captures.vars.remove(&u);
stack_captures.remove_var(u);
}
// add any new variables to the stack
stack.vars.extend(stack_captures.vars);

View File

@ -1,10 +1,10 @@
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::ReplOperation;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::Category;
use nu_protocol::IntoPipelineData;
use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape, Type, Value};
use unicode_segmentation::UnicodeSegmentation;
#[derive(Clone)]
pub struct Commandline;
@ -17,6 +17,11 @@ impl Command for Commandline {
fn signature(&self) -> Signature {
Signature::build("commandline")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.switch(
"cursor",
"Set or get the current cursor position",
Some('c'),
)
.switch(
"append",
"appends the string to the end of the buffer",
@ -56,30 +61,77 @@ impl Command for Commandline {
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
if let Some(cmd) = call.opt::<Value>(engine_state, stack, 0)? {
let mut ops = engine_state
.repl_operation_queue
.lock()
.expect("repl op queue mutex");
ops.push_back(if call.has_flag("append") {
ReplOperation::Append(cmd.as_string()?)
} else if call.has_flag("insert") {
ReplOperation::Insert(cmd.as_string()?)
} else {
ReplOperation::Replace(cmd.as_string()?)
});
Ok(Value::Nothing { span: call.head }.into_pipeline_data())
} else if let Some(ref cmd) = *engine_state
let mut buffer = engine_state
.repl_buffer_state
.lock()
.expect("repl buffer state mutex")
{
.expect("repl buffer state mutex");
let mut cursor_pos = engine_state
.repl_cursor_pos
.lock()
.expect("repl cursor pos mutex");
if call.has_flag("cursor") {
let cmd_str = cmd.as_string()?;
match cmd_str.parse::<i64>() {
Ok(n) => {
*cursor_pos = if n <= 0 {
0usize
} else {
buffer
.grapheme_indices(true)
.map(|(i, _c)| i)
.nth(n as usize)
.unwrap_or(buffer.len())
}
}
Err(_) => {
return Err(ShellError::CantConvert {
to_type: "int".to_string(),
from_type: "string".to_string(),
span: cmd.span()?,
help: Some(format!(
r#"string "{cmd_str}" does not represent a valid integer"#
)),
})
}
}
} else if call.has_flag("append") {
buffer.push_str(&cmd.as_string()?);
} else if call.has_flag("insert") {
let cmd_str = cmd.as_string()?;
buffer.insert_str(*cursor_pos, &cmd_str);
*cursor_pos += cmd_str.len();
} else {
*buffer = cmd.as_string()?;
*cursor_pos = buffer.len();
}
Ok(Value::Nothing { span: call.head }.into_pipeline_data())
} else {
let buffer = engine_state
.repl_buffer_state
.lock()
.expect("repl buffer state mutex");
if call.has_flag("cursor") {
let cursor_pos = engine_state
.repl_cursor_pos
.lock()
.expect("repl cursor pos mutex");
let char_pos = buffer
.grapheme_indices(true)
.position(|(i, _c)| i == *cursor_pos)
.unwrap_or(buffer.len());
Ok(Value::String {
val: cmd.clone(),
val: char_pos.to_string(),
span: call.head,
}
.into_pipeline_data())
} else {
Ok(Value::Nothing { span: call.head }.into_pipeline_data())
Ok(Value::String {
val: buffer.to_string(),
span: call.head,
}
.into_pipeline_data())
}
}
}
}

View File

@ -21,7 +21,7 @@ impl Command for Const {
.required("const_name", SyntaxShape::VarWithOptType, "constant name")
.required(
"initial_value",
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Expression)),
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::MathExpression)),
"equals sign followed by constant value",
)
.category(Category::Core)

View File

@ -22,7 +22,11 @@ impl Command for Do {
fn signature(&self) -> Signature {
Signature::build("do")
.required("closure", SyntaxShape::Any, "the closure to run")
.required(
"closure",
SyntaxShape::OneOf(vec![SyntaxShape::Closure(None), SyntaxShape::Any]),
"the closure to run",
)
.input_output_types(vec![(Type::Any, Type::Any)])
.switch(
"ignore-errors",

View File

@ -44,8 +44,8 @@ impl Command for ErrorMake {
let arg: Value = call.req(engine_state, stack, 0)?;
let unspanned = call.has_flag("unspanned");
if unspanned {
Err(make_error(&arg, None).unwrap_or_else(|| {
let throw_error = if unspanned { None } else { Some(span) };
Err(make_error(&arg, throw_error).unwrap_or_else(|| {
ShellError::GenericError(
"Creating error value not supported.".into(),
"unsupported error format".into(),
@ -54,33 +54,56 @@ impl Command for ErrorMake {
Vec::new(),
)
}))
} else {
Err(make_error(&arg, Some(span)).unwrap_or_else(|| {
ShellError::GenericError(
"Creating error value not supported.".into(),
"unsupported error format".into(),
Some(span),
None,
Vec::new(),
)
}))
}
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Create a custom error for a custom command",
example: r#"def foo [x] {
let span = (metadata $x).span;
error make {msg: "this is fishy", label: {text: "fish right here", start: $span.start, end: $span.end } }
}"#,
result: None,
description: "Create a simple custom error",
example: r#"error make {msg: "my custom error message"}"#,
result: Some(Value::Error {
error: Box::new(ShellError::GenericError(
"my custom error message".to_string(),
"".to_string(),
None,
None,
Vec::new(),
)),
}),
},
Example {
description: "Create a simple custom error for a custom command",
description: "Create a more complex custom error",
example: r#"error make {
msg: "my custom error message"
label: {
text: "my custom label text" # not mandatory unless $.label exists
start: 123 # not mandatory unless $.label.end is set
end: 456 # not mandatory unless $.label.start is set
}
}"#,
result: Some(Value::Error {
error: Box::new(ShellError::GenericError(
"my custom error message".to_string(),
"my custom label text".to_string(),
Some(Span::new(123, 456)),
None,
Vec::new(),
)),
}),
},
Example {
description:
"Create a custom error for a custom command that shows the span of the argument",
example: r#"def foo [x] {
error make {msg: "this is fishy"}
let span = (metadata $x).span;
error make {
msg: "this is fishy"
label: {
text: "fish right here"
start: $span.start
end: $span.end
}
}
}"#,
result: None,
},
@ -89,7 +112,7 @@ impl Command for ErrorMake {
}
fn make_error(value: &Value, throw_span: Option<Span>) -> Option<ShellError> {
if let Value::Record { .. } = &value {
if let Value::Record { span, .. } = &value {
let msg = value.get_data_by_key("msg");
let label = value.get_data_by_key("label");
@ -99,6 +122,11 @@ fn make_error(value: &Value, throw_span: Option<Span>) -> Option<ShellError> {
let label_end = label.get_data_by_key("end");
let label_text = label.get_data_by_key("text");
let label_span = match label.span() {
Ok(lspan) => Some(lspan),
Err(_) => None,
};
match (label_start, label_end, label_text) {
(
Some(Value::Int { val: start, .. }),
@ -106,13 +134,25 @@ fn make_error(value: &Value, throw_span: Option<Span>) -> Option<ShellError> {
Some(Value::String {
val: label_text, ..
}),
) => Some(ShellError::GenericError(
) => {
if start > end {
Some(ShellError::GenericError(
"invalid error format.".into(),
"`$.label.start` should be smaller than `$.label.end`".into(),
label_span,
Some(format!("{} > {}", start, end)),
Vec::new(),
))
} else {
Some(ShellError::GenericError(
message,
label_text,
Some(Span::new(start as usize, end as usize)),
None,
Vec::new(),
)),
))
}
}
(
None,
None,
@ -126,6 +166,27 @@ fn make_error(value: &Value, throw_span: Option<Span>) -> Option<ShellError> {
None,
Vec::new(),
)),
(_, _, None) => Some(ShellError::GenericError(
"Unable to parse error format.".into(),
"missing required member `$.label.text`".into(),
label_span,
None,
Vec::new(),
)),
(Some(Value::Int { .. }), None, _) => Some(ShellError::GenericError(
"Unable to parse error format.".into(),
"missing required member `$.label.end`".into(),
label_span,
Some("required because `$.label.start` is set".to_string()),
Vec::new(),
)),
(None, Some(Value::Int { .. }), _) => Some(ShellError::GenericError(
"Unable to parse error format.".into(),
"missing required member `$.label.start`".into(),
label_span,
Some("required because `$.label.end` is set".to_string()),
Vec::new(),
)),
_ => None,
}
}
@ -136,6 +197,13 @@ fn make_error(value: &Value, throw_span: Option<Span>) -> Option<ShellError> {
None,
Vec::new(),
)),
(None, _) => Some(ShellError::GenericError(
"Unable to parse error format.".into(),
"missing required member `$.msg`".into(),
Some(*span),
None,
Vec::new(),
)),
_ => None,
}
} else {

View File

@ -162,7 +162,7 @@ impl Command for For {
return Err(err);
}
Ok(pipeline) => {
let exit_code = pipeline.print(&engine_state, stack, false, false)?;
let exit_code = pipeline.drain_with_exit_code()?;
if exit_code != 0 {
break;
}

View File

@ -0,0 +1,152 @@
use crate::help::highlight_search_in_table;
use nu_color_config::StyleComputer;
use nu_engine::{get_full_help, scope::ScopeData, CallExt};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
span, Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData,
ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
};
#[derive(Clone)]
pub struct HelpExterns;
impl Command for HelpExterns {
fn name(&self) -> &str {
"help externs"
}
fn usage(&self) -> &str {
"Show help on nushell externs."
}
fn signature(&self) -> Signature {
Signature::build("help externs")
.category(Category::Core)
.rest(
"rest",
SyntaxShape::String,
"the name of extern to get help on",
)
.named(
"find",
SyntaxShape::String,
"string to find in extern names and usage",
Some('f'),
)
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.allow_variants_without_examples(true)
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "show all externs",
example: "help externs",
result: None,
},
Example {
description: "show help for single extern",
example: "help externs smth",
result: None,
},
Example {
description: "search for string in extern names and usages",
example: "help externs --find smth",
result: None,
},
]
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
help_externs(engine_state, stack, call)
}
}
pub fn help_externs(
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
) -> Result<PipelineData, ShellError> {
let head = call.head;
let find: Option<Spanned<String>> = call.get_flag(engine_state, stack, "find")?;
let rest: Vec<Spanned<String>> = call.rest(engine_state, stack, 0)?;
// 🚩The following two-lines are copied from filters/find.rs:
let style_computer = StyleComputer::from_config(engine_state, stack);
// Currently, search results all use the same style.
// Also note that this sample string is passed into user-written code (the closure that may or may not be
// defined for "string").
let string_style = style_computer.compute("string", &Value::string("search result", head));
if let Some(f) = find {
let all_cmds_vec = build_help_externs(engine_state, stack, head);
let found_cmds_vec =
highlight_search_in_table(all_cmds_vec, &f.item, &["name", "usage"], &string_style)?;
return Ok(found_cmds_vec
.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone()));
}
if rest.is_empty() {
let found_cmds_vec = build_help_externs(engine_state, stack, head);
Ok(found_cmds_vec
.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone()))
} else {
let mut name = String::new();
for r in &rest {
if !name.is_empty() {
name.push(' ');
}
name.push_str(&r.item);
}
let output = engine_state
.get_signatures_with_examples(false)
.iter()
.filter(|(signature, _, _, _, _)| signature.name == name)
.map(|(signature, examples, _, _, is_parser_keyword)| {
get_full_help(signature, examples, engine_state, stack, *is_parser_keyword)
})
.collect::<Vec<String>>();
if !output.is_empty() {
Ok(Value::String {
val: output.join("======================\n\n"),
span: call.head,
}
.into_pipeline_data())
} else {
Err(ShellError::CommandNotFound(span(&[
rest[0].span,
rest[rest.len() - 1].span,
])))
}
}
}
fn build_help_externs(engine_state: &EngineState, stack: &Stack, span: Span) -> Vec<Value> {
let mut scope = ScopeData::new(engine_state, stack);
scope.populate_all();
scope.collect_externs(span)
}
#[cfg(test)]
mod test {
#[test]
fn test_examples() {
use super::HelpExterns;
use crate::test_examples;
test_examples(HelpExterns {})
}
}

View File

@ -20,7 +20,7 @@ impl Command for If {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("if")
.input_output_types(vec![(Type::Any, Type::Any)])
.required("cond", SyntaxShape::Expression, "condition to check")
.required("cond", SyntaxShape::MathExpression, "condition to check")
.required(
"then_block",
SyntaxShape::Block,

View File

@ -22,7 +22,7 @@ impl Command for Let {
.required("var_name", SyntaxShape::VarWithOptType, "variable name")
.required(
"initial_value",
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Expression)),
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::MathExpression)),
"equals sign followed by value",
)
.category(Category::Core)

View File

@ -67,7 +67,7 @@ impl Command for Loop {
return Err(err);
}
Ok(pipeline) => {
let exit_code = pipeline.print(engine_state, stack, false, false)?;
let exit_code = pipeline.drain_with_exit_code()?;
if exit_code != 0 {
break;
}

View File

@ -0,0 +1,133 @@
use nu_engine::{eval_block, eval_expression_with_input, CallExt};
use nu_protocol::ast::{Call, Expr, Expression};
use nu_protocol::engine::{Command, EngineState, Matcher, Stack};
use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
};
#[derive(Clone)]
pub struct Match;
impl Command for Match {
fn name(&self) -> &str {
"match"
}
fn usage(&self) -> &str {
"Conditionally run a block on a matched value."
}
fn signature(&self) -> nu_protocol::Signature {
Signature::build("match")
.input_output_types(vec![(Type::Any, Type::Any)])
.required("value", SyntaxShape::Any, "value to check")
.required(
"match_block",
SyntaxShape::MatchBlock,
"block to run if check succeeds",
)
.category(Category::Core)
}
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let value: Value = call.req(engine_state, stack, 0)?;
let block = call.positional_nth(1);
if let Some(Expression {
expr: Expr::MatchBlock(matches),
..
}) = block
{
for match_ in matches {
let mut match_variables = vec![];
if match_.0.match_value(&value, &mut match_variables) {
// This case does match, go ahead and return the evaluated expression
for match_variable in match_variables {
stack.add_var(match_variable.0, match_variable.1);
}
if let Some(block_id) = match_.1.as_block() {
let block = engine_state.get_block(block_id);
return eval_block(
engine_state,
stack,
block,
input,
call.redirect_stdout,
call.redirect_stderr,
);
} else {
return eval_expression_with_input(
engine_state,
stack,
&match_.1,
input,
call.redirect_stdout,
call.redirect_stderr,
)
.map(|x| x.0);
}
}
}
}
Ok(PipelineData::Empty)
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Match on a value in range",
example: "match 3 { 1..10 => 'yes!' }",
result: Some(Value::test_string("yes!")),
},
Example {
description: "Match on a field in a record",
example: "match {a: 100} { {a: $my_value} => { $my_value } }",
result: Some(Value::test_int(100)),
},
Example {
description: "Match with a catch-all",
example: "match 3 { 1 => { 'yes!' }, _ => { 'no!' } }",
result: Some(Value::test_string("no!")),
},
Example {
description: "Match against a list",
example: "match [1, 2, 3] { [$a, $b, $c] => { $a + $b + $c }, _ => 0 }",
result: Some(Value::test_int(6)),
},
Example {
description: "Match against pipeline input",
example: "{a: {b: 3}} | match $in {{a: { $b }} => ($b + 10) }",
result: Some(Value::test_int(13)),
},
]
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(Match {})
}
}

View File

@ -1,5 +1,6 @@
mod alias;
mod break_;
mod collect;
mod commandline;
mod const_;
mod continue_;
@ -20,6 +21,7 @@ mod for_;
pub mod help;
pub mod help_aliases;
pub mod help_commands;
pub mod help_externs;
pub mod help_modules;
mod help_operators;
mod hide;
@ -28,6 +30,7 @@ mod if_;
mod ignore;
mod let_;
mod loop_;
mod match_;
mod module;
mod mut_;
pub(crate) mod overlay;
@ -39,6 +42,7 @@ mod while_;
pub use alias::Alias;
pub use break_::Break;
pub use collect::Collect;
pub use commandline::Commandline;
pub use const_::Const;
pub use continue_::Continue;
@ -59,6 +63,7 @@ pub use for_::For;
pub use help::Help;
pub use help_aliases::HelpAliases;
pub use help_commands::HelpCommands;
pub use help_externs::HelpExterns;
pub use help_modules::HelpModules;
pub use help_operators::HelpOperators;
pub use hide::Hide;
@ -67,6 +72,7 @@ pub use if_::If;
pub use ignore::Ignore;
pub use let_::Let;
pub use loop_::Loop;
pub use match_::Match;
pub use module::Module;
pub use mut_::Mut;
pub use overlay::*;

View File

@ -22,7 +22,7 @@ impl Command for Mut {
.required("var_name", SyntaxShape::VarWithOptType, "variable name")
.required(
"initial_value",
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Expression)),
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::MathExpression)),
"equals sign followed by value",
)
.category(Category::Core)

View File

@ -63,7 +63,7 @@ impl Command for Register {
result: None,
},
Example {
description: "Register `nu_plugin_query` plugin from `nu -c`(plugin will be available in that nu session only)",
description: "Register `nu_plugin_query` plugin from `nu -c` (writes/updates $nu.plugin-path)",
example: r#"let plugin = ((which nu).path.0 | path dirname | path join 'nu_plugin_query'); nu -c $'register ($plugin); version'"#,
result: None,
},

View File

@ -2,8 +2,8 @@ use nu_engine::{eval_block, CallExt};
use nu_protocol::ast::Call;
use nu_protocol::engine::{Block, Closure, Command, EngineState, Stack};
use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Type,
Value,
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape,
Type, Value,
};
#[derive(Clone)]
@ -26,7 +26,10 @@ impl Command for Try {
"catch_block",
SyntaxShape::Keyword(
b"catch".to_vec(),
Box::new(SyntaxShape::Closure(Some(vec![SyntaxShape::Any]))),
Box::new(SyntaxShape::OneOf(vec![
SyntaxShape::Closure(None),
SyntaxShape::Closure(Some(vec![SyntaxShape::Any])),
])),
),
"block to run if try block fails",
)
@ -59,17 +62,13 @@ impl Command for Try {
match result {
Err(error) => {
let error = intercept_block_control(error)?;
let err_value = Value::Error {
error: Box::new(error),
};
handle_catch(err_value, catch_block, engine_state, stack)
let err_record = err_to_record(error, call.head);
handle_catch(err_record, catch_block, engine_state, stack)
}
Ok(PipelineData::Value(Value::Error { error }, ..)) => {
let error = intercept_block_control(*error)?;
let err_value = Value::Error {
error: Box::new(error),
};
handle_catch(err_value, catch_block, engine_state, stack)
let err_record = err_to_record(error, call.head);
handle_catch(err_record, catch_block, engine_state, stack)
}
// external command may fail to run
Ok(pipeline) => {
@ -145,6 +144,19 @@ fn intercept_block_control(error: ShellError) -> Result<ShellError, ShellError>
}
}
/// Convert from `error` to [`Value::Record`] so the error information can be easily accessed in catch.
fn err_to_record(error: ShellError, head: Span) -> Value {
let cols = vec!["msg".to_string(), "debug".to_string(), "raw".to_string()];
let vals = vec![
Value::string(error.to_string(), head),
Value::string(format!("{error:?}"), head),
Value::Error {
error: Box::new(error),
},
];
Value::record(cols, vals, head)
}
#[cfg(test)]
mod test {
use super::*;

View File

@ -21,7 +21,7 @@ impl Command for While {
Signature::build("while")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.allow_variants_without_examples(true)
.required("cond", SyntaxShape::Expression, "condition to check")
.required("cond", SyntaxShape::MathExpression, "condition to check")
.required(
"block",
SyntaxShape::Block,
@ -77,8 +77,7 @@ impl Command for While {
return Err(err);
}
Ok(pipeline) => {
let exit_code =
pipeline.print(engine_state, stack, false, false)?;
let exit_code = pipeline.drain_with_exit_code()?;
if exit_code != 0 {
break;
}

View File

@ -18,6 +18,7 @@ pub fn create_default_context() -> EngineState {
bind_command! {
Alias,
Break,
Collect,
Commandline,
Const,
Continue,
@ -39,6 +40,7 @@ pub fn create_default_context() -> EngineState {
HelpAliases,
HelpCommands,
HelpModules,
HelpExterns,
HelpOperators,
Hide,
HideEnv,
@ -51,6 +53,7 @@ pub fn create_default_context() -> EngineState {
OverlayHide,
Let,
Loop,
Match,
Module,
Mut,
Return,

View File

@ -13,7 +13,7 @@ mod test_examples {
check_example_evaluates_to_expected_output,
check_example_input_and_output_types_match_command_signature,
};
use crate::{Break, Describe, Mut};
use crate::{Break, Collect, Describe, Mut};
use crate::{Echo, If, Let};
use nu_protocol::{
engine::{Command, EngineState, StateWorkingSet},
@ -66,6 +66,7 @@ mod test_examples {
working_set.add_decl(Box::new(If));
working_set.add_decl(Box::new(Let));
working_set.add_decl(Box::new(Mut));
working_set.add_decl(Box::new(Collect));
// Adding the command that is being tested to the working set
working_set.add_decl(cmd);

View File

@ -5,7 +5,7 @@ repository = "https://github.com/nushell/nushell/tree/main/crates/nu-color-confi
edition = "2021"
license = "MIT"
name = "nu-color-config"
version = "0.77.0"
version = "0.78.0"
[lib]
bench = false
@ -15,11 +15,11 @@ serde = { version="1.0.123", features=["derive"] }
# used only for text_style Alignments
tabled = { version = "0.10.0", features = ["color"], default-features = false }
nu-protocol = { path = "../nu-protocol", version = "0.77.0" }
nu-protocol = { path = "../nu-protocol", version = "0.78.0" }
nu-ansi-term = "0.47.0"
nu-utils = { path = "../nu-utils", version = "0.77.0" }
nu-engine = { path = "../nu-engine", version = "0.77.0" }
nu-json = { path="../nu-json", version = "0.77.0" }
nu-utils = { path = "../nu-utils", version = "0.78.0" }
nu-engine = { path = "../nu-engine", version = "0.78.0" }
nu-json = { path="../nu-json", version = "0.78.0" }
[dev-dependencies]
nu-test-support = { path="../nu-test-support", version = "0.77.0" }
nu-test-support = { path="../nu-test-support", version = "0.78.0" }

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2019 - 2022 The Nushell Project Developers
Copyright (c) 2019 - 2023 The Nushell Project Developers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -20,22 +20,26 @@ impl From<Style> for NuStyle {
}
fn style_get_attr(s: Style) -> Option<String> {
macro_rules! check {
($attrs:expr, $b:expr, $c:expr) => {
if $b {
$attrs.push($c);
}
};
}
let mut attrs = String::new();
check!(attrs, s.is_blink, 'l');
check!(attrs, s.is_bold, 'b');
check!(attrs, s.is_dimmed, 'd');
check!(attrs, s.is_reverse, 'r');
check!(attrs, s.is_strikethrough, 's');
check!(attrs, s.is_underline, 'u');
if s.is_blink {
attrs.push('l');
};
if s.is_bold {
attrs.push('b');
};
if s.is_dimmed {
attrs.push('d');
};
if s.is_reverse {
attrs.push('r');
};
if s.is_strikethrough {
attrs.push('s');
};
if s.is_underline {
attrs.push('u');
};
if attrs.is_empty() {
None

View File

@ -23,6 +23,7 @@ pub fn default_shape_color(shape: String) -> Style {
"shape_internalcall" => Style::new().fg(Color::Cyan).bold(),
"shape_list" => Style::new().fg(Color::Cyan).bold(),
"shape_literal" => Style::new().fg(Color::Blue),
"shape_match_pattern" => Style::new().fg(Color::Green),
"shape_nothing" => Style::new().fg(Color::LightCyan),
"shape_operator" => Style::new().fg(Color::Yellow),
"shape_or" => Style::new().fg(Color::Purple).bold(),

View File

@ -21,13 +21,6 @@ pub enum ComputableStyle {
Closure(Value),
}
// macro used for adding initial values to the style hashmap
macro_rules! initial {
($a:expr, $b:expr) => {
($a.to_string(), ComputableStyle::Static($b))
};
}
// An alias for the mapping used internally by StyleComputer.
pub type StyleMapping = HashMap<String, ComputableStyle>;
//
@ -153,6 +146,12 @@ impl<'a> StyleComputer<'a> {
pub fn from_config(engine_state: &'a EngineState, stack: &'a Stack) -> StyleComputer<'a> {
let config = engine_state.get_config();
macro_rules! initial {
($a:expr, $b:expr) => {
($a.to_string(), ComputableStyle::Static($b))
};
}
// Create the hashmap
let mut map: StyleMapping = HashMap::from([
initial!("separator", Color::White.normal()),

View File

@ -5,7 +5,7 @@ edition = "2021"
license = "MIT"
name = "nu-command"
repository = "https://github.com/nushell/nushell/tree/main/crates/nu-command"
version = "0.77.0"
version = "0.78.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -13,27 +13,27 @@ version = "0.77.0"
bench = false
[dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.77.0" }
nu-color-config = { path = "../nu-color-config", version = "0.77.0" }
nu-engine = { path = "../nu-engine", version = "0.77.0" }
nu-explore = { path = "../nu-explore", version = "0.77.0" }
nu-glob = { path = "../nu-glob", version = "0.77.0" }
nu-json = { path = "../nu-json", version = "0.77.0" }
nu-parser = { path = "../nu-parser", version = "0.77.0" }
nu-path = { path = "../nu-path", version = "0.77.0" }
nu-pretty-hex = { path = "../nu-pretty-hex", version = "0.77.0" }
nu-protocol = { path = "../nu-protocol", version = "0.77.0" }
nu-system = { path = "../nu-system", version = "0.77.0" }
nu-table = { path = "../nu-table", version = "0.77.0" }
nu-term-grid = { path = "../nu-term-grid", version = "0.77.0" }
nu-utils = { path = "../nu-utils", version = "0.77.0" }
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.78.0" }
nu-color-config = { path = "../nu-color-config", version = "0.78.0" }
nu-engine = { path = "../nu-engine", version = "0.78.0" }
nu-explore = { path = "../nu-explore", version = "0.78.0" }
nu-glob = { path = "../nu-glob", version = "0.78.0" }
nu-json = { path = "../nu-json", version = "0.78.0" }
nu-parser = { path = "../nu-parser", version = "0.78.0" }
nu-path = { path = "../nu-path", version = "0.78.0" }
nu-pretty-hex = { path = "../nu-pretty-hex", version = "0.78.0" }
nu-protocol = { path = "../nu-protocol", version = "0.78.0" }
nu-system = { path = "../nu-system", version = "0.78.0" }
nu-table = { path = "../nu-table", version = "0.78.0" }
nu-term-grid = { path = "../nu-term-grid", version = "0.78.0" }
nu-utils = { path = "../nu-utils", version = "0.78.0" }
num-format = { version = "0.4.3" }
nu-ansi-term = "0.47.0"
# Potential dependencies for extras
Inflector = "0.11"
alphanumeric-sort = "1.4.4"
alphanumeric-sort = "1.5.0"
atty = "0.2.14"
base64 = "0.21.0"
byteorder = "1.4.3"
@ -60,16 +60,17 @@ itertools = "0.10.0"
log = "0.4.14"
lscolors = { version = "0.12.0", features = ["crossterm"], default-features = false }
md5 = { package = "md-5", version = "0.10.0" }
miette = { version = "5.6.0", features = ["fancy-no-backtrace"] }
mime = "0.3.16"
mime_guess = "2.0.4"
notify = "4.0.17"
num = { version = "0.4.0", optional = true }
num-traits = "0.2.14"
once_cell = "1.17"
open = "3.2.0"
open = "4.0.0"
pathdiff = "0.2.1"
powierza-coefficient = "1.0.2"
quick-xml = "0.27"
quick-xml = "0.28"
rand = "0.8"
rayon = "1.7.0"
regex = "1.7.1"
@ -84,9 +85,9 @@ serde_yaml = "0.9.4"
sha2 = "0.10.0"
# Disable default features b/c the default features build Git (very slow to compile)
percent-encoding = "2.2.0"
reedline = { version = "0.17.0", features = ["bashisms", "sqlite"] }
reedline = { version = "0.18.0", features = ["bashisms", "sqlite"] }
rusqlite = { version = "0.28.0", features = ["bundled"], optional = true }
sqlparser = { version = "0.30.0", features = ["serde"], optional = true }
sqlparser = { version = "0.32.0", features = ["serde"], optional = true }
sysinfo = "0.28.2"
tabled = "0.10.0"
terminal_size = "0.2.1"
@ -146,7 +147,7 @@ version = "0.27.2"
[target.'cfg(windows)'.dependencies.windows]
features = ["Win32_Foundation", "Win32_Storage_FileSystem", "Win32_System_SystemServices"]
version = "0.44.0"
version = "0.46.0"
[features]
dataframe = ["num", "polars", "sqlparser"]
@ -156,12 +157,11 @@ trash-support = ["trash"]
which-support = ["which"]
[dev-dependencies]
nu-test-support = { path = "../nu-test-support", version = "0.77.0" }
mockito = "0.32.3"
nu-test-support = { path = "../nu-test-support", version = "0.78.0" }
mockito = "1.0.0"
dirs-next = "2.0.0"
hamcrest2 = "0.3.0"
proptest = "1.1.0"
quickcheck = "1.0.3"
quickcheck_macros = "1.0.0"
rstest = { version = "0.16.0", default-features = false }
rstest = { version = "0.17.0", default-features = false }

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2019 - 2022 The Nushell Project Developers
Copyright (c) 2019 - 2023 The Nushell Project Developers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,23 +0,0 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 96a80ecd19729fb43a7b7bb2766b37d6083ba73b16abb97075875e3cfcdc763f # shrinks to c = '"'
cc 4146602559ea717a02bcef3c6d73cdf613c30d0c3f92c48e26c79b9a1544e027 # shrinks to c = '\\'
cc 80532a0ee73df456a719b9e3cce1ae5f3d26009dde819cbaf16f8e0cb6709705 # shrinks to c = ':'
cc cdb88505686eea3c74c36f282fd29b2b68bc118ded4ebfc36f9838d174bd7653 # shrinks to c = '`'
cc 0f534d55f9771e8810b9c4252a4168abfaec1a35e1b0cac12dbaf726d295a08c # shrinks to c = '\0'
cc 5d31bcbab722acd1f4e23ca3a4f95ff309a636b45a73ca8ae9f820d93ff57acc # shrinks to c = '{'
cc 5afec063bc96160d681d77f90041b67ef5cfdea4dcbd12d984fd828fbeb4b421 # shrinks to c = '#'
cc f919beb3ee5c70e756a15635d65ded7d44f3ae58b5e86b6c09e814d5d8cdd506 # shrinks to c = ';'
cc ec00f39b8d45dfd8808947a56af5e50ba5a0ef7c951723b45377815a02e515b1 # shrinks to c = '('
cc 25b773cdf4c24179151fa86244c7de4136e05df9e94e6ee77a336ebfd8764444 # shrinks to c = '|'
cc 94dc0d54b97d59e1c0f4cb11bdccb3823a1bb908cbc3fd643ee8f067169fad72 # shrinks to c = '0'
cc c9d0051fb1e5a8bdc1d4f5a3dceac1b4b465827d1dff4fc3a3755baae6a7bb48 # shrinks to c = '$'
cc 14ec40d2eb5bd2663e9b11bb49fb2120852f9ea71678c69d732161412b55a3ec # shrinks to s = ""
cc d4afccc51ed9d421bdb7e1723e273dfb6e77c3a449489671a496db234e87c5ed # shrinks to c = '\r'
cc 515a56d73eb1b69290ef4c714b629421989879aebd57991bd2c2bf11294353b1 # shrinks to s = "\\\\𐊀{"
cc 111566990fffa432acd2dbc845141b0e7870f97125c7621e3ddf142204568246 # shrinks to s = "'\":`"
cc 0424c33000d9188be96b3049046eb052770b2158bf5ebb0c98656d7145e8aca9 # shrinks to s = "0"

View File

@ -90,7 +90,7 @@ impl Command for SubCommand {
Example {
description:
"Apply logical negation to a list of numbers, treat input as 2 bytes number",
example: "[4 3 2] | bits not -n 2",
example: "[4 3 2] | bits not -n '2'",
result: Some(Value::List {
vals: vec![
Value::test_int(65531),

View File

@ -85,7 +85,7 @@ impl Command for SubCommand {
},
Example {
description: "Rotate right a list of numbers of one byte",
example: "[15 33 92] | bits ror 2 -n 1",
example: "[15 33 92] | bits ror 2 -n '1'",
result: Some(Value::List {
vals: vec![
Value::test_int(195),

View File

@ -85,7 +85,7 @@ impl Command for SubCommand {
},
Example {
description: "Shift left a number with 1 byte by 7 bits",
example: "2 | bits shl 7 -n 1",
example: "2 | bits shl 7 -n '1'",
result: Some(Value::test_int(0)),
},
Example {

View File

@ -1,20 +1,19 @@
use crate::input_handler::{operate, CmdArgument};
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::ast::CellPath;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
use crate::{
input_handler::{operate, CmdArgument},
util,
};
use nu_engine::CallExt;
use nu_protocol::{
ast::{Call, CellPath},
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, Range, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use std::cmp::Ordering;
#[derive(Clone)]
pub struct BytesAt;
struct Arguments {
start: isize,
end: isize,
arg_span: Span,
indexes: Subbytes,
cell_paths: Option<Vec<CellPath>>,
}
@ -24,104 +23,15 @@ impl CmdArgument for Arguments {
}
}
/// ensure given `range` is valid, and returns [start, end, val_span] pair.
fn parse_range(range: Value, head: Span) -> Result<(isize, isize, Span), ShellError> {
let (start, end, span) = match range {
Value::List { mut vals, span } => {
if vals.len() != 2 {
return Err(ShellError::UnsupportedInput(
"More than two indices in range".to_string(),
"value originates from here".to_string(),
head,
span,
));
} else {
let end = vals.pop().expect("Already check has size 2");
let end = match end {
Value::Int { val, .. } => val.to_string(),
Value::String { val, .. } => val,
// Explicitly propagate errors instead of dropping them.
Value::Error { error } => return Err(*error),
other => {
return Err(ShellError::UnsupportedInput(
"Only string or list<int> ranges are supported".into(),
format!("input type: {:?}", other.get_type()),
head,
other.expect_span(),
))
impl From<(isize, isize)> for Subbytes {
fn from(input: (isize, isize)) -> Self {
Self(input.0, input.1)
}
};
let start = vals.pop().expect("Already check has size 1");
let start = match start {
Value::Int { val, .. } => val.to_string(),
Value::String { val, .. } => val,
// Explicitly propagate errors instead of dropping them.
Value::Error { error } => return Err(*error),
other => {
return Err(ShellError::UnsupportedInput(
"Only string or list<int> ranges are supported".into(),
format!("input type: {:?}", other.get_type()),
head,
other.expect_span(),
))
}
};
(start, end, span)
}
}
Value::String { val, span } => {
let split_result = val.split_once(',');
match split_result {
Some((start, end)) => (start.to_string(), end.to_string(), span),
None => {
return Err(ShellError::UnsupportedInput(
"could not perform subbytes".to_string(),
"with this range".to_string(),
head,
span,
))
}
}
}
// Explicitly propagate errors instead of dropping them.
Value::Error { error } => return Err(*error),
other => {
return Err(ShellError::UnsupportedInput(
"could not perform subbytes".to_string(),
"with this range".to_string(),
head,
other.expect_span(),
))
}
};
let start: isize = if start.is_empty() || start == "_" {
0
} else {
start.trim().parse().map_err(|_| {
ShellError::UnsupportedInput(
"could not perform subbytes".to_string(),
"with this range".to_string(),
head,
span,
)
})?
};
let end: isize = if end.is_empty() || end == "_" {
isize::max_value()
} else {
end.trim().parse().map_err(|_| {
ShellError::UnsupportedInput(
"could not perform subbytes".to_string(),
"with this range".to_string(),
head,
span,
)
})?
};
Ok((start, end, span))
}
#[derive(Clone, Copy)]
struct Subbytes(isize, isize);
impl Command for BytesAt {
fn name(&self) -> &str {
"bytes at"
@ -131,7 +41,7 @@ impl Command for BytesAt {
Signature::build("bytes at")
.input_output_types(vec![(Type::Binary, Type::Binary)])
.vectorizes_over_list(true)
.required("range", SyntaxShape::Any, "the indexes to get bytes")
.required("range", SyntaxShape::Range, "the range to get bytes")
.rest(
"rest",
SyntaxShape::CellPath,
@ -141,7 +51,7 @@ impl Command for BytesAt {
}
fn usage(&self) -> &str {
"Get bytes defined by a range. Note that the start is included but the end is excluded, and that the first byte is index 0."
"Get bytes defined by a range"
}
fn search_terms(&self) -> Vec<&str> {
@ -155,48 +65,45 @@ impl Command for BytesAt {
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let range: Value = call.req(engine_state, stack, 0)?;
let (start, end, arg_span) = parse_range(range, call.head)?;
let range: Range = call.req(engine_state, stack, 0)?;
let indexes = match util::process_range(&range) {
Ok(idxs) => idxs.into(),
Err(processing_error) => {
return Err(processing_error("could not perform subbytes", call.head));
}
};
let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 1)?;
let cell_paths = (!cell_paths.is_empty()).then_some(cell_paths);
let arg = Arguments {
start,
end,
arg_span,
let args = Arguments {
indexes,
cell_paths,
};
operate(at, arg, input, call.head, engine_state.ctrlc.clone())
operate(action, args, input, call.head, engine_state.ctrlc.clone())
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Get a subbytes `0x[10 01]` from the bytes `0x[33 44 55 10 01 13]`",
example: " 0x[33 44 55 10 01 13] | bytes at [3 4]",
example: " 0x[33 44 55 10 01 13] | bytes at 3..<4",
result: Some(Value::Binary {
val: vec![0x10],
span: Span::test_data(),
}),
},
Example {
description: "Alternatively, you can use the form",
example: " 0x[33 44 55 10 01 13] | bytes at '3,4'",
description: "Get a subbytes `0x[10 01 13]` from the bytes `0x[33 44 55 10 01 13]`",
example: " 0x[33 44 55 10 01 13] | bytes at 3..6",
result: Some(Value::Binary {
val: vec![0x10],
span: Span::test_data(),
}),
},
Example {
description: "Drop the last `n` characters from the string",
example: " 0x[33 44 55 10 01 13] | bytes at ',-3'",
result: Some(Value::Binary {
val: vec![0x33, 0x44, 0x55],
val: vec![0x10, 0x01, 0x13],
span: Span::test_data(),
}),
},
Example {
description: "Get the remaining characters from a starting index",
example: " 0x[33 44 55 10 01 13] | bytes at '3,'",
example: " 0x[33 44 55 10 01 13] | bytes at 3..",
result: Some(Value::Binary {
val: vec![0x10, 0x01, 0x13],
span: Span::test_data(),
@ -204,7 +111,7 @@ impl Command for BytesAt {
},
Example {
description: "Get the characters from the beginning until ending index",
example: " 0x[33 44 55 10 01 13] | bytes at ',4'",
example: " 0x[33 44 55 10 01 13] | bytes at ..<4",
result: Some(Value::Binary {
val: vec![0x33, 0x44, 0x55, 0x10],
span: Span::test_data(),
@ -213,7 +120,7 @@ impl Command for BytesAt {
Example {
description:
"Or the characters from the beginning until ending index inside a table",
example: r#" [[ColA ColB ColC]; [0x[11 12 13] 0x[14 15 16] 0x[17 18 19]]] | bytes at "1," ColB ColC"#,
example: r#" [[ColA ColB ColC]; [0x[11 12 13] 0x[14 15 16] 0x[17 18 19]]] | bytes at 1.. ColB ColC"#,
result: Some(Value::List {
vals: vec![Value::Record {
cols: vec!["ColA".to_string(), "ColB".to_string(), "ColC".to_string()],
@ -240,73 +147,66 @@ impl Command for BytesAt {
}
}
fn at(val: &Value, args: &Arguments, span: Span) -> Value {
match val {
Value::Binary {
val,
span: val_span,
} => at_impl(val, args, *val_span),
// Propagate errors by explicitly matching them before the final case.
Value::Error { .. } => val.clone(),
other => Value::Error {
error: Box::new(ShellError::OnlySupportsThisInputType {
exp_input_type: "binary".into(),
wrong_type: other.get_type().to_string(),
dst_span: span,
src_span: other.expect_span(),
}),
},
}
}
fn action(input: &Value, args: &Arguments, head: Span) -> Value {
let range = &args.indexes;
match input {
Value::Binary { val, .. } => {
use std::cmp::{self, Ordering};
let len = val.len() as isize;
fn at_impl(input: &[u8], arg: &Arguments, span: Span) -> Value {
let len: isize = input.len() as isize;
let start = if range.0 < 0 { range.0 + len } else { range.0 };
let start: isize = if arg.start < 0 {
arg.start + len
let end = if range.1 < 0 {
cmp::max(range.1 + len, 0)
} else {
arg.start
};
let end: isize = if arg.end < 0 {
std::cmp::max(len + arg.end, 0)
} else {
arg.end
range.1
};
if start < len && end >= 0 {
match start.cmp(&end) {
Ordering::Equal => Value::Binary { val: vec![], span },
Ordering::Equal => Value::Binary {
val: vec![],
span: head,
},
Ordering::Greater => Value::Error {
error: Box::new(ShellError::TypeMismatch {
err_message: "End must be greater than or equal to Start".to_string(),
span: arg.arg_span,
span: head,
}),
},
Ordering::Less => Value::Binary {
val: {
let input_iter = input.iter().copied().skip(start as usize);
if end == isize::max_value() {
input_iter.collect()
val.iter().skip(start as usize).copied().collect()
} else {
input_iter.take((end - start) as usize).collect()
val.iter()
.skip(start as usize)
.take((end - start) as usize)
.copied()
.collect()
}
},
span,
span: head,
},
}
} else {
Value::Binary { val: vec![], span }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(BytesAt {})
Value::Binary {
val: vec![],
span: head,
}
}
}
Value::Error { .. } => input.clone(),
other => Value::Error {
error: Box::new(ShellError::UnsupportedInput(
"Only binary values are supported".into(),
format!("input type: {:?}", other.get_type()),
head,
// This line requires the Value::Error match above.
other.expect_span(),
)),
},
}
}

View File

@ -49,12 +49,12 @@ impl Command for BytesLen {
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Return the lengths of multiple strings",
description: "Return the length of a binary",
example: "0x[1F FF AA AB] | bytes length",
result: Some(Value::test_int(4)),
},
Example {
description: "Return the lengths of multiple strings",
description: "Return the lengths of multiple binaries",
example: "[0x[1F FF AA AB] 0x[1F]] | bytes length",
result: Some(Value::List {
vals: vec![Value::test_int(4), Value::test_int(1)],

View File

@ -240,7 +240,11 @@ mod test {
},
Value::CellPath {
val: CellPath {
members: vec![PathMember::Int { val: 0, span }],
members: vec![PathMember::Int {
val: 0,
span,
optional: false,
}],
},
span,
},

View File

@ -98,11 +98,17 @@ impl Command for Histogram {
let frequency_name_arg = call.opt::<Spanned<String>>(engine_state, stack, 1)?;
let frequency_column_name = match frequency_name_arg {
Some(inner) => {
if ["value", "count", "quantile", "percentage"].contains(&inner.item.as_str()) {
let forbidden_column_names = ["value", "count", "quantile", "percentage"];
if forbidden_column_names.contains(&inner.item.as_str()) {
return Err(ShellError::TypeMismatch {
err_message:
"frequency-column-name can't be 'value', 'count' or 'percentage'"
.to_string(),
err_message: format!(
"frequency-column-name can't be {}",
forbidden_column_names
.iter()
.map(|val| format!("'{}'", val))
.collect::<Vec<_>>()
.join(", ")
),
span: inner.span,
});
}

View File

@ -105,7 +105,7 @@ impl Command for Fill {
Example {
description:
"Fill a number on the left side to a width of 5 with the character '0'",
example: "1 | fill --alignment right --character 0 --width 5",
example: "1 | fill --alignment right --character '0' --width 5",
result: Some(Value::String {
val: "00001".into(),
span: Span::test_data(),
@ -113,7 +113,7 @@ impl Command for Fill {
},
Example {
description: "Fill a number on both sides to a width of 5 with the character '0'",
example: "1.1 | fill --alignment center --character 0 --width 5",
example: "1.1 | fill --alignment center --character '0' --width 5",
result: Some(Value::String {
val: "01.10".into(),
span: Span::test_data(),
@ -122,7 +122,7 @@ impl Command for Fill {
Example {
description:
"Fill a filesize on the left side to a width of 5 with the character '0'",
example: "1kib | fill --alignment middle --character 0 --width 10",
example: "1kib | fill --alignment middle --character '0' --width 10",
result: Some(Value::String {
val: "0001024000".into(),
span: Span::test_data(),

View File

@ -145,6 +145,30 @@ impl Command for SubCommand {
span,
}),
},
Example {
description: "Convert µs duration to the requested duration as a string",
example: "1000000µs | into duration --convert sec",
result: Some(Value::String {
val: "1 sec".to_string(),
span,
}),
},
Example {
description: "Convert duration to the µs duration as a string",
example: "1sec | into duration --convert µs",
result: Some(Value::String {
val: "1000000 µs".to_string(),
span,
}),
},
Example {
description: "Convert duration to µs as a string if unit asked for was us",
example: "1sec | into duration --convert us",
result: Some(Value::String {
val: "1000000 µs".to_string(),
span,
}),
},
]
}
}
@ -197,6 +221,8 @@ fn convert_str_from_unit_to_unit(
match (from_unit, to_unit) {
("ns", "ns") => Ok(val as f64),
("ns", "us") => Ok(val as f64 / 1000.0),
("ns", "µs") => Ok(val as f64 / 1000.0), // Micro sign
("ns", "μs") => Ok(val as f64 / 1000.0), // Greek small letter
("ns", "ms") => Ok(val as f64 / 1000.0 / 1000.0),
("ns", "sec") => Ok(val as f64 / 1000.0 / 1000.0 / 1000.0),
("ns", "min") => Ok(val as f64 / 1000.0 / 1000.0 / 1000.0 / 60.0),
@ -211,6 +237,8 @@ fn convert_str_from_unit_to_unit(
("us", "ns") => Ok(val as f64 * 1000.0),
("us", "us") => Ok(val as f64),
("us", "µs") => Ok(val as f64), // Micro sign
("us", "μs") => Ok(val as f64), // Greek small letter
("us", "ms") => Ok(val as f64 / 1000.0),
("us", "sec") => Ok(val as f64 / 1000.0 / 1000.0),
("us", "min") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0),
@ -221,8 +249,40 @@ fn convert_str_from_unit_to_unit(
("us", "yr") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0 / 60.0 / 24.0 / 365.0),
("us", "dec") => Ok(val as f64 / 10.0 / 1000.0 / 1000.0 / 60.0 / 60.0 / 24.0 / 365.0),
// Micro sign
("µs", "ns") => Ok(val as f64 * 1000.0),
("µs", "us") => Ok(val as f64),
("µs", "µs") => Ok(val as f64), // Micro sign
("µs", "μs") => Ok(val as f64), // Greek small letter
("µs", "ms") => Ok(val as f64 / 1000.0),
("µs", "sec") => Ok(val as f64 / 1000.0 / 1000.0),
("µs", "min") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0),
("µs", "hr") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0 / 60.0),
("µs", "day") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0 / 60.0 / 24.0),
("µs", "wk") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0 / 60.0 / 24.0 / 7.0),
("µs", "month") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0 / 60.0 / 24.0 / 30.0),
("µs", "yr") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0 / 60.0 / 24.0 / 365.0),
("µs", "dec") => Ok(val as f64 / 10.0 / 1000.0 / 1000.0 / 60.0 / 60.0 / 24.0 / 365.0),
// Greek small letter
("μs", "ns") => Ok(val as f64 * 1000.0),
("μs", "us") => Ok(val as f64),
("μs", "µs") => Ok(val as f64), // Micro sign
("μs", "μs") => Ok(val as f64), // Greek small letter
("μs", "ms") => Ok(val as f64 / 1000.0),
("μs", "sec") => Ok(val as f64 / 1000.0 / 1000.0),
("μs", "min") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0),
("μs", "hr") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0 / 60.0),
("μs", "day") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0 / 60.0 / 24.0),
("μs", "wk") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0 / 60.0 / 24.0 / 7.0),
("μs", "month") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0 / 60.0 / 24.0 / 30.0),
("μs", "yr") => Ok(val as f64 / 1000.0 / 1000.0 / 60.0 / 60.0 / 24.0 / 365.0),
("μs", "dec") => Ok(val as f64 / 10.0 / 1000.0 / 1000.0 / 60.0 / 60.0 / 24.0 / 365.0),
("ms", "ns") => Ok(val as f64 * 1000.0 * 1000.0),
("ms", "us") => Ok(val as f64 * 1000.0),
("ms", "µs") => Ok(val as f64 * 1000.0), // Micro sign
("ms", "μs") => Ok(val as f64 * 1000.0), // Greek small letter
("ms", "ms") => Ok(val as f64),
("ms", "sec") => Ok(val as f64 / 1000.0),
("ms", "min") => Ok(val as f64 / 1000.0 / 60.0),
@ -235,6 +295,8 @@ fn convert_str_from_unit_to_unit(
("sec", "ns") => Ok(val as f64 * 1000.0 * 1000.0 * 1000.0),
("sec", "us") => Ok(val as f64 * 1000.0 * 1000.0),
("sec", "µs") => Ok(val as f64 * 1000.0 * 1000.0), // Micro sign
("sec", "μs") => Ok(val as f64 * 1000.0 * 1000.0), // Greek small letter
("sec", "ms") => Ok(val as f64 * 1000.0),
("sec", "sec") => Ok(val as f64),
("sec", "min") => Ok(val as f64 / 60.0),
@ -247,6 +309,8 @@ fn convert_str_from_unit_to_unit(
("min", "ns") => Ok(val as f64 * 1000.0 * 1000.0 * 1000.0 * 60.0),
("min", "us") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0),
("min", "µs") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0), // Micro sign
("min", "μs") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0), // Greek small letter
("min", "ms") => Ok(val as f64 * 1000.0 * 60.0),
("min", "sec") => Ok(val as f64 * 60.0),
("min", "min") => Ok(val as f64),
@ -259,6 +323,8 @@ fn convert_str_from_unit_to_unit(
("hr", "ns") => Ok(val as f64 * 1000.0 * 1000.0 * 1000.0 * 60.0 * 60.0),
("hr", "us") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0),
("hr", "µs") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0), // Micro sign
("hr", "μs") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0), // Greek small letter
("hr", "ms") => Ok(val as f64 * 1000.0 * 60.0 * 60.0),
("hr", "sec") => Ok(val as f64 * 60.0 * 60.0),
("hr", "min") => Ok(val as f64 * 60.0),
@ -271,6 +337,8 @@ fn convert_str_from_unit_to_unit(
("day", "ns") => Ok(val as f64 * 1000.0 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0),
("day", "us") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0),
("day", "µs") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0), // Micro sign
("day", "μs") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0), // Greek small letter
("day", "ms") => Ok(val as f64 * 1000.0 * 60.0 * 60.0 * 24.0),
("day", "sec") => Ok(val as f64 * 60.0 * 60.0 * 24.0),
("day", "min") => Ok(val as f64 * 60.0 * 24.0),
@ -283,6 +351,8 @@ fn convert_str_from_unit_to_unit(
("wk", "ns") => Ok(val as f64 * 1000.0 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0 * 7.0),
("wk", "us") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0 * 7.0),
("wk", "µs") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0 * 7.0), // Micro sign
("wk", "μs") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0 * 7.0), // Greek small letter
("wk", "ms") => Ok(val as f64 * 1000.0 * 60.0 * 60.0 * 24.0 * 7.0),
("wk", "sec") => Ok(val as f64 * 60.0 * 60.0 * 24.0 * 7.0),
("wk", "min") => Ok(val as f64 * 60.0 * 24.0 * 7.0),
@ -295,6 +365,8 @@ fn convert_str_from_unit_to_unit(
("month", "ns") => Ok(val as f64 * 1000.0 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0 * 30.0),
("month", "us") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0 * 30.0),
("month", "µs") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0 * 30.0), // Micro sign
("month", "μs") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0 * 30.0), // Greek small letter
("month", "ms") => Ok(val as f64 * 1000.0 * 60.0 * 60.0 * 24.0 * 30.0),
("month", "sec") => Ok(val as f64 * 60.0 * 60.0 * 24.0 * 30.0),
("month", "min") => Ok(val as f64 * 60.0 * 24.0 * 30.0),
@ -307,6 +379,8 @@ fn convert_str_from_unit_to_unit(
("yr", "ns") => Ok(val as f64 * 1000.0 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0 * 365.0),
("yr", "us") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0 * 365.0),
("yr", "µs") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0 * 365.0), // Micro sign
("yr", "μs") => Ok(val as f64 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0 * 365.0), // Greek small letter
("yr", "ms") => Ok(val as f64 * 1000.0 * 60.0 * 60.0 * 24.0 * 365.0),
("yr", "sec") => Ok(val as f64 * 60.0 * 60.0 * 24.0 * 365.0),
("yr", "min") => Ok(val as f64 * 60.0 * 24.0 * 365.0),
@ -324,7 +398,7 @@ fn convert_str_from_unit_to_unit(
dst_span: span,
src_span: value_span,
help: Some(
"supported units are ns, us, ms, sec, min, hr, day, wk, month, yr and dec"
"supported units are ns, us/µs, ms, sec, min, hr, day, wk, month, yr, and dec"
.to_string(),
),
}),
@ -357,7 +431,8 @@ fn string_to_duration(s: &str, span: Span, value_span: Span) -> Result<i64, Shel
dst_span: span,
src_span: value_span,
help: Some(
"supported units are ns, us, ms, sec, min, hr, day, wk, month, yr and dec".to_string(),
"supported units are ns, us/µs, ms, sec, min, hr, day, wk, month, yr, and dec"
.to_string(),
),
})
}
@ -372,7 +447,7 @@ fn string_to_unit_duration(
if let Expr::Int(x) = value.expr {
match unit.item {
Unit::Nanosecond => return Ok(("ns", x)),
Unit::Microsecond => return Ok(("us", x)),
Unit::Microsecond => return Ok(("µs", x)),
Unit::Millisecond => return Ok(("ms", x)),
Unit::Second => return Ok(("sec", x)),
Unit::Minute => return Ok(("min", x)),
@ -393,7 +468,8 @@ fn string_to_unit_duration(
dst_span: span,
src_span: value_span,
help: Some(
"supported units are ns, us, ms, sec, min, hr, day, wk, month, yr and dec".to_string(),
"supported units are ns, us/µs, ms, sec, min, hr, day, wk, month, yr, and dec"
.to_string(),
),
})
}
@ -420,14 +496,19 @@ fn action(
*value_span,
) {
Ok(d) => {
let unit = if &to_unit.item == "us" {
"µs"
} else {
&to_unit.item
};
if d.fract() == 0.0 {
Value::String {
val: format!("{} {}", d, &to_unit.item),
val: format!("{} {}", d, unit),
span: *value_span,
}
} else {
Value::String {
val: format!("{:.float_precision$} {}", d, &to_unit.item),
val: format!("{:.float_precision$} {}", d, unit),
span: *value_span,
}
}
@ -454,14 +535,19 @@ fn action(
*value_span,
) {
Ok(d) => {
let unit = if &to_unit.item == "us" {
"µs"
} else {
&to_unit.item
};
if d.fract() == 0.0 {
Value::String {
val: format!("{} {}", d, &to_unit.item),
val: format!("{} {}", d, unit),
span: *value_span,
}
} else {
Value::String {
val: format!("{:.float_precision$} {}", d, &to_unit.item),
val: format!("{:.float_precision$} {}", d, unit),
span: *value_span,
}
}
@ -536,6 +622,34 @@ mod test {
assert_eq!(actual, expected);
}
#[test]
fn turns_micro_sign_s_to_duration() {
let span = Span::new(0, 2);
let word = Value::test_string("4\u{00B5}s");
let expected = Value::Duration {
val: 4 * 1000,
span,
};
let convert_duration = None;
let actual = action(&word, &convert_duration, 2, span);
assert_eq!(actual, expected);
}
#[test]
fn turns_mu_s_to_duration() {
let span = Span::new(0, 2);
let word = Value::test_string("4\u{03BC}s");
let expected = Value::Duration {
val: 4 * 1000,
span,
};
let convert_duration = None;
let actual = action(&word, &convert_duration, 2, span);
assert_eq!(actual, expected);
}
#[test]
fn turns_ms_to_duration() {
let span = Span::new(0, 2);

View File

@ -270,6 +270,7 @@ fn nu_value_to_string(value: Value, separator: &str) -> String {
Value::Binary { val, .. } => format!("{val:?}"),
Value::CellPath { val, .. } => val.into_string(),
Value::CustomValue { val, .. } => val.value_string(),
Value::MatchPattern { val, .. } => format!("{:?}", val),
}
}

View File

@ -22,7 +22,7 @@ impl Command for OpenDataFrame {
}
fn usage(&self) -> &str {
"Opens csv, json, arrow, or parquet file to create dataframe."
"Opens CSV, JSON, arrow, or parquet file to create dataframe."
}
fn signature(&self) -> Signature {

View File

@ -19,7 +19,7 @@ impl Command for ToCSV {
}
fn usage(&self) -> &str {
"Saves dataframe to csv file."
"Saves dataframe to CSV file."
}
fn signature(&self) -> Signature {
@ -40,12 +40,12 @@ impl Command for ToCSV {
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Saves dataframe to csv file",
description: "Saves dataframe to CSV file",
example: "[[a b]; [1 2] [3 4]] | dfr into-df | dfr to-csv test.csv",
result: None,
},
Example {
description: "Saves dataframe to csv file using other delimiter",
description: "Saves dataframe to CSV file using other delimiter",
example: "[[a b]; [1 2] [3 4]] | dfr into-df | dfr to-csv test.csv -d '|'",
result: None,
},

View File

@ -76,7 +76,8 @@ impl Command for Debug {
},
Example {
description: "Debug print a table",
example: "[[version patch]; [0.1.0 false] [0.1.1 true] [0.2.0 false]] | debug",
example:
"[[version patch]; ['0.1.0' false] ['0.1.1' true] ['0.2.0' false]] | debug",
result: Some(Value::List {
vals: vec![
Value::test_string("{version: 0.1.0, patch: false}"),

View File

@ -328,5 +328,6 @@ pub fn debug_string_without_formatting(value: &Value) -> String {
Value::Binary { val, .. } => format!("{val:?}"),
Value::CellPath { val, .. } => val.into_string(),
Value::CustomValue { val, .. } => val.value_string(),
Value::MatchPattern { val, .. } => format!("{:?}", val),
}
}

View File

@ -7,8 +7,9 @@ use tabled::{
};
use self::{
global_horizontal_char::SetHorizontalChar, peak2::Peak2, table_column_width::GetColumnWidths,
truncate_table::TruncateTable, width_increase::IncWidth,
global_horizontal_char::SetHorizontalCharOnFirstRow, peak2::Peak2,
table_column_width::get_first_cell_width, truncate_table::TruncateTable,
width_increase::IncWidth,
};
pub fn build_table(value: Value, description: String, termsize: usize) -> String {
@ -23,7 +24,8 @@ pub fn build_table(value: Value, description: String, termsize: usize) -> String
let mut desc_table = Builder::from(desc).build();
let desc_table_width = desc_table.total_width();
let width = val_table_width.clamp(desc_table_width, termsize);
#[allow(clippy::manual_clamp)]
let width = val_table_width.max(desc_table_width).min(termsize);
desc_table
.with(Style::rounded().off_bottom())
@ -36,10 +38,11 @@ pub fn build_table(value: Value, description: String, termsize: usize) -> String
.with(Wrap::new(width).priority::<PriorityMax>())
.with(IncWidth(width));
let mut desc_widths = GetColumnWidths(Vec::new());
desc_table.with(&mut desc_widths);
// we use only 1, cause left border considered 0 position
let count_split_lines = 1;
let desc_width = get_first_cell_width(&mut desc_table) + count_split_lines;
val_table.with(SetHorizontalChar::new('┼', '┴', 0, desc_widths.0[0]));
val_table.with(SetHorizontalCharOnFirstRow::new('┼', '┴', desc_width));
format!("{desc_table}\n{val_table}")
}
@ -136,7 +139,7 @@ mod util {
let mut columns = get_columns(&vals);
let data = convert_records_to_dataset(&columns, vals);
if columns.is_empty() && !data.is_empty() {
if columns.is_empty() {
columns = vec![String::from("")];
}
@ -208,10 +211,11 @@ mod util {
let path = PathMember::String {
val: header.to_owned(),
span: Span::unknown(),
optional: false,
};
item.clone()
.follow_cell_path(&[path], false, false)
.follow_cell_path(&[path], false)
.unwrap_or_else(|_| item.clone())
}
item => item.clone(),
@ -260,18 +264,30 @@ mod peak2 {
}
mod table_column_width {
use tabled::papergrid::{records::Records, Estimate};
use tabled::{
papergrid::{records::Records, width::CfgWidthFunction},
Table,
};
pub struct GetColumnWidths(pub Vec<usize>);
pub fn get_first_cell_width<R: Records>(table: &mut Table<R>) -> usize {
let mut opt = GetFirstCellWidth(0);
table.with(&mut opt);
opt.0
}
impl<R> tabled::TableOption<R> for GetColumnWidths
where
R: Records,
{
struct GetFirstCellWidth(pub usize);
impl<R: Records> tabled::TableOption<R> for GetFirstCellWidth {
fn change(&mut self, table: &mut tabled::Table<R>) {
let mut evaluator = tabled::papergrid::width::WidthEstimator::default();
evaluator.estimate(table.get_records(), table.get_config());
self.0 = evaluator.into();
let w = table
.get_records()
.get_width((0, 0), CfgWidthFunction::default());
let pad = table
.get_config()
.get_padding(tabled::papergrid::Entity::Cell(0, 0));
let pad = pad.left.size + pad.right.size;
self.0 = w + pad;
}
}
}
@ -282,91 +298,65 @@ mod global_horizontal_char {
Table, TableOption,
};
pub struct SetHorizontalChar {
pub struct SetHorizontalCharOnFirstRow {
c1: char,
c2: char,
line: usize,
position: usize,
pos: usize,
}
impl SetHorizontalChar {
pub fn new(c1: char, c2: char, line: usize, position: usize) -> Self {
Self {
c1,
c2,
line,
position,
}
impl SetHorizontalCharOnFirstRow {
pub fn new(c1: char, c2: char, pos: usize) -> Self {
Self { c1, c2, pos }
}
}
impl<R> TableOption<R> for SetHorizontalChar
impl<R> TableOption<R> for SetHorizontalCharOnFirstRow
where
R: Records,
{
fn change(&mut self, table: &mut Table<R>) {
let shape = table.shape();
let is_last_line = self.line == (shape.0 * 2);
let mut row = self.line;
if is_last_line {
row = self.line - 1;
if table.is_empty() {
return;
}
let shape = table.shape();
let mut evaluator = WidthEstimator::default();
evaluator.estimate(table.get_records(), table.get_config());
let widths: Vec<_> = evaluator.into();
let mut i = 0;
#[allow(clippy::needless_range_loop)]
for column in 0..shape.1 {
let has_vertical = table.get_config().has_vertical(column, shape.1);
if has_vertical {
if self.position == i {
let mut border = table.get_config().get_border((row, column), shape);
if is_last_line {
border.left_bottom_corner = Some(self.c1);
} else {
let has_vertical = table.get_config().has_vertical(0, shape.1);
if has_vertical && self.pos == 0 {
let mut border = table.get_config().get_border((0, 0), shape);
border.left_top_corner = Some(self.c1);
table.get_config_mut().set_border((0, 0), border);
return;
}
table.get_config_mut().set_border((row, column), border);
let mut i = 1;
#[allow(clippy::needless_range_loop)]
for (col, width) in widths.into_iter().enumerate() {
if self.pos < i + width {
let o = self.pos - i;
table
.get_config_mut()
.override_horizontal_border((0, col), self.c2, Begin(o));
return;
}
i += width;
let has_vertical = table.get_config().has_vertical(col, shape.1);
if has_vertical {
if self.pos == i {
let mut border = table.get_config().get_border((0, col), shape);
border.right_top_corner = Some(self.c1);
table.get_config_mut().set_border((0, col), border);
return;
}
i += 1;
}
let width = widths[column];
if self.position < i + width {
let offset = self.position + 1 - i;
// let offset = width - offset;
table.get_config_mut().override_horizontal_border(
(self.line, column),
self.c2,
Begin(offset),
);
return;
}
i += width;
}
let has_vertical = table.get_config().has_vertical(shape.1, shape.1);
if self.position == i && has_vertical {
let mut border = table.get_config().get_border((row, shape.1), shape);
if is_last_line {
border.left_bottom_corner = Some(self.c1);
} else {
border.left_top_corner = Some(self.c1);
}
table.get_config_mut().set_border((row, shape.1), border);
}
}
}

View File

@ -1,7 +1,7 @@
use nu_engine::{eval_block, CallExt};
use nu_engine::{eval_block, eval_expression_with_input};
use nu_protocol::{
ast::Call,
engine::{Closure, Command, EngineState, Stack},
engine::{Command, EngineState, Stack},
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Type,
Value,
};
@ -16,15 +16,15 @@ impl Command for TimeIt {
}
fn usage(&self) -> &str {
"Time the running time of a closure."
"Time the running time of a block."
}
fn signature(&self) -> nu_protocol::Signature {
Signature::build("timeit")
.required(
"closure",
SyntaxShape::Closure(Some(vec![SyntaxShape::Any])),
"the closure to run",
"command",
SyntaxShape::OneOf(vec![SyntaxShape::Block, SyntaxShape::Expression]),
"the command or block to run",
)
.input_output_types(vec![
(Type::Any, Type::Duration),
@ -45,37 +45,36 @@ impl Command for TimeIt {
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let capture_block: Closure = call.req(engine_state, stack, 0)?;
let block = engine_state.get_block(capture_block.block_id);
let redirect_stdout = call.redirect_stdout;
let redirect_stderr = call.redirect_stderr;
let mut stack = stack.captures_to_stack(&capture_block.captures);
// In order to provide the pipeline as a positional, it must be converted into a value.
// But because pipelines do not have Clone, this one has to be cloned as a value
// and then converted back into a pipeline for eval_block().
// So, the metadata must be saved here and restored at that point.
let input_metadata = input.metadata();
let input_val = input.into_value(call.head);
if let Some(var) = block.signature.get_positional(0) {
if let Some(var_id) = &var.var_id {
stack.add_var(*var_id, input_val.clone());
}
}
let command_to_run = call.positional_nth(0);
// Get the start time after all other computation has been done.
let start_time = Instant::now();
if let Some(command_to_run) = command_to_run {
if let Some(block_id) = command_to_run.as_block() {
let block = engine_state.get_block(block_id);
eval_block(
engine_state,
&mut stack,
stack,
block,
input_val.into_pipeline_data_with_metadata(input_metadata),
redirect_stdout,
redirect_stderr,
input,
call.redirect_stdout,
call.redirect_stderr,
)?
} else {
eval_expression_with_input(
engine_state,
stack,
command_to_run,
input,
call.redirect_stdout,
call.redirect_stderr,
)
.map(|res| res.0)?
}
} else {
PipelineData::empty()
}
.into_value(call.head);
let end_time = Instant::now();
@ -100,6 +99,11 @@ impl Command for TimeIt {
example: "http get https://www.nushell.sh/book/ | timeit { split chars }",
result: None,
},
Example {
description: "Times a command invocation",
example: "timeit ls -la",
result: None,
},
]
}
}
@ -107,11 +111,11 @@ impl Command for TimeIt {
#[test]
// Due to difficulty in observing side-effects from time closures,
// checks that the closures have run correctly must use the filesystem.
fn test_time_closure() {
fn test_time_block() {
use nu_test_support::{nu, nu_repl_code, playground::Playground};
Playground::setup("test_time_closure", |dirs, _| {
Playground::setup("test_time_block", |dirs, _| {
let inp = [
r#"[2 3 4] | timeit { to nuon | save foo.txt }"#,
r#"[2 3 4] | timeit {to nuon | save foo.txt }"#,
"open foo.txt",
];
let actual_repl = nu!(cwd: dirs.test(), nu_repl_code(&inp));
@ -121,11 +125,11 @@ fn test_time_closure() {
}
#[test]
fn test_time_closure_2() {
fn test_time_block_2() {
use nu_test_support::{nu, nu_repl_code, playground::Playground};
Playground::setup("test_time_closure", |dirs, _| {
Playground::setup("test_time_block", |dirs, _| {
let inp = [
r#"[2 3 4] | timeit {|e| {result: $e} | to nuon | save foo.txt }"#,
r#"[2 3 4] | timeit {{result: $in} | to nuon | save foo.txt }"#,
"open foo.txt",
];
let actual_repl = nu!(cwd: dirs.test(), nu_repl_code(&inp));

View File

@ -36,7 +36,6 @@ pub fn create_default_context() -> EngineState {
All,
Any,
Append,
Collect,
Columns,
Compact,
Default,
@ -57,6 +56,7 @@ pub fn create_default_context() -> EngineState {
GroupBy,
Headers,
Insert,
Join,
SplitBy,
Take,
Merge,
@ -168,6 +168,8 @@ pub fn create_default_context() -> EngineState {
Encode,
DecodeBase64,
EncodeBase64,
DecodeHex,
EncodeHex,
DetectColumns,
Format,
FileSize,
@ -181,7 +183,6 @@ pub fn create_default_context() -> EngineState {
Str,
StrCamelCase,
StrCapitalize,
StrCollect,
StrContains,
StrDistance,
StrDowncase,
@ -386,6 +387,7 @@ pub fn create_default_context() -> EngineState {
MathPi,
MathTau,
MathEuler,
MathExp,
MathLn,
MathLog,
};
@ -440,17 +442,18 @@ pub fn create_default_context() -> EngineState {
// Deprecated
bind_command! {
ExportOldAlias,
HashBase64,
LPadDeprecated,
RPadDeprecated,
Source,
StrDatetimeDeprecated,
StrDecimalDeprecated,
StrIntDeprecated,
StrFindReplaceDeprecated,
MathEvalDeprecated,
OldAlias,
ExportOldAlias,
RPadDeprecated,
Source,
StrCollectDeprecated,
StrDatetimeDeprecated,
StrDecimalDeprecated,
StrFindReplaceDeprecated,
StrIntDeprecated,
};
working_set.render()
@ -460,5 +463,9 @@ pub fn create_default_context() -> EngineState {
eprintln!("Error creating default context: {err:?}");
}
// Cache the table decl id so we don't have to look it up later
let table_decl_id = engine_state.find_decl("table".as_bytes(), &[]);
engine_state.table_decl_id = table_decl_id;
engine_state
}

View File

@ -0,0 +1,34 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, PipelineData, ShellError, Signature};
#[derive(Clone)]
pub struct StrCollectDeprecated;
impl Command for StrCollectDeprecated {
fn name(&self) -> &str {
"str collect"
}
fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Deprecated)
}
fn usage(&self) -> &str {
"Deprecated command."
}
fn run(
&self,
_: &EngineState,
_: &mut Stack,
call: &Call,
_: PipelineData,
) -> Result<PipelineData, ShellError> {
Err(nu_protocol::ShellError::DeprecatedCommand(
self.name().to_string(),
"str join".to_owned(),
call.head,
))
}
}

View File

@ -23,5 +23,6 @@ pub fn deprecated_commands() -> HashMap<String, String> {
("str lpad".to_string(), "fill".to_string()),
("str rpad".to_string(), "fill".to_string()),
("benchmark".to_string(), "timeit".to_string()),
("str collect".to_string(), "str join".to_string()),
])
}

View File

@ -1,3 +1,4 @@
mod collect;
mod deprecated_commands;
mod export_old_alias;
mod hash_base64;
@ -11,6 +12,7 @@ mod str_decimal;
mod str_find_replace;
mod str_int;
pub use collect::StrCollectDeprecated;
pub use deprecated_commands::*;
pub use export_old_alias::ExportOldAlias;
pub use hash_base64::HashBase64;

View File

@ -35,10 +35,7 @@ pub(crate) fn get_editor(
if let Some((a, b)) = editor.split_once(' ') {
Ok((
a.to_string(),
b.split(' ')
.into_iter()
.map(|s| s.to_string())
.collect::<Vec<String>>(),
b.split(' ').map(|s| s.to_string()).collect::<Vec<String>>(),
))
} else {
Ok((editor, Vec::new()))

View File

@ -24,7 +24,7 @@ impl Command for LetEnv {
.required("var_name", SyntaxShape::String, "variable name")
.required(
"initial_value",
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Expression)),
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::MathExpression)),
"equals sign followed by value",
)
.category(Category::Env)

View File

@ -129,7 +129,7 @@ impl Command for Ls {
));
}
if is_empty_dir(&expanded) {
return Ok(Value::nothing(call_span).into_pipeline_data());
return Ok(Value::list(vec![], call_span).into_pipeline_data());
}
p.push("*");
}
@ -141,7 +141,7 @@ impl Command for Ls {
if directory {
(PathBuf::from("."), call_span, false)
} else if is_empty_dir(current_dir(engine_state, stack)?) {
return Ok(Value::nothing(call_span).into_pipeline_data());
return Ok(Value::list(vec![], call_span).into_pipeline_data());
} else {
(PathBuf::from("./*"), call_span, false)
}

View File

@ -87,8 +87,8 @@ impl Command for Mv {
if sources.is_empty() {
return Err(ShellError::GenericError(
"Invalid file or pattern".into(),
"invalid file or pattern".into(),
"File(s) not found".into(),
"could not find any files matching this glob pattern".into(),
Some(spanned_source.span),
None,
Vec::new(),

View File

@ -1,10 +1,10 @@
use nu_engine::{eval_block, CallExt};
use nu_engine::{current_dir, eval_block, CallExt};
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::util::BufferedReader;
use nu_protocol::{
Category, Example, PipelineData, RawStream, ShellError, Signature, Spanned, SyntaxShape, Type,
Value,
Category, Example, IntoInterruptiblePipelineData, PipelineData, RawStream, ShellError,
Signature, Spanned, SyntaxShape, Type, Value,
};
use std::io::BufReader;
@ -38,6 +38,11 @@ impl Command for Open {
Signature::build("open")
.input_output_types(vec![(Type::Nothing, Type::Any), (Type::String, Type::Any)])
.optional("filename", SyntaxShape::Filepath, "the filename to use")
.rest(
"filenames",
SyntaxShape::Filepath,
"optional additional files to open",
)
.switch("raw", "open file as raw binary", Some('r'))
.category(Category::FileSystem)
}
@ -52,24 +57,16 @@ impl Command for Open {
let raw = call.has_flag("raw");
let call_span = call.head;
let ctrlc = engine_state.ctrlc.clone();
let path = call.opt::<Spanned<String>>(engine_state, stack, 0)?;
let cwd = current_dir(engine_state, stack)?;
let req_path = call.opt::<Spanned<String>>(engine_state, stack, 0)?;
let mut path_params = call.rest::<Spanned<String>>(engine_state, stack, 1)?;
let path = {
if let Some(path_val) = path {
Some(Spanned {
item: nu_utils::strip_ansi_string_unlikely(path_val.item),
span: path_val.span,
})
} else {
path
}
};
// FIXME: JT: what is this doing here?
let path = if let Some(path) = path {
path
if let Some(filename) = req_path {
path_params.insert(0, filename);
} else {
// Collect a filename from the input
match input {
let filename = match input {
PipelineData::Value(Value::Nothing { .. }, ..) => {
return Err(ShellError::MissingParameter {
param_name: "needs filename".to_string(),
@ -83,11 +80,28 @@ impl Command for Open {
span: call.head,
});
}
};
path_params.insert(0, filename);
}
let mut output = vec![];
for path in path_params.into_iter() {
//FIXME: `open` should not have to do this
let path = {
Spanned {
item: nu_utils::strip_ansi_string_unlikely(path.item),
span: path.span,
}
};
let arg_span = path.span;
let path_no_whitespace = &path.item.trim_end_matches(|x| matches!(x, '\x09'..='\x0d'));
let path = Path::new(path_no_whitespace);
// let path_no_whitespace = &path.item.trim_end_matches(|x| matches!(x, '\x09'..='\x0d'));
for path in nu_engine::glob_from(&path, &cwd, call_span, None)?.1 {
let path = path?;
let path = Path::new(&path);
if permission_denied(path) {
#[cfg(unix)]
@ -101,13 +115,13 @@ impl Command for Open {
#[cfg(not(unix))]
let error_msg = String::from("Permission denied");
Err(ShellError::GenericError(
return Err(ShellError::GenericError(
"Permission denied".into(),
error_msg,
Some(arg_span),
None,
Vec::new(),
))
));
} else {
#[cfg(feature = "sqlite")]
if !raw {
@ -134,10 +148,10 @@ impl Command for Open {
let buf_reader = BufReader::new(file);
let output = PipelineData::ExternalStream {
let file_contents = PipelineData::ExternalStream {
stdout: Some(RawStream::new(
Box::new(BufferedReader { input: buf_reader }),
ctrlc,
ctrlc.clone(),
call_span,
None,
)),
@ -159,13 +173,25 @@ impl Command for Open {
match engine_state.find_decl(format!("from {ext}").as_bytes(), &[]) {
Some(converter_id) => {
let decl = engine_state.get_decl(converter_id);
if let Some(block_id) = decl.get_block_id() {
let command_output = if let Some(block_id) = decl.get_block_id() {
let block = engine_state.get_block(block_id);
eval_block(engine_state, stack, block, output, false, false)
eval_block(
engine_state,
stack,
block,
file_contents,
false,
false,
)
} else {
decl.run(engine_state, stack, &Call::new(call_span), output)
}
.map_err(|inner| {
decl.run(
engine_state,
stack,
&Call::new(call_span),
file_contents,
)
};
output.push(command_output.map_err(|inner| {
ShellError::GenericError(
format!("Error while parsing as {ext}"),
format!("Could not parse '{}' with `from {}`", path.display(), ext),
@ -173,15 +199,25 @@ impl Command for Open {
Some(format!("Check out `help from {}` or `help from` for more options or open raw data with `open --raw '{}'`", ext, path.display())),
vec![inner],
)
})
})?);
}
None => Ok(output),
None => output.push(file_contents),
}
} else {
Ok(output)
output.push(file_contents)
}
}
}
}
if output.is_empty() {
Ok(PipelineData::Empty)
} else if output.len() == 1 {
Ok(output.remove(0))
} else {
Ok(output.into_iter().flatten().into_pipeline_data(ctrlc))
}
}
fn examples(&self) -> Vec<nu_protocol::Example> {
vec![

View File

@ -16,7 +16,7 @@ impl Command for Start {
}
fn usage(&self) -> &str {
"Open a folder,file or website in the default application or viewer."
"Open a folder, file or website in the default application or viewer."
}
fn search_terms(&self) -> Vec<&str> {

View File

@ -1,11 +1,11 @@
use nu_engine::{eval_block, CallExt};
use nu_protocol::{
ast::Call,
engine::{Closure, Command, EngineState, Stack},
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Type,
Value,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
};
use super::utils;
#[derive(Clone)]
pub struct All;
@ -45,7 +45,7 @@ impl Command for All {
},
Example {
description: "Check that each item is a string",
example: "[foo bar 2 baz] | all { ($in | describe) == 'string' }",
example: "[foo bar 2 baz] | all {|| ($in | describe) == 'string' }",
result: Some(Value::test_bool(false)),
},
Example {
@ -60,9 +60,7 @@ impl Command for All {
},
]
}
// This is almost entirely a copy-paste of `any`'s run(), so make sure any changes to this are
// reflected in the other!! (Or, you could figure out a way for both of them to use
// the same function...)
fn run(
&self,
engine_state: &EngineState,
@ -70,51 +68,7 @@ impl Command for All {
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let span = call.head;
let capture_block: Closure = call.req(engine_state, stack, 0)?;
let block_id = capture_block.block_id;
let block = engine_state.get_block(block_id);
let var_id = block.signature.get_positional(0).and_then(|arg| arg.var_id);
let mut stack = stack.captures_to_stack(&capture_block.captures);
let orig_env_vars = stack.env_vars.clone();
let orig_env_hidden = stack.env_hidden.clone();
let ctrlc = engine_state.ctrlc.clone();
let engine_state = engine_state.clone();
for value in input.into_interruptible_iter(ctrlc) {
// with_env() is used here to ensure that each iteration uses
// a different set of environment variables.
// Hence, a 'cd' in the first loop won't affect the next loop.
stack.with_env(&orig_env_vars, &orig_env_hidden);
if let Some(var_id) = var_id {
stack.add_var(var_id, value.clone());
}
let eval = eval_block(
&engine_state,
&mut stack,
block,
value.into_pipeline_data(),
call.redirect_stdout,
call.redirect_stderr,
);
match eval {
Err(e) => {
return Err(e);
}
Ok(pipeline_data) => {
if !pipeline_data.into_value(span).is_true() {
return Ok(Value::Bool { val: false, span }.into_pipeline_data());
}
}
}
}
Ok(Value::Bool { val: true, span }.into_pipeline_data())
utils::boolean_fold(engine_state, stack, call, input, false)
}
}

View File

@ -1,11 +1,11 @@
use nu_engine::{eval_block, CallExt};
use nu_protocol::{
ast::Call,
engine::{Closure, Command, EngineState, Stack},
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Type,
Value,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
};
use super::utils;
#[derive(Clone)]
pub struct Any;
@ -45,7 +45,7 @@ impl Command for Any {
},
Example {
description: "Check that any item is a string",
example: "[1 2 3 4] | any { ($in | describe) == 'string' }",
example: "[1 2 3 4] | any {|| ($in | describe) == 'string' }",
result: Some(Value::test_bool(false)),
},
Example {
@ -60,9 +60,7 @@ impl Command for Any {
},
]
}
// This is almost entirely a copy-paste of `all`'s run(), so make sure any changes to this are
// reflected in the other!! Or, you could figure out a way for both of them to use
// the same function...
fn run(
&self,
engine_state: &EngineState,
@ -70,51 +68,7 @@ impl Command for Any {
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let span = call.head;
let capture_block: Closure = call.req(engine_state, stack, 0)?;
let block_id = capture_block.block_id;
let block = engine_state.get_block(block_id);
let var_id = block.signature.get_positional(0).and_then(|arg| arg.var_id);
let mut stack = stack.captures_to_stack(&capture_block.captures);
let orig_env_vars = stack.env_vars.clone();
let orig_env_hidden = stack.env_hidden.clone();
let ctrlc = engine_state.ctrlc.clone();
let engine_state = engine_state.clone();
for value in input.into_interruptible_iter(ctrlc) {
// with_env() is used here to ensure that each iteration uses
// a different set of environment variables.
// Hence, a 'cd' in the first loop won't affect the next loop.
stack.with_env(&orig_env_vars, &orig_env_hidden);
if let Some(var_id) = var_id {
stack.add_var(var_id, value.clone());
}
let eval = eval_block(
&engine_state,
&mut stack,
block,
value.into_pipeline_data(),
call.redirect_stdout,
call.redirect_stderr,
);
match eval {
Err(e) => {
return Err(e);
}
Ok(pipeline_data) => {
if pipeline_data.into_value(span).is_true() {
return Ok(Value::Bool { val: true, span }.into_pipeline_data());
}
}
}
}
Ok(Value::Bool { val: false, span }.into_pipeline_data())
utils::boolean_fold(engine_state, stack, call, input, true)
}
}

View File

@ -109,10 +109,7 @@ fn dropcol(
let mut vals = vec![];
for path in &keep_columns {
let fetcher =
input_val
.clone()
.follow_cell_path(&path.members, false, false)?;
let fetcher = input_val.clone().follow_cell_path(&path.members, false)?;
cols.push(path.into_string());
vals.push(fetcher);
}
@ -136,10 +133,7 @@ fn dropcol(
let mut vals = vec![];
for path in &keep_columns {
let fetcher =
input_val
.clone()
.follow_cell_path(&path.members, false, false)?;
let fetcher = input_val.clone().follow_cell_path(&path.members, false)?;
cols.push(path.into_string());
vals.push(fetcher);
}
@ -155,9 +149,7 @@ fn dropcol(
let mut vals = vec![];
for cell_path in &keep_columns {
let result = v
.clone()
.follow_cell_path(&cell_path.members, false, false)?;
let result = v.clone().follow_cell_path(&cell_path.members, false)?;
cols.push(cell_path.into_string());
vals.push(result);

View File

@ -74,7 +74,7 @@ with 'transpose' first."#
}),
},
Example {
example: "{major:2, minor:1, patch:4} | values | each { into string }",
example: "{major:2, minor:1, patch:4} | values | each {|| into string }",
description: "Produce a list of values in the record, converted to string",
result: Some(Value::List {
vals: vec![

View File

@ -74,7 +74,7 @@ fn empty(
for val in input {
for column in &columns {
let val = val.clone();
match val.follow_cell_path(&column.members, false, false) {
match val.follow_cell_path(&column.members, false) {
Ok(Value::Nothing { .. }) => {}
Ok(_) => return Ok(Value::boolean(false, head).into_pipeline_data()),
Err(err) => return Err(err),

View File

@ -119,7 +119,7 @@ impl Command for Find {
},
Example {
description: "Find value in records",
example: r#"[[version name]; [0.1.0 nushell] [0.1.1 fish] [0.2.0 zsh]] | find -r "nu""#,
example: r#"[[version name]; ['0.1.0' nushell] ['0.1.1' fish] ['0.2.0' zsh]] | find -r "nu""#,
result: Some(Value::List {
vals: vec![Value::test_record(
vec!["version", "name"],
@ -404,6 +404,7 @@ fn find_with_rest_and_highlight(
Err(_) => false,
},
Value::Binary { .. } => false,
Value::MatchPattern { .. } => false,
}) != invert
},
ctrlc,
@ -484,6 +485,7 @@ fn find_with_rest_and_highlight(
Err(_) => false,
},
Value::Binary { .. } => false,
Value::MatchPattern { .. } => false,
}) != invert
}),
ctrlc.clone(),

View File

@ -279,7 +279,7 @@ fn flat_value(columns: &[CellPath], item: &Value, _name_tag: Span, all: bool) ->
if !columns.is_empty() {
let cell_path =
column_requested.and_then(|x| match x.members.first() {
Some(PathMember::String { val, span: _ }) => Some(val),
Some(PathMember::String { val, span: _, .. }) => Some(val),
_ => None,
});

View File

@ -43,7 +43,7 @@ If multiple cell paths are given, this will produce a list of values."#
.rest("rest", SyntaxShape::CellPath, "additional cell paths")
.switch(
"ignore-errors",
"when there are empty cells, instead of erroring out, replace them with nothing",
"ignore missing data (make all cell path members optional)",
Some('i'),
)
.switch(
@ -62,16 +62,20 @@ If multiple cell paths are given, this will produce a list of values."#
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let span = call.head;
let cell_path: CellPath = call.req(engine_state, stack, 0)?;
let mut cell_path: CellPath = call.req(engine_state, stack, 0)?;
let rest: Vec<CellPath> = call.rest(engine_state, stack, 1)?;
let sensitive = call.has_flag("sensitive");
let ignore_errors = call.has_flag("ignore-errors");
let sensitive = call.has_flag("sensitive");
let ctrlc = engine_state.ctrlc.clone();
let metadata = input.metadata();
if ignore_errors {
cell_path.make_optional();
}
if rest.is_empty() {
input
.follow_cell_path(&cell_path.members, call.head, !sensitive, ignore_errors)
.follow_cell_path(&cell_path.members, call.head, !sensitive)
.map(|x| x.into_pipeline_data())
} else {
let mut output = vec![];
@ -81,9 +85,7 @@ If multiple cell paths are given, this will produce a list of values."#
let input = input.into_value(span);
for path in paths {
let val = input
.clone()
.follow_cell_path(&path.members, !sensitive, false);
let val = input.clone().follow_cell_path(&path.members, !sensitive);
output.push(val?);
}

View File

@ -0,0 +1,422 @@
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Config, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use std::cmp::max;
use std::collections::{HashMap, HashSet};
#[derive(Clone)]
pub struct Join;
enum JoinType {
Inner,
Left,
Right,
Outer,
}
enum IncludeInner {
No,
Yes,
}
type RowEntries<'a> = Vec<(&'a Vec<String>, &'a Vec<Value>)>;
const EMPTY_COL_NAMES: &Vec<String> = &vec![];
impl Command for Join {
fn name(&self) -> &str {
"join"
}
fn signature(&self) -> Signature {
Signature::build("join")
.required(
"right-table",
SyntaxShape::List(Box::new(SyntaxShape::Any)),
"The right table in the join",
)
.required(
"left-on",
SyntaxShape::String,
"Name of column in input (left) table to join on",
)
.optional(
"right-on",
SyntaxShape::String,
"Name of column in right table to join on. Defaults to same column as left table.",
)
.switch("inner", "Inner join (default)", Some('i'))
.switch("left", "Left-outer join", Some('l'))
.switch("right", "Right-outer join", Some('r'))
.switch("outer", "Outer join", Some('o'))
.input_output_types(vec![(Type::Table(vec![]), Type::Table(vec![]))])
}
fn usage(&self) -> &str {
"Join two tables"
}
fn search_terms(&self) -> Vec<&str> {
vec!["sql"]
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let table_2: Value = call.req(engine_state, stack, 0)?;
let l_on: Value = call.req(engine_state, stack, 1)?;
let r_on: Value = call
.opt(engine_state, stack, 2)?
.unwrap_or_else(|| l_on.clone());
let span = call.head;
let join_type = join_type(call)?;
// FIXME: we should handle ListStreams properly instead of collecting
let collected_input = input.into_value(span);
match (&collected_input, &table_2, &l_on, &r_on) {
(
Value::List { vals: rows_1, .. },
Value::List { vals: rows_2, .. },
Value::String { val: l_on, .. },
Value::String { val: r_on, .. },
) => {
let result = join(rows_1, rows_2, l_on, r_on, join_type, span);
Ok(PipelineData::Value(result, None))
}
_ => Err(ShellError::UnsupportedInput(
"(PipelineData<table>, table, string, string)".into(),
format!(
"({:?}, {:?}, {:?} {:?})",
collected_input,
table_2.get_type(),
l_on.get_type(),
r_on.get_type(),
),
span,
span,
)),
}
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Join two tables",
example: "[{a: 1 b: 2}] | join [{a: 1 c: 3}] a",
result: Some(Value::List {
vals: vec![Value::Record {
cols: vec!["a".into(), "b".into(), "c".into()],
vals: vec![
Value::Int {
val: 1,
span: Span::test_data(),
},
Value::Int {
val: 2,
span: Span::test_data(),
},
Value::Int {
val: 3,
span: Span::test_data(),
},
],
span: Span::test_data(),
}],
span: Span::test_data(),
}),
}]
}
}
fn join_type(call: &Call) -> Result<JoinType, nu_protocol::ShellError> {
match (
call.has_flag("inner"),
call.has_flag("left"),
call.has_flag("right"),
call.has_flag("outer"),
) {
(_, false, false, false) => Ok(JoinType::Inner),
(false, true, false, false) => Ok(JoinType::Left),
(false, false, true, false) => Ok(JoinType::Right),
(false, false, false, true) => Ok(JoinType::Outer),
_ => Err(ShellError::UnsupportedInput(
"Choose one of: --inner, --left, --right, --outer".into(),
"".into(),
call.head,
call.head,
)),
}
}
fn join(
left: &Vec<Value>,
right: &Vec<Value>,
left_join_key: &str,
right_join_key: &str,
join_type: JoinType,
span: Span,
) -> Value {
// Inner / Right Join
// ------------------
// Make look-up table from rows on left
// For each row r on right:
// If any matching rows on left:
// For each matching row l on left:
// Emit (l, r)
// Else if RightJoin:
// Emit (null, r)
// Left Join
// ----------
// Make look-up table from rows on right
// For each row l on left:
// If any matching rows on right:
// For each matching row r on right:
// Emit (l, r)
// Else:
// Emit (l, null)
// Outer Join
// ----------
// Perform Left Join procedure
// Perform Right Join procedure, but excluding rows in Inner Join
let config = Config::default();
let sep = ",";
let cap = max(left.len(), right.len());
let shared_join_key = if left_join_key == right_join_key {
Some(left_join_key)
} else {
None
};
// For the "other" table, create a map from value in `on` column to a list of the
// rows having that value.
let mut result: Vec<Value> = Vec::new();
let is_outer = matches!(join_type, JoinType::Outer);
let (this, this_join_key, other, other_keys, join_type) = match join_type {
JoinType::Left | JoinType::Outer => (
left,
left_join_key,
lookup_table(right, right_join_key, sep, cap, &config),
column_names(right),
// For Outer we do a Left pass and a Right pass; this is the Left
// pass.
JoinType::Left,
),
JoinType::Inner | JoinType::Right => (
right,
right_join_key,
lookup_table(left, left_join_key, sep, cap, &config),
column_names(left),
join_type,
),
};
join_rows(
&mut result,
this,
this_join_key,
other,
other_keys,
shared_join_key,
&join_type,
IncludeInner::Yes,
sep,
&config,
span,
);
if is_outer {
let (this, this_join_key, other, other_names, join_type) = (
right,
right_join_key,
lookup_table(left, left_join_key, sep, cap, &config),
column_names(left),
JoinType::Right,
);
join_rows(
&mut result,
this,
this_join_key,
other,
other_names,
shared_join_key,
&join_type,
IncludeInner::No,
sep,
&config,
span,
);
}
Value::List { vals: result, span }
}
// Join rows of `this` (a nushell table) to rows of `other` (a lookup-table
// containing rows of a nushell table).
#[allow(clippy::too_many_arguments)]
fn join_rows(
result: &mut Vec<Value>,
this: &Vec<Value>,
this_join_key: &str,
other: HashMap<String, RowEntries>,
other_keys: &Vec<String>,
shared_join_key: Option<&str>,
join_type: &JoinType,
include_inner: IncludeInner,
sep: &str,
config: &Config,
span: Span,
) {
for this_row in this {
if let Value::Record {
cols: this_cols,
vals: this_vals,
..
} = this_row
{
if let Some(this_valkey) = this_row.get_data_by_key(this_join_key) {
if let Some(other_rows) = other.get(&this_valkey.into_string(sep, config)) {
if matches!(include_inner, IncludeInner::Yes) {
for (other_cols, other_vals) in other_rows {
// `other` table contains rows matching `this` row on the join column
let (res_cols, res_vals) = match join_type {
JoinType::Inner | JoinType::Right => merge_records(
(other_cols, other_vals), // `other` (lookup) is the left input table
(this_cols, this_vals),
shared_join_key,
),
JoinType::Left => merge_records(
(this_cols, this_vals), // `this` is the left input table
(other_cols, other_vals),
shared_join_key,
),
_ => panic!("not implemented"),
};
result.push(Value::Record {
cols: res_cols,
vals: res_vals,
span,
})
}
}
} else if !matches!(join_type, JoinType::Inner) {
// `other` table did not contain any rows matching
// `this` row on the join column; emit a single joined
// row with null values for columns not present,
let other_vals = other_keys
.iter()
.map(|key| {
if Some(key.as_ref()) == shared_join_key {
this_row
.get_data_by_key(key)
.unwrap_or_else(|| Value::nothing(span))
} else {
Value::nothing(span)
}
})
.collect();
let (res_cols, res_vals) = match join_type {
JoinType::Inner | JoinType::Right => merge_records(
(other_keys, &other_vals),
(this_cols, this_vals),
shared_join_key,
),
JoinType::Left => merge_records(
(this_cols, this_vals),
(other_keys, &other_vals),
shared_join_key,
),
_ => panic!("not implemented"),
};
result.push(Value::Record {
cols: res_cols,
vals: res_vals,
span,
})
}
} // else { a row is missing a value for the join column }
};
}
}
// Return column names (i.e. ordered keys from the first row; we assume that
// these are the same for all rows).
fn column_names(table: &[Value]) -> &Vec<String> {
table
.iter()
.find_map(|val| match val {
Value::Record { cols, .. } => Some(cols),
_ => None,
})
.unwrap_or(EMPTY_COL_NAMES)
}
// Create a map from value in `on` column to a list of the rows having that
// value.
fn lookup_table<'a>(
rows: &'a Vec<Value>,
on: &str,
sep: &str,
cap: usize,
config: &Config,
) -> HashMap<String, RowEntries<'a>> {
let mut map = HashMap::<String, RowEntries>::with_capacity(cap);
for row in rows {
if let Value::Record { cols, vals, .. } = row {
if let Some(val) = &row.get_data_by_key(on) {
let valkey = val.into_string(sep, config);
map.entry(valkey).or_default().push((cols, vals));
}
};
}
map
}
// Merge `left` and `right` records, renaming keys in `right` where they clash
// with keys in `left`. If `shared_key` is supplied then it is the name of a key
// that should not be renamed (its values are guaranteed to be equal).
fn merge_records(
left: (&Vec<String>, &Vec<Value>),
right: (&Vec<String>, &Vec<Value>),
shared_key: Option<&str>,
) -> (Vec<String>, Vec<Value>) {
let ((l_keys, l_vals), (r_keys, r_vals)) = (left, right);
let cap = max(l_keys.len(), r_keys.len());
let mut seen = HashSet::with_capacity(cap);
let (mut res_keys, mut res_vals) = (Vec::with_capacity(cap), Vec::with_capacity(cap));
for (k, v) in l_keys.iter().zip(l_vals) {
res_keys.push(k.clone());
res_vals.push(v.clone());
seen.insert(k);
}
for (k, v) in r_keys.iter().zip(r_vals) {
let k_seen = seen.contains(k);
let k_shared = shared_key == Some(k);
// Do not output shared join key twice
if !(k_seen && k_shared) {
res_keys.push(if k_seen { format!("{}_", k) } else { k.clone() });
res_vals.push(v.clone());
}
}
(res_keys, res_vals)
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(Join {})
}
}

View File

@ -1,7 +1,6 @@
mod all;
mod any;
mod append;
mod collect;
mod columns;
mod compact;
mod default;
@ -20,6 +19,7 @@ mod group;
mod group_by;
mod headers;
mod insert;
mod join;
mod last;
mod length;
mod lines;
@ -57,7 +57,6 @@ mod zip;
pub use all::All;
pub use any::Any;
pub use append::Append;
pub use collect::Collect;
pub use columns::Columns;
pub use compact::Compact;
pub use default::Default;
@ -76,6 +75,7 @@ pub use group::Group;
pub use group_by::GroupBy;
pub use headers::Headers;
pub use insert::Insert;
pub use join::Join;
pub use last::Last;
pub use length::Length;
pub use lines::Lines;

View File

@ -30,6 +30,12 @@ impl Command for ParEach {
),
(Type::Table(vec![]), Type::List(Box::new(Type::Any))),
])
.named(
"threads",
SyntaxShape::Int,
"the number of threads to use",
Some('t'),
)
.required(
"closure",
SyntaxShape::Closure(Some(vec![SyntaxShape::Any, SyntaxShape::Int])),
@ -85,8 +91,27 @@ impl Command for ParEach {
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let capture_block: Closure = call.req(engine_state, stack, 0)?;
fn create_pool(num_threads: usize) -> Result<rayon::ThreadPool, ShellError> {
match rayon::ThreadPoolBuilder::new()
.num_threads(num_threads)
.build()
{
Err(e) => Err(e).map_err(|e| {
ShellError::GenericError(
"Error creating thread pool".into(),
e.to_string(),
Some(Span::unknown()),
None,
Vec::new(),
)
}),
Ok(pool) => Ok(pool),
}
}
let capture_block: Closure = call.req(engine_state, stack, 0)?;
let threads: Option<usize> = call.get_flag(engine_state, stack, "threads")?;
let max_threads = threads.unwrap_or(0);
let metadata = input.metadata();
let ctrlc = engine_state.ctrlc.clone();
let block_id = capture_block.block_id;
@ -96,8 +121,10 @@ impl Command for ParEach {
match input {
PipelineData::Empty => Ok(PipelineData::Empty),
PipelineData::Value(Value::Range { val, .. }, ..) => Ok(val
.into_range_iter(ctrlc.clone())?
PipelineData::Value(Value::Range { val, .. }, ..) => Ok(create_pool(max_threads)?
.install(|| {
val.into_range_iter(ctrlc.clone())
.expect("unable to create a range iterator")
.par_bridge()
.map(move |x| {
let block = engine_state.get_block(block_id);
@ -129,9 +156,45 @@ impl Command for ParEach {
.collect::<Vec<_>>()
.into_iter()
.flatten()
.into_pipeline_data(ctrlc)),
PipelineData::Value(Value::List { vals: val, .. }, ..) => Ok(val
.into_pipeline_data(ctrlc)
})),
PipelineData::Value(Value::List { vals: val, .. }, ..) => Ok(create_pool(max_threads)?
.install(|| {
val.par_iter()
.map(move |x| {
let block = engine_state.get_block(block_id);
let mut stack = stack.clone();
if let Some(var) = block.signature.get_positional(0) {
if let Some(var_id) = &var.var_id {
stack.add_var(*var_id, x.clone());
}
}
let val_span = x.span();
match eval_block_with_early_return(
engine_state,
&mut stack,
block,
x.clone().into_pipeline_data(),
redirect_stdout,
redirect_stderr,
) {
Ok(v) => v,
Err(error) => Value::Error {
error: Box::new(chain_error_with_input(error, val_span)),
}
.into_pipeline_data(),
}
})
.collect::<Vec<_>>()
.into_iter()
.flatten()
.into_pipeline_data(ctrlc)
})),
PipelineData::ListStream(stream, ..) => Ok(create_pool(max_threads)?.install(|| {
stream
.par_bridge()
.map(move |x| {
let block = engine_state.get_block(block_id);
@ -163,45 +226,14 @@ impl Command for ParEach {
.collect::<Vec<_>>()
.into_iter()
.flatten()
.into_pipeline_data(ctrlc)),
PipelineData::ListStream(stream, ..) => Ok(stream
.par_bridge()
.map(move |x| {
let block = engine_state.get_block(block_id);
let mut stack = stack.clone();
if let Some(var) = block.signature.get_positional(0) {
if let Some(var_id) = &var.var_id {
stack.add_var(*var_id, x.clone());
}
}
let val_span = x.span();
match eval_block_with_early_return(
engine_state,
&mut stack,
block,
x.into_pipeline_data(),
redirect_stdout,
redirect_stderr,
) {
Ok(v) => v,
Err(error) => Value::Error {
error: Box::new(chain_error_with_input(error, val_span)),
}
.into_pipeline_data(),
}
})
.collect::<Vec<_>>()
.into_iter()
.flatten()
.into_pipeline_data(ctrlc)),
.into_pipeline_data(ctrlc)
})),
PipelineData::ExternalStream { stdout: None, .. } => Ok(PipelineData::empty()),
PipelineData::ExternalStream {
stdout: Some(stream),
..
} => Ok(stream
} => Ok(create_pool(max_threads)?.install(|| {
stream
.par_bridge()
.map(move |x| {
let x = match x {
@ -242,10 +274,12 @@ impl Command for ParEach {
.collect::<Vec<_>>()
.into_iter()
.flatten()
.into_pipeline_data(ctrlc)),
.into_pipeline_data(ctrlc)
})),
// This match allows non-iterables to be accepted,
// which is currently considered undesirable (Nov 2022).
PipelineData::Value(x, ..) => {
eprint!("value");
let block = engine_state.get_block(block_id);
if let Some(var) = block.signature.get_positional(0) {

View File

@ -24,7 +24,7 @@ impl Command for Select {
])
.switch(
"ignore-errors",
"when an error occurs, instead of erroring out, suppress the error message",
"ignore missing data (make all cell path members optional)",
Some('i'),
)
.rest(
@ -56,11 +56,17 @@ produce a table, a list will produce a list, and a record will produce a record.
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let columns: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
let span = call.head;
let mut columns: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
let ignore_errors = call.has_flag("ignore-errors");
let span = call.head;
select(engine_state, span, columns, input, ignore_errors)
if ignore_errors {
for cell_path in &mut columns {
cell_path.make_optional();
}
}
select(engine_state, span, columns, input)
}
fn examples(&self) -> Vec<Example> {
@ -97,7 +103,6 @@ fn select(
call_span: Span,
columns: Vec<CellPath>,
input: PipelineData,
ignore_errors: bool,
) -> Result<PipelineData, ShellError> {
let mut unique_rows: HashSet<usize> = HashSet::new();
@ -106,11 +111,8 @@ fn select(
for column in columns {
let CellPath { ref members } = column;
match members.get(0) {
Some(PathMember::Int { val, span }) => {
Some(PathMember::Int { val, span, .. }) => {
if members.len() > 1 {
if ignore_errors {
return Ok(Value::nothing(call_span).into_pipeline_data());
}
return Err(ShellError::GenericError(
"Select only allows row numbers for rows".into(),
"extra after row number".into(),
@ -165,20 +167,14 @@ fn select(
) => {
let mut output = vec![];
let mut columns_with_value = Vec::new();
let mut allempty = true;
for input_val in input_vals {
if !columns.is_empty() {
let mut cols = vec![];
let mut vals = vec![];
for path in &columns {
//FIXME: improve implementation to not clone
match input_val.clone().follow_cell_path(
&path.members,
false,
ignore_errors,
) {
match input_val.clone().follow_cell_path(&path.members, false) {
Ok(fetcher) => {
allempty = false;
cols.push(path.into_string().replace('.', "_"));
vals.push(fetcher);
if !columns_with_value.contains(&path) {
@ -196,15 +192,12 @@ fn select(
output.push(input_val)
}
}
if allempty {
Ok(Value::nothing(call_span).into_pipeline_data())
} else {
Ok(output
.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone())
.set_metadata(metadata))
}
}
PipelineData::ListStream(stream, metadata, ..) => {
let mut values = vec![];
@ -214,10 +207,7 @@ fn select(
let mut vals = vec![];
for path in &columns {
//FIXME: improve implementation to not clone
match x
.clone()
.follow_cell_path(&path.members, false, ignore_errors)
{
match x.clone().follow_cell_path(&path.members, false) {
Ok(value) => {
cols.push(path.into_string().replace('.', "_"));
vals.push(value);
@ -246,10 +236,7 @@ fn select(
for cell_path in columns {
// FIXME: remove clone
match v
.clone()
.follow_cell_path(&cell_path.members, false, ignore_errors)
{
match v.clone().follow_cell_path(&cell_path.members, false) {
Ok(result) => {
cols.push(cell_path.into_string().replace('.', "_"));
vals.push(result);

View File

@ -271,22 +271,12 @@ pub fn sort(
insensitive: bool,
natural: bool,
) -> Result<(), ShellError> {
if vec.is_empty() {
return Err(ShellError::GenericError(
"no values to work with".to_string(),
"".to_string(),
None,
Some("no values to work with".to_string()),
Vec::new(),
));
}
match &vec[0] {
Value::Record {
match vec.first() {
Some(Value::Record {
cols,
vals: _input_vals,
..
} => {
}) => {
let columns = cols.clone();
vec.sort_by(|a, b| process(a, b, &columns, span, insensitive, natural));
}

View File

@ -244,7 +244,7 @@ fn sort_attributes(val: Value) -> Value {
fn generate_key(item: &ValueCounter) -> Result<String, ShellError> {
let value = sort_attributes(item.val_to_compare.clone()); //otherwise, keys could be different for Records
value_to_string(&value, Span::unknown())
value_to_string(&value, Span::unknown(), 0, &None)
}
fn generate_results_with_count(head: Span, uniq_values: Vec<ValueCounter>) -> Vec<Value> {

View File

@ -107,21 +107,11 @@ impl Command for UniqBy {
}
fn validate(vec: Vec<Value>, columns: &Vec<String>, span: Span) -> Result<(), ShellError> {
if vec.is_empty() {
return Err(ShellError::GenericError(
"no values to work with".to_string(),
"".to_string(),
None,
Some("no values to work with".to_string()),
Vec::new(),
));
}
if let Value::Record {
if let Some(Value::Record {
cols,
vals: _input_vals,
span: val_span,
} = &vec[0]
}) = vec.first()
{
if columns.is_empty() {
// This uses the same format as the 'requires a column name' error in split_by.rs

View File

@ -143,7 +143,7 @@ fn update(
ctrlc,
)
} else {
if let Some(PathMember::Int { val, span }) = cell_path.members.get(0) {
if let Some(PathMember::Int { val, span, .. }) = cell_path.members.get(0) {
let mut input = input.into_iter();
let mut pre_elems = vec![];

View File

@ -165,7 +165,7 @@ fn upsert(
ctrlc,
)
} else {
if let Some(PathMember::Int { val, span }) = cell_path.members.get(0) {
if let Some(PathMember::Int { val, span, .. }) = cell_path.members.get(0) {
let mut input = input.into_iter();
let mut pre_elems = vec![];

View File

@ -1,4 +1,9 @@
use nu_protocol::{ShellError, Span};
use nu_engine::{eval_block, CallExt};
use nu_protocol::{
ast::Call,
engine::{Closure, EngineState, Stack},
IntoPipelineData, PipelineData, ShellError, Span, Value,
};
pub fn chain_error_with_input(
error_source: ShellError,
@ -9,3 +14,66 @@ pub fn chain_error_with_input(
}
error_source
}
pub fn boolean_fold(
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
accumulator: bool,
) -> Result<PipelineData, ShellError> {
let span = call.head;
let capture_block: Closure = call.req(engine_state, stack, 0)?;
let block_id = capture_block.block_id;
let block = engine_state.get_block(block_id);
let var_id = block.signature.get_positional(0).and_then(|arg| arg.var_id);
let mut stack = stack.captures_to_stack(&capture_block.captures);
let orig_env_vars = stack.env_vars.clone();
let orig_env_hidden = stack.env_hidden.clone();
let ctrlc = engine_state.ctrlc.clone();
let engine_state = engine_state.clone();
for value in input.into_interruptible_iter(ctrlc) {
// with_env() is used here to ensure that each iteration uses
// a different set of environment variables.
// Hence, a 'cd' in the first loop won't affect the next loop.
stack.with_env(&orig_env_vars, &orig_env_hidden);
if let Some(var_id) = var_id {
stack.add_var(var_id, value.clone());
}
let eval = eval_block(
&engine_state,
&mut stack,
block,
value.into_pipeline_data(),
call.redirect_stdout,
call.redirect_stderr,
);
match eval {
Err(e) => {
return Err(e);
}
Ok(pipeline_data) => {
if pipeline_data.into_value(span).is_true() == accumulator {
return Ok(Value::Bool {
val: accumulator,
span,
}
.into_pipeline_data());
}
}
}
}
Ok(Value::Bool {
val: !accumulator,
span,
}
.into_pipeline_data())
}

View File

@ -1,4 +1,4 @@
use super::delimited::{from_delimited_data, trim_from_str};
use super::delimited::{from_delimited_data, trim_from_str, DelimitedReaderConfig};
use nu_engine::CallExt;
use nu_protocol::ast::Call;
@ -24,11 +24,34 @@ impl Command for FromCsv {
"a character to separate columns, defaults to ','",
Some('s'),
)
.named(
"comment",
SyntaxShape::String,
"a comment character to ignore lines starting with it",
Some('c'),
)
.named(
"quote",
SyntaxShape::String,
"a quote character to ignore separators in strings, defaults to '\"'",
Some('q'),
)
.named(
"escape",
SyntaxShape::String,
"an escape character for strings containing the quote character",
Some('e'),
)
.switch(
"noheaders",
"don't treat the first row as column names",
Some('n'),
)
.switch(
"flexible",
"allow the number of fields in records to be variable",
None,
)
.switch("no-infer", "no field type inferencing", None)
.named(
"trim",
@ -75,28 +98,28 @@ impl Command for FromCsv {
example: "open data.txt | from csv --noheaders",
result: None,
},
Example {
description: "Convert comma-separated data to a table, ignoring headers",
example: "open data.txt | from csv -n",
result: None,
},
Example {
description: "Convert semicolon-separated data to a table",
example: "open data.txt | from csv --separator ';'",
result: None,
},
Example {
description: "Convert semicolon-separated data to a table, dropping all possible whitespaces around header names and field values",
description: "Convert comma-separated data to a table, ignoring lines starting with '#'",
example: "open data.txt | from csv --comment '#'",
result: None,
},
Example {
description: "Convert comma-separated data to a table, dropping all possible whitespaces around header names and field values",
example: "open data.txt | from csv --trim all",
result: None,
},
Example {
description: "Convert semicolon-separated data to a table, dropping all possible whitespaces around header names",
description: "Convert comma-separated data to a table, dropping all possible whitespaces around header names",
example: "open data.txt | from csv --trim headers",
result: None,
},
Example {
description: "Convert semicolon-separated data to a table, dropping all possible whitespaces around field values",
description: "Convert comma-separated data to a table, dropping all possible whitespaces around field values",
example: "open data.txt | from csv --trim fields",
result: None,
},
@ -112,32 +135,41 @@ fn from_csv(
) -> Result<PipelineData, ShellError> {
let name = call.head;
let separator = call
.get_flag(engine_state, stack, "separator")?
.map(|v: Value| v.as_char())
.transpose()?
.unwrap_or(',');
let comment = call
.get_flag(engine_state, stack, "comment")?
.map(|v: Value| v.as_char())
.transpose()?;
let quote = call
.get_flag(engine_state, stack, "quote")?
.map(|v: Value| v.as_char())
.transpose()?
.unwrap_or('"');
let escape = call
.get_flag(engine_state, stack, "escape")?
.map(|v: Value| v.as_char())
.transpose()?;
let no_infer = call.has_flag("no-infer");
let noheaders = call.has_flag("noheaders");
let separator: Option<Value> = call.get_flag(engine_state, stack, "separator")?;
let trim: Option<Value> = call.get_flag(engine_state, stack, "trim")?;
let flexible = call.has_flag("flexible");
let trim = trim_from_str(call.get_flag(engine_state, stack, "trim")?)?;
let sep = match separator {
Some(Value::String { val: s, span }) => {
if s == r"\t" {
'\t'
} else {
let vec_s: Vec<char> = s.chars().collect();
if vec_s.len() != 1 {
return Err(ShellError::MissingParameter {
param_name: "single character separator".into(),
span,
});
};
vec_s[0]
}
}
_ => ',',
let config = DelimitedReaderConfig {
separator,
comment,
quote,
escape,
noheaders,
flexible,
no_infer,
trim,
};
let trim = trim_from_str(trim)?;
from_delimited_data(noheaders, no_infer, sep, trim, input, name)
from_delimited_data(config, input, name)
}
#[cfg(test)]

View File

@ -2,16 +2,26 @@ use csv::{ReaderBuilder, Trim};
use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Span, Value};
fn from_delimited_string_to_value(
DelimitedReaderConfig {
separator,
comment,
quote,
escape,
noheaders,
flexible,
no_infer,
trim,
}: DelimitedReaderConfig,
s: String,
noheaders: bool,
no_infer: bool,
separator: char,
trim: Trim,
span: Span,
) -> Result<Value, csv::Error> {
let mut reader = ReaderBuilder::new()
.has_headers(!noheaders)
.flexible(flexible)
.delimiter(separator as u8)
.comment(comment.map(|c| c as u8))
.quote(quote as u8)
.escape(escape.map(|c| c as u8))
.trim(trim)
.from_reader(s.as_bytes());
@ -56,24 +66,30 @@ fn from_delimited_string_to_value(
Ok(Value::List { vals: rows, span })
}
pub fn from_delimited_data(
noheaders: bool,
no_infer: bool,
sep: char,
trim: Trim,
pub(super) struct DelimitedReaderConfig {
pub separator: char,
pub comment: Option<char>,
pub quote: char,
pub escape: Option<char>,
pub noheaders: bool,
pub flexible: bool,
pub no_infer: bool,
pub trim: Trim,
}
pub(super) fn from_delimited_data(
config: DelimitedReaderConfig,
input: PipelineData,
name: Span,
) -> Result<PipelineData, ShellError> {
let (concat_string, _span, metadata) = input.collect_string_strict(name)?;
Ok(
from_delimited_string_to_value(concat_string, noheaders, no_infer, sep, trim, name)
Ok(from_delimited_string_to_value(config, concat_string, name)
.map_err(|x| ShellError::DelimiterError {
msg: x.to_string(),
span: name,
})?
.into_pipeline_data_with_metadata(metadata),
)
.into_pipeline_data_with_metadata(metadata))
}
pub fn trim_from_str(trim: Option<Value>) -> Result<Trim, ShellError> {

View File

@ -249,6 +249,12 @@ fn convert_to_value(
"extra tokens in input file".into(),
expr.span,
)),
Expr::MatchPattern(..) => Err(ShellError::OutsideSpannedLabeledError(
original_text.to_string(),
"Error when loading".into(),
"extra tokens in input file".into(),
expr.span,
)),
Expr::GlobPattern(val) => Ok(Value::String { val, span }),
Expr::ImportPattern(..) => Err(ShellError::OutsideSpannedLabeledError(
original_text.to_string(),
@ -277,6 +283,12 @@ fn convert_to_value(
Ok(Value::List { vals: output, span })
}
Expr::MatchBlock(..) => Err(ShellError::OutsideSpannedLabeledError(
original_text.to_string(),
"Error when loading".into(),
"match blocks not supported in nuon".into(),
expr.span,
)),
Expr::Nothing => Ok(Value::Nothing { span }),
Expr::Operator(..) => Err(ShellError::OutsideSpannedLabeledError(
original_text.to_string(),

View File

@ -85,15 +85,23 @@ fn parse_aligned_columns<'a>(
.iter()
.enumerate()
.map(|(i, (header_name, start_position))| {
let char_index_start = match l.char_indices().nth(*start_position) {
Some(idx) => idx.0,
None => *start_position,
};
let val = match headers.get(i + 1) {
Some((_, end)) => {
if *end < l.len() {
l.get(*start_position..*end)
let char_index_end = match l.char_indices().nth(*end) {
Some(idx) => idx.0,
None => *end,
};
l.get(char_index_start..char_index_end)
} else {
l.get(*start_position..)
l.get(char_index_start..)
}
}
None => l.get(*start_position..),
None => l.get(char_index_start..),
}
.unwrap_or("")
.trim()

View File

@ -1,4 +1,4 @@
use super::delimited::{from_delimited_data, trim_from_str};
use super::delimited::{from_delimited_data, trim_from_str, DelimitedReaderConfig};
use nu_engine::CallExt;
use nu_protocol::ast::Call;
@ -18,11 +18,34 @@ impl Command for FromTsv {
fn signature(&self) -> Signature {
Signature::build("from tsv")
.input_output_types(vec![(Type::String, Type::Table(vec![]))])
.named(
"comment",
SyntaxShape::String,
"a comment character to ignore lines starting with it",
Some('c'),
)
.named(
"quote",
SyntaxShape::String,
"a quote character to ignore separators in strings, defaults to '\"'",
Some('q'),
)
.named(
"escape",
SyntaxShape::String,
"an escape character for strings containing the quote character",
Some('e'),
)
.switch(
"noheaders",
"don't treat the first row as column names",
Some('n'),
)
.switch(
"flexible",
"allow the number of fields in records to be variable",
None,
)
.switch("no-infer", "no field type inferencing", None)
.named(
"trim",
@ -101,12 +124,36 @@ fn from_tsv(
) -> Result<PipelineData, ShellError> {
let name = call.head;
let comment = call
.get_flag(engine_state, stack, "comment")?
.map(|v: Value| v.as_char())
.transpose()?;
let quote = call
.get_flag(engine_state, stack, "quote")?
.map(|v: Value| v.as_char())
.transpose()?
.unwrap_or('"');
let escape = call
.get_flag(engine_state, stack, "escape")?
.map(|v: Value| v.as_char())
.transpose()?;
let no_infer = call.has_flag("no-infer");
let noheaders = call.has_flag("noheaders");
let trim: Option<Value> = call.get_flag(engine_state, stack, "trim")?;
let trim = trim_from_str(trim)?;
let flexible = call.has_flag("flexible");
let trim = trim_from_str(call.get_flag(engine_state, stack, "trim")?)?;
from_delimited_data(noheaders, no_infer, '\t', trim, input, name)
let config = DelimitedReaderConfig {
separator: '\t',
comment,
quote,
escape,
noheaders,
flexible,
no_infer,
trim,
};
from_delimited_data(config, input, name)
}
#[cfg(test)]

View File

@ -35,10 +35,10 @@ impl Command for FromXml {
fn extra_usage(&self) -> &str {
r#"Every XML entry is represented via a record with tag, attribute and content fields.
To represent different types of entries different values are written to this fields:
1. Tag entry: {tag: <tag name> attrs: {<attr name>: "<string value>" ...} content: [<entries>]}
2. Comment entry: {tag: '!' attrs: null content: "<comment string>"}
3. Processing instruction (PI): {tag: '?<pi name>' attrs: null content: "<pi content string>"}
4. Text: {tag: null attrs: null content: "<text>"}.
1. Tag entry: `{tag: <tag name> attrs: {<attr name>: "<string value>" ...} content: [<entries>]}`
2. Comment entry: `{tag: '!' attrs: null content: "<comment string>"}`
3. Processing instruction (PI): `{tag: '?<pi name>' attrs: null content: "<pi content string>"}`
4. Text: `{tag: null attrs: null content: "<text>"}`.
Unlike to xml command all null values are always present and text is never represented via plain
string. This way content of every tag is always a table and is easier to parse"#
@ -141,7 +141,6 @@ fn element_to_value(n: &roxmltree::Node, info: &ParsingInfo) -> Value {
let content: Vec<Value> = n
.children()
.into_iter()
.filter_map(|node| from_node_to_value(&node, info))
.collect();
let content = Value::list(content, span);
@ -395,7 +394,7 @@ mod tests {
fn parses_empty_element() -> Result<(), roxmltree::Error> {
let source = "<nu></nu>";
assert_eq!(parse(source)?, content_tag("nu", indexmap! {}, &vec![]));
assert_eq!(parse(source)?, content_tag("nu", indexmap! {}, &[]));
Ok(())
}
@ -409,7 +408,7 @@ mod tests {
content_tag(
"nu",
indexmap! {},
&vec![content_string("La era de los tres caballeros")]
&[content_string("La era de los tres caballeros")]
)
);
@ -421,7 +420,7 @@ mod tests {
let source = "\
<nu>
<dev>Andrés</dev>
<dev>Jonathan</dev>
<dev>JT</dev>
<dev>Yehuda</dev>
</nu>";
@ -431,9 +430,9 @@ mod tests {
"nu",
indexmap! {},
&vec![
content_tag("dev", indexmap! {}, &vec![content_string("Andrés")]),
content_tag("dev", indexmap! {}, &vec![content_string("Jonathan")]),
content_tag("dev", indexmap! {}, &vec![content_string("Yehuda")])
content_tag("dev", indexmap! {}, &[content_string("Andrés")]),
content_tag("dev", indexmap! {}, &[content_string("JT")]),
content_tag("dev", indexmap! {}, &[content_string("Yehuda")])
]
)
);
@ -449,7 +448,7 @@ mod tests {
assert_eq!(
parse(source)?,
content_tag("nu", indexmap! {"version" => "2.0"}, &vec![])
content_tag("nu", indexmap! {"version" => "2.0"}, &[])
);
Ok(())
@ -467,10 +466,10 @@ mod tests {
content_tag(
"nu",
indexmap! {"version" => "2.0"},
&vec![content_tag(
&[content_tag(
"version",
indexmap! {},
&vec![content_string("2.0")]
&[content_string("2.0")]
)]
)
);
@ -486,7 +485,7 @@ mod tests {
assert_eq!(
parse(source)?,
content_tag("nu", indexmap! {"version" => "2.0", "age" => "25"}, &vec![])
content_tag("nu", indexmap! {"version" => "2.0", "age" => "25"}, &[])
);
Ok(())

View File

@ -174,6 +174,30 @@ fn convert_yaml_value_to_nu_value(
Value::from(collected)
}
serde_yaml::Value::Tagged(t) => {
let tag = &t.tag;
let value = match &t.value {
serde_yaml::Value::String(s) => {
let val = format!("{} {}", tag, s).trim().to_string();
Value::String { val, span }
}
serde_yaml::Value::Number(n) => {
let val = format!("{} {}", tag, n).trim().to_string();
Value::String { val, span }
}
serde_yaml::Value::Bool(b) => {
let val = format!("{} {}", tag, b).trim().to_string();
Value::String { val, span }
}
serde_yaml::Value::Null => {
let val = format!("{}", tag).trim().to_string();
Value::String { val, span }
}
v => convert_yaml_value_to_nu_value(v, span, val_span)?,
};
value
}
serde_yaml::Value::Null => Value::nothing(span),
x => unimplemented!("Unsupported YAML case: {:?}", x),
})
@ -314,4 +338,63 @@ mod test {
test_examples(FromYaml {})
}
#[test]
fn test_convert_yaml_value_to_nu_value_for_tagged_values() {
struct TestCase {
input: &'static str,
expected: Result<Value, ShellError>,
}
let test_cases: Vec<TestCase> = vec![
TestCase {
input: "Key: !Value ${TEST}-Test-role",
expected: Ok(Value::Record {
cols: vec!["Key".to_string()],
vals: vec![Value::test_string("!Value ${TEST}-Test-role")],
span: Span::test_data(),
}),
},
TestCase {
input: "Key: !Value test-${TEST}",
expected: Ok(Value::Record {
cols: vec!["Key".to_string()],
vals: vec![Value::test_string("!Value test-${TEST}")],
span: Span::test_data(),
}),
},
TestCase {
input: "Key: !Value",
expected: Ok(Value::Record {
cols: vec!["Key".to_string()],
vals: vec![Value::test_string("!Value")],
span: Span::test_data(),
}),
},
TestCase {
input: "Key: !True",
expected: Ok(Value::Record {
cols: vec!["Key".to_string()],
vals: vec![Value::test_string("!True")],
span: Span::test_data(),
}),
},
TestCase {
input: "Key: !123",
expected: Ok(Value::Record {
cols: vec!["Key".to_string()],
vals: vec![Value::test_string("!123")],
span: Span::test_data(),
}),
},
];
for test_case in test_cases {
let doc = serde_yaml::Deserializer::from_str(test_case.input);
let v: serde_yaml::Value = serde_yaml::Value::deserialize(doc.last().unwrap()).unwrap();
let result = convert_yaml_value_to_nu_value(&v, Span::test_data(), Span::test_data());
assert!(result.is_ok());
assert!(result.ok().unwrap() == test_case.expected.ok().unwrap());
}
}
}

Some files were not shown because too many files have changed in this diff Show More