Commit Graph

4963 Commits

Author SHA1 Message Date
Stefan Holderbach
f91713b714
Add format duration to replace into duration --convert (#9788)
# Description
Add `format duration` cmd to choose output unit.

This takes the previous `into duration --convert ...` behavior which
returned a string into its own `format duration` command.
This was suprising and not fitting with the general type signature for
the `into ...` commands.

This command for now lives in the `nu-cmd-extra` nursery.

# User-Facing Changes
## Breaking change
Removes formatting behavior from `into duration`
Now use `format duration` instead of `into duration --convert`
## Usage:
```
1sec | format duration us # Output data in microseconds
"2ms" | into duration | format duration sec # go from string to string
```


# Tests + Formatting
Basic example testing (including basic broadcast)
2023-07-30 22:23:36 +02:00
Darren Schroeder
955de76116
bump to dev version 0.83.2 (#9866)
# Description

This PR bumps the development version of nushell to version 0.83.2.
2023-07-30 22:16:57 +02:00
Jack Wright
bf5bd3ff10
"merging into one dfr into-nu command" (#9858)
- fixes #9806

# Description

Merges ExprAsNu command and ToNu into one command. 

# User-Facing Changes

As both commands were overloading ```dfr into-nu``` there are no user
facing changes

---------

Co-authored-by: Jack Wright <jack.wright@disqo.com>
2023-07-29 15:23:31 -05:00
Stefan Holderbach
6ac3351fd1
Fix signature for math mode (#9846)
This command will always return a list, either because there are
multiple entries with the same frequency or just one.

It's implementation doesn't care about the composition of types as long
as they are number like, can be heterogeneous, will report
independently.

Work for #9812
2023-07-28 23:53:36 +02:00
Stefan Holderbach
b6dafa6e67
Fix math log signature (#9845)
While we are at it also fix `math log` to a more narrow type.

This supersedes part of #9740
2023-07-28 23:47:00 +02:00
Stefan Holderbach
152a541696
Fix signature for math sum (#9847)
This also supports filesize and duration.
Filesize is actually used for a non-running example

Work for #9812
2023-07-28 23:34:47 +02:00
Stefan Holderbach
ff8c3aa356
Fix signature for math abs (#9844)
This only supports number or duration

Make sure duration still works with the stricter type system

Work for #9812
2023-07-28 23:32:59 +02:00
Stefan Holderbach
99ed8e42a3
Fix type signature of median (#9843)
Still support forming the median over homogeneous lists of `Duration` or
`Filesize`. Don't advertise `list<any>` as this can become funky when
given an even number of elements...

Work for #9812
2023-07-28 23:32:26 +02:00
Stefan Holderbach
6a7a23e3fa
Fix math min/max signatures (#9830)
# Description
Under the hood those are just `Value::partial_cmp` and this is defined
for all values and defines a partial order over `any`

Should address part of https://github.com/nushell/nushell/issues/9813

# User-Facing Changes
Reenable all behavior before `0.83`

# Tests + Formatting
Added an example to `math min` showing this cursedness
2023-07-28 15:12:58 -05:00
JT
9448225690
Fix transpose input/output types (#9842)
# Description

As the typechecker doesn't currently support having the same input type
but two different output types, collapse the `transpose` input/output
signatures for now so that we don't mistakenly think that when given a
`table` a `table is always returned.

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

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-29 06:23:17 +12:00
Stefan Holderbach
28b99bfaf7
Narrow signature of math ceil/floor (#9836)
# Description
More narrow attempt than #9740
This doesn't cause issues with the current `test_examples`
infrastructure.
But allows the output of those clearly integer producing commands to be
used with functions declaring `list<int>` or `int`

# User-Facing Changes
see above

# Tests + Formatting
None
2023-07-28 12:31:48 -05:00
Antoine Stevan
8403fff345
allow print to take data as input again (#9823)
related to
https://discord.com/channels/601130461678272522/601130461678272524/1134079115134251129

# Description
before 0.83.0, `print` used to allow piping data into it, e.g.
```nushell
"foo" | print
```
instead of 
```nushell
print "foo"
```

this PR enables the `any -> nothing` input / output type to allow this
again.

i've double checked and `print` is essentially the following snippet
```rust
        if !args.is_empty() {
            for arg in args {
                arg.into_pipeline_data()
                    .print(engine_state, stack, no_newline, to_stderr)?;
            }
        } else if !input.is_nothing() {
            input.print(engine_state, stack, no_newline, to_stderr)?;
        }
```
1. the first part is for `print a b c`
2. the second part is for `"foo" | print`

# User-Facing Changes
```nushell
"foo" | print
```
works again

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

# After Submitting

---------

Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
2023-07-27 21:40:25 +02:00
Antoine Stevan
aa08e81370
change signature of enumerate to any -> table (#9822)
related to
https://discord.com/channels/601130461678272522/1134054657086464072

# Description
the `enumerate` command always returns a table but its signature is `any
-> any` which can be confusing 😕
this PR changes the signature to `any -> table`

i've double checked and the source of `enumerate` returns a list of
records, a.k.a. a table 👌

# User-Facing Changes
this shouldn't change anything apart from the help page of `enumerate`
showing now
```
Input/output types:
  ╭───┬───────┬────────╮
  │ # │ input │ output │
  ├───┼───────┼────────┤
  │ 0 │ any   │ table  │
  ╰───┴───────┴────────╯
```
instead of 
```
Input/output types:
  ╭───┬───────┬────────╮
  │ # │ input │ output │
  ├───┼───────┼────────┤
  │ 0 │ any   │ any    │
  ╰───┴───────┴────────╯
```

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

# After Submitting
2023-07-27 21:39:03 +02:00
Stefan Holderbach
3481c7e242
Fix signature of split row (#9829)
# Description
This command also flat-maps and doesn't create a table like `split
column`

We should probably reconsider the flatmap behavior like in #9739
but for the #9812 hotfix this is an unwelcome breaking change.

# User-Facing Changes
None

# Tests + Formatting
- Fix signature of `split row`
- Add test for output signature
2023-07-27 21:32:25 +02:00
JT
78e29af423
Fix prepend type, fix typos (#9828)
# Description

This PR does two (somewhat related) things:

* Fixes the `prepend` signature in the same way we fixed `append`
* Fixes a few typos in the examples of `prepend` and `append`

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-28 06:52:45 +12:00
JT
3ef5e90b64
Fix the implied collect type to 'any' (#9827)
# Description

Previously, we had a bug slip in about implied collection caused by
`$in`, that this output type would be of type `string`.

The type system fixes in 0.83 now make this more visible and cause
issues. This PR changes the output of the implied collection to `any`.
At some point in the future, we may want to carry the type through where
we can, but `any` should unblock using `$in`.

fixes #9825

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-28 06:26:28 +12:00
WindSoilder
6aa30132aa
fix append signature (#9821)
# Description
Fixes: #9720
Actually it mainly address the comment:
https://github.com/nushell/nushell/issues/9720#issuecomment-1652240104

After looking into example, I think if it receives a string, it should
returns a list too rather than a string
2023-07-27 15:53:48 +02:00
Darren Schroeder
5d2ef0faf1
add input_output_type to ansi command (#9817)
# Description

This PR fixes this not working `ansi --list | columns`. I originally
thought that this was a problem with `columns` but it turned out to be a
problem with the input output type of `ansi`. Since `ansi` was only
allowed to return strings, `columns` thought it was getting a string,
but it was a table.

closes #9808

tracking #9812

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-26 16:39:24 -05:00
Stefan Holderbach
b2e191f836
Remove Signature.vectorizes_over_list entirely (#9777)
# Description
With the current typechecking logic this property has no effect.
It was only used in the example testing, and provided some indication of
this vectorizing property.
With #9742 all commands that previously declared it have explicit list
signatures. If we want to get it back in the future we can reconstruct
it from the signature.

Simplifies the example testing a bit.

# User-Facing Changes
Causes a breaking change for plugins that previously declared it. While
this causes a compile fail, this was already broken by our more
stringent type checking.
This will be a good reminder for plugin authors to update their
signature as well to reflect the more stringent type checking.
2023-07-26 23:34:43 +02:00
Stefan Holderbach
d9230a76f3
Fix signatures for cellpath access of records (#9793)
# Description
The same procedure as for #9778 repeated for records.

# User-Facing Changes
Commands that directly supported applying their work directly to record
fields via cell paths, that worked before #9680 will now work again

# Tests + Formatting
Tried to limit the need to add new `.allow_variants_without_examples()`
by adjusting or adding tests to also use some records with access.
2023-07-26 23:13:57 +02:00
JT
f8d325dbfe
Set the rest variable to the correct type (#9816)
# Description

This fixes the type of `$rest` to be a `List<...>` so that it properly
is checked in function bodies.

fixes https://github.com/nushell/nushell/issues/9809
2023-07-26 20:22:08 +02:00
Darren Schroeder
88a890c11f
bump to dev version 0.83.1 (#9811)
# Description

This bumps nushell to the dev version of 0.83.1 and updates the default
config files with the proper version.

# User-Facing Changes
# Tests + Formatting
# After Submitting
2023-07-26 19:02:13 +02:00
Justin Ma
5a28371b18
Fix command docs deployment for input listen (#9805)
Fix command docs deployment for `input listen`, for more detail check:
https://github.com/nushell/nushell.github.io/pull/987
2023-07-26 07:00:23 -05:00
JT
a33b5fe6ce
bump to 0.83 (#9802)
# Description

Bump 0.83

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-26 07:36:36 +12:00
Stefan Holderbach
2080719162
Pin reedline to 0.22.0 release (#9794)
See release notes:

https://github.com/nushell/reedline/releases/tag/v0.22.0
2023-07-24 22:14:28 +02:00
Stefan Holderbach
9db0d6bd34
Adjust signatures for cellpath access of tables (#9778)
# Description
Reallow the commands that take cellpaths as rest parameters to operate
on table input data.

Went through all commands returned by

```
scope commands |
  filter { |cmd| $cmd.signatures |
    values |
    any {|sig| $sig |
      any {|$sig| $sig.parameter_type == rest and $sig.syntax_shape ==
cellpath }
    }
  } | get name
```

Only exception to that was `is-empty` that returns a bool.
# User-Facing Changes
Same table operations as in `0.82` should still be possible
Mitigates effects of #9680
2023-07-24 13:17:30 +02:00
Stefan Holderbach
d7ebe5fdc3
Update nu-ansi-term, lscolors, and reedline (#9787)
# Description
Now use `nu-ansi-term` 0.49
Small adjustments to accommodate breaking changes.


# User-Facing Changes
None
2023-07-24 13:16:18 +02:00
Stefan Holderbach
2dcd1c5dbe
Abort type determination for List early (#9779)
# Description
If we reach the conclusion that the fields of a list are of `Type::Any`
there is no need to continue as the type will remain `Type::Any`

This should improve runtimes of `Value.get_type()` for lists with mixed
types.

# User-Facing Changes
None, a speedup in some cases.

# Tests + Formatting
Relies on existing tests
2023-07-24 07:15:53 +02:00
Stefan Holderbach
2aeb77bd3e
Fix output signature of split chars/words (#9739)
# Description
Those two commands did *not* vectorize over the input in the pure sense
as they performed a flat map. Now they return a list for each string
that gets split by them.

```
["foo" "bar"] | split chars
```

## Before 

```
╭───┬───╮
│ 0 │ f │
│ 1 │ o │
│ 2 │ o │
│ 3 │ b │
│ 4 │ a │
│ 5 │ r │
╰───┴───╯
```

## After
```
╭───┬───────────╮
│ 0 │ ╭───┬───╮ │
│   │ │ 0 │ f │ │
│   │ │ 1 │ o │ │
│   │ │ 2 │ o │ │
│   │ ╰───┴───╯ │
│ 1 │ ╭───┬───╮ │
│   │ │ 0 │ b │ │
│   │ │ 1 │ a │ │
│   │ │ 2 │ r │ │
│   │ ╰───┴───╯ │
╰───┴───────────╯
```
2023-07-23 17:06:41 -05:00
Stefan Holderbach
17f8ad7210
Use explicit in/out list types for vectorized commands (#9742)
# Description
All commands that declared `.vectorizes_over_list(true)` now also
explicitly declare the list form of their scalar types.

- Explicit in/out list signatures for nu-command
- Explicit in/out list signatures for nu-cmd-extra
- Add comments about cellpath behavior that is still unresolved


# User-Facing Changes
Our type signatures will now be more explicit about which commands
support vectorization over lists.
On the downside this is a bit more verbose and less systematic.
2023-07-23 20:46:53 +02:00
Stefan Holderbach
4dbdb1fe54
Add explicit input types for vectorized into int form (#9741)
# Description
Don't just use `List<Any>`, be precise for the vectorized form as well.

# User-Facing Changes
More explicit albeit verbose type information in the signature
2023-07-23 20:36:53 +02:00
Antoine Stevan
79359598db
add table -> table to into datetime (#9775)
should close https://github.com/nushell/nushell/issues/9774

# Description
given the help page of `into datetime`, 
```
Parameters:
  ...rest <cellpath>: for a data structure input, convert data at the given cell paths
```
it looks like `into datetime` should accept tables as input 🤔 

this PR
- adds the `table -> table` signature to `into datetime`
- adds a test to make sure the behaviour stays there
2023-07-23 20:14:51 +02:00
Vikrant A P
75180d07de
Fix: remove unnecessary r#"..."# (#8670) (#9764)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# 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.
-->
This PR is related to **Tests: clean up unnecessary use of cwd,
pipeline(), etc.
[#8670](https://github.com/nushell/nushell/issues/8670)**

- Removed the `r#"..."#` raw string literal syntax, which is unnecessary
when there are no special characters that need quoting from the tests
that use the `nu!` macro.
- `cwd:` and `pipeline()` has not changed


# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-21 17:32:37 +02:00
mengsuenyan
cdc4fb1011
fix #9653 the cmd detect columns with the flag -c (#9667)
fix `detect columns` with flag `-c, --combine-columns` run failed when
using some range

- fixes #9653 

fix #9653 the cmd detect columns with the flag -c, --combine-columns run
failed when using some range.

add unit test for the command `detect columns`

```text
Attempt to automatically split text into multiple columns.

Usage:
  > detect columns {flags} 

Flags:
  -h, --help - Display the help message for this command
  -s, --skip <Int> - number of rows to skip before detecting
  -n, --no-headers - don't detect headers
  -c, --combine-columns <Range> - columns to be combined; listed as a range

Signatures:
  <string> | detect columns -> <table>

Examples:
  Splits string across multiple columns
  > 'a b c' | detect columns -n
  ╭───┬─────────┬─────────┬─────────╮
  │ # │ column0 │ column1 │ column2 │
  ├───┼─────────┼─────────┼─────────┤
  │ 0 │ a       │ b       │ c       │
  ╰───┴─────────┴─────────┴─────────╯

  Splits a multi-line string into columns with headers detected
  > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns
  ╭───┬────┬────┬────┬────┬────╮
  │ # │ c1 │ c2 │ c3 │ c4 │ c5 │
  ├───┼────┼────┼────┼────┼────┤
  │ 0 │ a  │ b  │ c  │ d  │ e  │
  ╰───┴────┴────┴────┴────┴────╯

  
  > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 0..1
  ╭───┬─────┬────┬────┬────╮
  │ # │ c1  │ c3 │ c4 │ c5 │
  ├───┼─────┼────┼────┼────┤
  │ 0 │ a b │ c  │ d  │ e  │
  ╰───┴─────┴────┴────┴────╯

  Splits a multi-line string into columns with headers detected
  > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c -2..-1
  ╭───┬────┬────┬────┬─────╮
  │ # │ c1 │ c2 │ c3 │ c4  │
  ├───┼────┼────┼────┼─────┤
  │ 0 │ a  │ b  │ c  │ d e │
  ╰───┴────┴────┴────┴─────╯

  Splits a multi-line string into columns with headers detected
  > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 2..
  ╭───┬────┬────┬───────╮
  │ # │ c1 │ c2 │  c3   │
  ├───┼────┼────┼───────┤
  │ 0 │ a  │ b  │ c d e │
  ╰───┴────┴────┴───────╯

  Parse external ls command and combine columns for datetime
  > ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7

```
2023-07-21 08:25:06 -05:00
Ian Manske
7e1b922ea7
Add functions for each Value case (#9736)
# Description
This PR ensures functions exist to extract and create each and every
`Value` case. It also renames `Value::boolean` to `Value::bool` to match
`Value::test_bool`, `Value::as_bool`, and `Value::Bool`. Similarly,
`Value::as_integer` was renamed to `Value::as_int` to be consistent with
`Value::int`, `Value::test_int`, and `Value::Int`. These two renames can
be undone if necessary.

# User-Facing Changes
No user facing changes, but two public functions were renamed which may
affect downstream dependents.
2023-07-21 08:20:33 -05:00
Darren Schroeder
0b1e368cea
update history_isolation to false (#9763)
# Description

This PR follows #9762 and sets the rust component to match

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-21 06:58:32 -05:00
Darren Schroeder
3b9a0ac7c6
change the default of history.isolation (#9762)
# Description

This PR just fixes the default value of history.isolation and adds a few
more comments. isolation isn't available in plaintext so it should be
defaulted to off/false.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-21 06:40:42 -05:00
Antoine Stevan
a1f989caf9
change the output of which to be more explicit (#9646)
related to
- https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548

# Description
this PR changes the output of `which` from `table<arg: string, path:
string, built-in: bool> (stream)` to `table<command: string, path:
string, type: string> (stream)`.
- `command`: same as `arg` but more explicit name
- `path`: same as before, `null` when built-in
- `type`: instead of `buil-in: bool` says if it's a `built-in` a
`custom` command, an `alias` or an `external`

# User-Facing Changes
the output of `which` has changed

## some examples
```nushell
> which open
╭───┬─────────┬──────┬──────────╮
│ # │ command │ path │   type   │
├───┼─────────┼──────┼──────────┤
│ 0 │ open    │      │ built-in │
╰───┴─────────┴──────┴──────────╯
```
```nushell
> alias foo = print "foo"
> which foo
╭───┬─────────┬──────┬───────╮
│ # │ command │ path │ type  │
├───┼─────────┼──────┼───────┤
│ 0 │ foo     │      │ alias │
╰───┴─────────┴──────┴───────╯
```
```nushell
> def bar [] {}
> which bar
╭───┬─────────┬──────┬────────╮
│ # │ command │ path │  type  │
├───┼─────────┼──────┼────────┤
│ 0 │ bar     │      │ custom │
╰───┴─────────┴──────┴────────╯
```
```nushell
> which git
╭───┬─────────┬──────────────┬──────────╮
│ # │ command │     path     │   type   │
├───┼─────────┼──────────────┼──────────┤
│ 0 │ git     │ /usr/bin/git │ external │
╰───┴─────────┴──────────────┴──────────╯
```
```nushell
> which open git foo bar
╭───┬─────────┬──────────────┬──────────╮
│ # │ command │     path     │   type   │
├───┼─────────┼──────────────┼──────────┤
│ 0 │ open    │              │ built-in │
│ 1 │ git     │ /usr/bin/git │ external │
│ 2 │ foo     │              │ alias    │
│ 3 │ bar     │              │ custom   │
╰───┴─────────┴──────────────┴──────────╯
```

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

# After Submitting
mention that in the release note
2023-07-20 19:10:53 -05:00
A. Taha Baki
c01f2ee0e9
str-expand: new capability, empty collection item (#9750)
I added a new capability to `bracoxide` which is for `brace expansion`
(it's almost like bash brace expressions).

Anyway, this change adds this capability:

`A{,B,C} | str expand`, returns:

```md
- A
- AB
- AC
```


`A{B,,C} | str expand`, returns:

```md
- AB
- A
- AC
```

`A{B,C,} | str expand`, returns:

```md
- AB
- AC
- A
```

Updated examples, according to the new feature.
2023-07-20 18:51:25 -05:00
Antoine Stevan
693cb5c142
add any -> record to metadata (#9755)
# Description
in the help page of `metadata`, there is the following example
```nushell
ls | metadata
```
which gives the following error
```
Error: nu::parser::input_type_mismatch

  × Command does not support table input.
   ╭─[entry #2:1:1]
 1 │ ls | metadata
   ·      ────┬───
   ·          ╰── command doesn't support table input
   ╰────
```

this PR adds `any -> record` to the signatures of `metadata` to allow
the use of that kind of example.

# User-Facing Changes
`ls | metadata` will work again

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

# After Submitting
2023-07-21 07:11:20 +12:00
JT
d104efdf68
Fix capture logic for inner closures (#9754)
# Description

This fixes the variable capture logic for closures in two cases:

* Closures inside of closures did not properly register the closures (or
lack thereof) in the outer closure
* Closures which called their inner closures before definition did not
properly calculate the closures of the outer closure

Example of the first case:
```
do { let b = 3; def c [] { $b }; c }
```

Example of the second case (notice `c` is called before it is defined):
```
do { let b = 3; c; def c [] { $b }; c }
```

# User-Facing Changes
This should strictly allow closures to work more correctly.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-21 07:10:54 +12:00
Alexandra Østermark
bd9d865912
fix removing symlinks on windows (#9704)
this PR should close #9624

# Description

Fixes the `rm` command assuming that a symlink is a directory and trying
to delete the directory as opposed to unlinking the symlink.

Should probably be tested on linux before merge.

Added tests for deleting symlinks
2023-07-20 20:16:03 +02:00
Darren Schroeder
c62cbcd5f8
handle sqlite tables better by surrounding with brackets (#9752)
# Description

This PR helps the sqlite handling better by surrounding table names with
brackets. This makes it easier to have table names with spaces like
`Basin / profile`.

Closes #9751 

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-20 11:20:56 -05:00
WindSoilder
ba4723cc9f
Support variables/interpolation in o>, e>, o+e> redirect (#9747)
# Description
Fixes:  #8517
Fixes: #9246
Fixes: #9709
Relative: #9723


## About the change
Before the pr, nushell only parse redirection target as a string(through
`parse_string` call).
In the pr, I'm trying to make the value more generic(using `parse_value`
with `SyntaxShape::Any`)

And during eval stage, we guard it to only eval `String`,
`StringInterpolation`, `FullCellPath`, `FilePath`, so other type of
redirection target like `1ms` won't be permitted.

# User-Facing Changes

After the pr: redirection support something like the following:
1. `let a = "x"; cat toolkit.nu o> $a`
2. `let a = "x"; cat toolkit.nu o> $"($a).txt"`
3. `cat toolkit.nu out> ("~/a.txt" | path expand)`
2023-07-20 13:56:46 +02:00
Darren Schroeder
488002f4bc
add range input to par-each (#9749)
# Description

Thie PR adds `Type::Range` input to `par-each` to allow `1..3 | do
something` again.
closes #9748 

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-20 06:48:18 -05:00
Michael Angerman
5115260366
add in a Readme for the crate nu-cmd-extra (#9745)
This outlines our plans for the commands located in the crate
nu-cmd-extra.

It also documents how one can build these commands from source.
2023-07-19 21:35:58 -07:00
Darren Schroeder
2d557bce5d
normalize default_config/env formatting (#9731)
# Description

This PR just tried to normalize the formatting. Everything should be 4
spaces now for those people that can't live with 2 spaces in the default
config files. I also remove some unneeded line breaks and changed two
places that should've been `edit` vs `send`.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-19 06:49:21 -05:00
David Matos
1ba2269aa9
Disallow empty record with empty key,value pairs on ini format (#9722)
# Description
This PR fixes #9556. Now, only a section will be added if it contains a
key, value pair. With this change, `{record with 0 fields}`, should not
appear anymore.

For more context on empty sections, see issue on the
[crate](https://github.com/zonyitoo/rust-ini/issues/109)

```
open -r whatever | from ini
╭─────────────┬──────────────────────────────────────────────────────────────╮
│             │ ╭───────────────────────┬──────────────────────────────────╮ │
│ placeholder │ │ aws_access_key_id     │ AAAAAAAAAAAAAAAAAAAAA            │ │
│             │ │ aws_secret_access_key │ BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB │ │
│             │ ╰───────────────────────┴──────────────────────────────────╯ │
│             │ ╭───────────────────────┬──────────────────────────╮         │
│ default     │ │ aws_access_key_id     │ AAAAAAAAAAAAAAAAAA       │         │
│             │ │ aws_secret_access_key │ AAAAAAAAAAAAAAAAAAAAAAA  │         │
│             │ │ aws_session_token     │ BBBBBBBBBBBBBBBBBBBBBBBB │         │
│             │ │ region                │ us-east-1                │         │
│             │ │ output                │ json                     │         │
│             │ ╰───────────────────────┴──────────────────────────╯         │
╰─────────────┴──────────────────────────────────────────────────────────────╯
```
# Tests + Formatting
Now test for exact `from ini` output

---------

Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
2023-07-18 22:14:18 +02:00
Stefan Holderbach
36030cab8a
Remove underused devdep getset (#9727)
# Description
We only used this procmacro crate in one place to generate two trivial
getters. Straightforward to replace. Should reduce test-compilation
requirements a bit.

# User-Facing Changes
None
2023-07-19 06:18:52 +12:00
Antoine Stevan
345c00aa1e
sync default config / env with default behaviour without any configuration (#9676)
related PRs and issues
- supersedes https://github.com/nushell/nushell/pull/9633
- should close https://github.com/nushell/nushell/issues/9630

# Description
this PR updates the `default_config.nu` config file and the `config.rs`
module in `nu_protocol` so that the default behaviour of Nushell,
without any config, and the one with `default_config.nu` and
`default_env.nu` are the same.

## changelog
- 3e2bfc9bb: copy the structure of `default_config.nu` inside the
implementation of `Default` in the `config.rs` module for easier check
of the default values
- e25e5ccd6: sync all the *simple* config fields, i.e. the
non-structured ones
- ae7e8111c: set the `display_output` hook to always run `table`
- a09a1c564: leave only the default menus => i've removed
`commands_menu`, `vars_menu` and `commands_with_description`

## todo
- [x] ~~check the defaults in `$env.config.explore`~~ done in 173bdbba5
and b9622084c
- [x] ~~check the defaults in `$env.config.color_config`~~ done in
c411d781d => the theme is now `{}` by default so that it's the same as
the default one with `--no-config`
- [x] ~~check the defaults `$env.config.keybindings`~~ done in 715a69797
- already available with the selected mode: `completion_previous`,
`next_page`, `undo_or_previous_page`, `yank`, `unix-line-discard` and
`kill-line`, e.g. in *vi* mode, `unlix-line-discard` is done in NORMAL
mode with either `d0` from the end of the line or `dd` from anywhere in
the line and `kill-line` is done in NORMAL mode with `shift + d`. these
bindings are available by default in *emacs* mode as well.
- previously with removed custom menus: `commands_menu`, `vars_menu` and
`commands_with_description`
- [x] ~~check `$env.config.datetime_format`~~ done in 0ced6b8ec => as
there is no *human* format for datetimes, i've commented out both
`$env.config.datetime_format` fields
- [x] ~~fix `default_env.nu`~~ done in 67c215011

# User-Facing Changes
this should not change anything, just make sure the default behaviour of
Nushell and the `default_config.nu` are in sync.

# Tests + Formatting
# After Submitting
2023-07-18 11:22:00 -05:00
nibon7
cc202e2199
Remove is-root crate (#9615)
# Description
This PR tries to remove `is-root` crate.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2023-07-18 15:36:54 +02:00
Ian Manske
a5a79a7d95
Do not attempt to take control of terminal in non-interactive mode (#9693)
# Description
Fixes a regression from #9681 where nushell will attempt to place itself
into the background or take control of the terminal even in
non-interactive mode.

Using the same
[reference](https://www.gnu.org/software/libc/manual/html_node/Initializing-the-Shell.html)
from #6584:

>A subshell that runs *interactively* has to ensure that it has been
placed in the foreground...

>A subshell that runs *non-interactively* cannot and should not support
job control.

`fish`
[code](54fa1ad6ec/src/reader.cpp (L4862))
also seems to follow this.

This *partially* fixes
[9026](https://github.com/nushell/nushell/issues/9026). That is, nushell
will no longer set the foreground process group in non-interactive mode.
2023-07-17 16:32:29 -05:00
Stefan Holderbach
656f707a0b
Clean up tests containing unnecessary cwd: tokens (#9692)
# Description
The working directory doesn't have to be set for those tests (or would
be the default anyways). When appropriate also remove calls to the
`pipeline()` function. In most places kept the diff minimal and only
removed the superfluous part to not pollute the blame view. With simpler
tests also simplified things to make them more readable overall (this
included removal of the raw string literal).

Work for #8670
2023-07-17 18:43:51 +02:00
dependabot[bot]
48271d8c3e
Bump miette from 5.9.0 to 5.10.0 (#9713) 2023-07-17 06:25:04 +00:00
dependabot[bot]
60bb984e6e
Bump strum_macros from 0.24.3 to 0.25.1 (#9714) 2023-07-17 06:23:17 +00:00
Darren Schroeder
eeb3b38fba
allow range as a input_output_type on filter (#9707)
# Description

This PR allows `Type::Range` on the `filter` command so you can do
things like this:
```nushell
❯ 9..17 | filter {|el| $el mod 2 != 0}
╭───┬────╮
│ 0 │  9 │
│ 1 │ 11 │
│ 2 │ 13 │
│ 3 │ 15 │
│ 4 │ 17 │
╰───┴────╯
```

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-16 08:13:46 -05:00
Antoine Stevan
79d9a0542f
allow into filesize to take tables as input / output (#9706)
# Description
i have the following command that should give a table of all the mounted
devices with information about their sizes, etc, etc... a glorified
output for the `df -h` command:
```nushell
def disk [] {
    df -h
      | str replace "Mounted on" "Mountpoint"
      | detect columns
      | rename filesystem size used avail used% mountpoint
      | into filesize size used avail
      | upsert used% {|it| 100 * (1 - $it.avail / $it.size)}
}
```

this should work given the first example of `into filesize`
```nushell
  Convert string to filesize in table
  > [[bytes]; ['5'] [3.2] [4] [2kb]] | into filesize bytes
```

## before this PR
it does not even parse
```nushell
Error: nu::parser::input_type_mismatch

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

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

## with this PR
it parses again and gives
```nushell
> disk | where mountpoint == "/" | into record
╭────────────┬───────────────────╮
│ filesystem │ /dev/sda2         │
│ size       │ 217.9 GiB         │
│ used       │ 158.3 GiB         │
│ avail      │ 48.4 GiB          │
│ used%      │ 77.77777777777779 │
│ mountpoint │ /                 │
╰────────────┴───────────────────╯
```

> **Note**
> the two following commands also work now and did not before the PR
> ```nushell
> ls | insert name_size {|it| $it.name | str length} | into filesize
name_size
> ```
> ```nushell
> [[device size]; ["/dev/sda1" 200] ["/dev/loop0" 50]] | into filesize
size
> ```

# User-Facing Changes
`into filesize` works back with tables and this effectively fixes the
doc.

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

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

# After Submitting
2023-07-16 08:04:35 -05:00
mike
5bfec20244
add match guards (#9621)
## description

this pr adds [match
guards](https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards)
to match patterns
```nushell
match $x {
   _ if $x starts-with 'nu' => {},
   $x => {}
}
```

these work pretty much like rust's match guards, with few limitations:

1. multiple matches using the `|` are not (yet?) supported
 
```nushell
match $num {
    0 | _ if (is-odd $num) => {},
    _ => {}
}
```

2. blocks cannot be used as guards, (yet?)

```nushell
match $num {
    $x if { $x ** $x == inf } => {},
     _ => {}
}
```

## checklist
- [x] syntax
- [x] syntax highlighting[^1]
- [x] semantics
- [x] tests
- [x] clean up

[^1]: defered for another pr
2023-07-16 12:25:12 +12:00
JT
57d96c09fa
fix input signature of let/mut (#9695)
# Description

This updates `let` and `mut` to allow for any input. This lets them
typecheck any collection they do.

For example, this now compiles:

```
def foo []: [int -> int, string -> int] {
  let x = $in
  if ($x | describe) == "int" { 3 } else { 4 }
}

100 | foo
```

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-15 19:41:48 +12:00
JT
53ae03bd63
Custom command input/output types (#9690)
# Description

This adds input/output types to custom commands. These are input/output
pairs that related an input type to an output type.

For example (a single int-to-int input/output pair):

```
def foo []: int -> int { ... }
```

You can also have multiple input/output pairs:
```
def bar []: [int -> string, string -> list<string>] { ... }
```

These types are checked during definition time in the parser. If the
block does not match the type, the user will get a parser error.

This `:` to begin the input/output signatures should immediately follow
the argument signature as shown above.

The PR also improves type parsing by re-using the shape parser. The
shape parser is now the canonical way to parse types/shapes in user
code.

This PR also splits `extern` into `extern`/`extern-wrapped` because of
the parser limitation that a multi-span argument (which Signature now
is) can't precede an optional argument. `extern-wrapped` now takes the
required block that was previously optional.

# User-Facing Changes

The change to `extern` to split into `extern` and `extern-wrapped` is a
breaking change.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-15 09:51:28 +12:00
Jakub Žádník
ba766de5d1
Refactor path commands (#9687) 2023-07-15 00:04:22 +03:00
JT
8c52b7a23a
Change input/output types in help to a table (#9686)
# Description

Updates `help` to more clearly show input/output types.

Before:


![image](https://github.com/nushell/nushell/assets/547158/5f11ca5c-54a0-414d-b3de-1a8b4dd7fcbd)

After:


![image](https://github.com/nushell/nushell/assets/547158/afc0eb1e-fad8-43b1-9382-c2a0d8e9334e)

# 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-15 06:23:21 +12:00
Darren Schroeder
4804e6a151
add more input_output_types found from breaking scripts (#9683)
# Description

This PR fixes some problems I found in scripts by adding some additional
input_output_types.

Here's a list of nushell scripts that it fixed. Look for `# broke here:`
below.

This PR fixes 3, 4, 6, 7 by adding additional input_output_types. 1 was
fixed by changing the script. 2. just doesn't work anymore because mkdir
return type has changed. 5, is a problem with the script, the datatype
for `...rest` needed to be removed.

```nushell
# 1.
def terminal-size [] {
    let sz = (input (ansi size) --bytes-until 'R')
    # $sz should look like this
    # Length: 9 (0x9) bytes | printable whitespace ascii_other non_ascii
    # 00000000:   1b 5b 33 38  3b 31 35 30  52                         •[38;150R
    let sz_len = ($sz | bytes length)

    # let's skip the esc[ and R
    let r = ($sz | bytes at 2..($sz_len - 2) | into string)

    # $r should look like 38;150
    # broke here: because $r needed to be a string for split row
    let size = ($r | split row ';')

    # output in record syntax
    {
        rows: ($size | get 0)
        columns: ($size | get 1)
    }
}

# 2.
# make and cd to a folder
def-env mkcd [name: path] {
    # broke here: but apparently doesn't work anymore
    # It looks like  mkdir returns nothing where it used to return a value
    cd (mkdir $name -v | first) 
}

# 3.
# changed 'into datetime'
def get-monday [] {
  (seq date -r --days 7 |
  # broke here: because into datetime didn't support list input
   into datetime | 
   where { |e| 
   ($e | date format %u) == "1" }).0 | 
   date format "%Y-%m-%d"
}

# 4.
# Delete all branches that are not in the excepts list
# Usage: del-branches [main]
def del-branches [
    excepts:list  # don't delete branch in the list
    --dry-run(-d) # do a dry-run
 ] {
    let branches = (git branch | lines | str trim)
    # broke here: because str replace didn't support list<string>
    let remote_branches = (git branch -r | lines | str replace '^.+?/' '' | uniq)
    if $dry_run {
        print "Starting Dry-Run"
    } else {
        print "Deleting for real"
    }
    $branches | each {|it|
        if ($it not-in $excepts) and ($it not-in $remote_branches) and (not ($it | str starts-with "*")) {
            # git branch -D $it
            if $dry_run {
                print $"git branch -D ($it)"
            } else {
                print $"Deleting ($it) for real"
                #git branch -D $it
            }
        }
    }
}

# 5.
# zoxide script
def-env __zoxide_z [...rest] {
  # `z -` does not work yet, see https://github.com/nushell/nushell/issues/4769
  # broke here: 'append doesn't support string input'
  let arg0 = ($rest | append '~').0
  # broke here: 'length doesn't support string input' so change `...rest:string` to `...rest`
  let path = if (($rest | length) <= 1) and ($arg0 == '-' or ($arg0 | path expand | path type) == dir) {
    $arg0
  } else {
    (zoxide query --exclude $env.PWD -- $rest | str trim -r -c "\n")
  }
  cd $path
}

# 6.
def a [] { 
    let x = (commandline)
    if ($x | is-empty) { return }
    # broke here: because commandline was previously only returning Type::Nothing
    if not ($x | str starts-with "aaa") { print "bbb" }
}

# 7.
# repeat a string x amount of times
def repeat [arg: string, dupe: int] {
  # broke here: 'command does not support range input'
  0..<$dupe | reduce -f '' {|i acc| $acc + $arg}
}
```

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-14 10:58:41 -05:00
JT
786ba3bf91
Input output checking (#9680)
# Description

This PR tights input/output type-checking a bit more. There are a lot of
commands that don't have correct input/output types, so part of the
effort is updating them.

This PR now contains updates to commands that had wrong input/output
signatures. It doesn't add examples for these new signatures, but that
can be follow-up work.

# User-Facing Changes

BREAKING CHANGE BREAKING CHANGE

This work enforces many more checks on pipeline type correctness than
previous nushell versions. This strictness may uncover incompatibilities
in existing scripts or shortcomings in the type information for internal
commands.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-14 15:20:35 +12:00
Jakub Žádník
e66139e6bb
Fix broken constants in scopes (#9679) 2023-07-14 00:02:05 +03:00
JT
30904bd095
Remove broken compile-time overload system (#9677)
# Description

This PR removes the compile-time overload system. Unfortunately, this
system never worked correctly because in a gradual type system where
types can be `Any`, you don't have enough information to correctly
resolve function calls with overloads. These resolutions must be done at
runtime, if they're supported.

That said, there's a bit of work that needs to go into resolving
input/output types (here overloads do not execute separate commands, but
the same command and each overload explains how each output type
corresponds to input types).

This PR also removes the type scope, which would give incorrect answers
in cases where multiple subexpressions were used in a pipeline.

# User-Facing Changes

Finishes removing compile-time overloads. These were only used in a few
places in the code base, but it's possible it may impact user code. I'll
mark this as breaking change so we can review.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-14 07:05:03 +12:00
Michael Angerman
99329f14a3
remove warning: unused import pipeline (#9675)
Fix a compiler warning caused by this file...

```rust
crates/nu-command/tests/commands/let_.rs
```
2023-07-13 09:12:20 -07:00
Michael Angerman
3c583c9a20
cratification: part III of the math commands to nu-cmd-extra (#9674)
The following math commands are being moved to nu-cmd-extra

* e (euler)
* exp
* ln

This should conclude moving the extra math commands as discussed in
yesterday's
core team meeting...

The remaining math commands will stay in nu-command (for now)....
2023-07-13 09:11:26 -07:00
WindSoilder
9a6a3a731e
support env and mut assignment with if block and match guard (#9650)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# 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.
-->
Fixes: https://github.com/nushell/nushell/issues/9595

So we can do the following in nushell:
```nushell
mut a = 3
$a = if 4 == 3 { 10 } else {20}
```
or
```nushell
$env.BUILD_EXT = match 3 { 1 => { 'yes!' }, _ => { 'no!' } }
```

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: WindSoilder <windsoilder@DESKTOP-R8GRJ1D.localdomain>
2023-07-13 10:55:41 +02:00
Maxim Zhiburt
b2043135ed
nu-explore/ Add handlers for HOME/END keys (#9666)
close #9665

It could be good to run it though and see if it does what indented.
(I did but cause there's no test coverage for it it's better to recheck)

PS: Surely... this cursor logic much more complex then it shall be ...
the method names ....

cc: @fdncred

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-07-12 14:13:35 -05:00
Antoine Stevan
545697c0b2
simplify the test for let core command (#9671)
related to
- follow-up of https://github.com/nushell/nushell/pull/9658
- addressed part of https://github.com/nushell/nushell/issues/8670

# Description
removes useless `cwd` and `pipeline()` from the tests of `let`.

# User-Facing Changes
# Tests + Formatting
# After Submitting
2023-07-12 19:33:25 +02:00
Antoine Stevan
ca794f6adb
fix the std test commands calls in dev documents (#9535)
related to a comment in https://github.com/nushell/nushell/pull/9500
> `cargo run -- crates/nu-std/tests/run.nu` Not done - doesn't seem to
work

this is absolutely true because the command in the PR template was
obsolete...
i've also updated the commands in the `CONTRIBUTING` document of the
library 👍

cc/ @fnordpig
2023-07-12 18:26:47 +02:00
Stefan Holderbach
39b43d1e4b
Use is-terminal crate for now (#9670)
# Description
Until we bump our minimal Rust version to `1.70.0` we can't use
`std::io::IsTerminal`. The crate `is-terminal` (depending on `rustix` or
`windows-sys`) can provide the same.
Get's rid of the dependency on the outdated `atty` crate.
We already transitively depend on it (e.g. through `miette`)

As soon as we reach the new Rust version we can supersede this with
@nibon7's #9550

Co-authored-by: nibon7 <nibon7@163.com>
2023-07-12 18:15:54 +02:00
mengsuenyan
026335fff0
Fix cp -u/mv -u when the dst doesn't exist (#9662)
Fixes #9655
2023-07-12 18:12:59 +02:00
Stefan Holderbach
7c9edbd9ee
Bump deps to transitively use hashbrown 0.14 (#9668)
# Description
Update `lru` to `0.11`: `cargo build` will now not need `hashbrown 0.13`
Update `dashmap`: upgrades `hashbrown` for dev-dependency

-1 dependency in the `cargo install` path
2023-07-12 17:55:51 +02:00
Darren Schroeder
341fa7b196
add kind and state to other key presses (#9669)
# Description

This PR adds `kind` and `state` to other `keybindings listen` presses
like `home` and `end` keys. Before they didn't exist.

```
❯ keybindings listen
Type any key combination to see key details. Press ESC to abort.
code: Enter, modifier: NONE, flags: 0b000000, kind: Release, state: NONE
code: Home, modifier: NONE, flags: 0b000000, kind: Press, state: NONE
code: Home, modifier: NONE, flags: 0b000000, kind: Release, state: NONE
code: End, modifier: NONE, flags: 0b000000, kind: Press, state: NONE
code: End, modifier: NONE, flags: 0b000000, kind: Release, state: NONE
code: End, modifier: CONTROL, flags: 0b000010, kind: Press, state: NONE
code: End, modifier: CONTROL, flags: 0b000010, kind: Release, state: NO
```

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-12 10:42:19 -05:00
Stefan Holderbach
bd0032898f
Apply nightly clippy lints (#9654)
# Description
- A new one is the removal of unnecessary `#` in raw strings without `"`
inside.
-
https://rust-lang.github.io/rust-clippy/master/index.html#/needless_raw_string_hashes
- The automatically applied removal of `.into_iter()` touched several
places where #9648 will change to the use of the record API. If
necessary I can remove them @IanManske to avoid churn with this PR.
- Manually applied `.try_fold` in two places
- Removed a dead `if`
- Manual: Combat rightward-drift with early return
2023-07-12 00:00:31 +02:00
JT
ad11e25fc5
allow mut to take pipelines (#9658)
# Description

This extends the syntax fix for `let` (#9589) to `mut` as well.

Example: `mut x = "hello world" | str length; print $x`

closes #9634

# User-Facing Changes

`mut` now joins `let` in being able to be assigned from a pipeline

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-12 06:36:34 +12:00
Michael Angerman
942c66a9f3
cratification: part II of the math commands to nu-cmd-extra (#9657)
The following math commands are being moved to nu-cmd-extra

* cos
* cosh
* egamma
* phi
* pi
* sin
* sinh
* tan
* tanh
* tau

For now I think we have most of the obvious commands moved over based on

@sholderbach this should cover moving the "high school" commands..

>>Yeah I think this rough separation into "high school" math in extra
and "middle school"/"programmer" math in the core makes a ton of sense.

And to reference the @fdncred list from
https://github.com/nushell/nushell/pull/9647#issuecomment-1629498812
2023-07-11 11:23:39 -07:00
Michael Angerman
e10d84b72f
cratification: start moving over the math commands to nu-cmd-extra (#9647)
* arccos
* arccosh
* arcsin
* arcsinh
* arctan
* arctanh

The above commands are being ported over to nu-cmd-extra

I initially moved all of the math commands over but there are some
issues with the tests...

So we will move them over slowly --- and actually I kind of like this
idea better...

Because some of the math commands we might want to leave in the core
nushell...

Stay tuned...

For more details 👍 
Read this document:

https://github.com/stormasm/nutmp/blob/main/commands/math.md
2023-07-10 12:08:45 -07:00
dependabot[bot]
cf36f052c4
Bump strum from 0.24.1 to 0.25.0 (#9639) 2023-07-10 11:35:23 +00:00
Stefan Holderbach
a3702e1eb7
Bump indexmap to 2.0 (#9643)
# Description
Apart from `polars` (only used with `--features dataframe`) and the
dev-dependencies our deps use `indexmap 2.0`.
Thus the default or `extra` `cargo build` will reduce deps.
This also will help deduplicating `hashbrown` and `ahash`.

For #8060

- Bump `indexmap` to 2.0
- Remove unneeded `serde` feature from `indexmap`

# User-Facing Changes
None
2023-07-10 10:30:01 +02:00
Stefan Holderbach
92354a817c
Remove duplicated dependency on ansi-str 0.7 (#9641)
# Description
`tabled`/`papergrid` already use `ansi-str 0.8` while `nu-explore`
itself was still depending on `0.7`. Single fix necessary to adapt to
the new API.

cc @zhiburt

# User-Facing Changes
None
2023-07-10 09:24:08 +02:00
dependabot[bot]
79a9751a58
Bump scraper from 0.16.0 to 0.17.1 (#9638) 2023-07-10 05:28:36 +00:00
dependabot[bot]
47979651f3
Bump libproc from 0.13.0 to 0.14.0 (#9640) 2023-07-10 05:10:36 +00:00
Yethal
fabc0a3f45
test-runner: add configurable threading (#9628)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# 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.
-->
Max amount of threads used by the test runner can now be configured via
the `--threads` flag

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-08 11:27:56 +02:00
Ayush Singh
ad125abf6a
fixes which showing aliases as built-in nushell commands (#9580)
fixes #8577 

# Description
Currently, using `which` on an alias describes it as a nushell built-in
command:
```bash
> alias foo = print "foo!"                                                                                                                                                                                   > which ls foo --all                                                                                                                                                                                        
╭───┬─────┬──────────────────────────┬──────────╮
│ # │ arg │           path           │ built-in │
├───┼─────┼──────────────────────────┼──────────┤
│ 0 │ ls  │ Nushell built-in command │ true     │
│ 1 │ ls  │ /bin/ls                  │ false    │
│ 2 │ foo │ Nushell built-in command │ true     │
╰───┴─────┴──────────────────────────┴──────────╯
```

This PR fixes the behaviour above to the following:
```bash
> alias foo = print "foo!"
> which ls foo --all
╭───┬─────┬──────────────────────────┬──────────╮
│ # │ arg │           path           │ built-in │
├───┼─────┼──────────────────────────┼──────────┤
│ 0 │ ls  │ Nushell built-in command │ true     │
│ 1 │ ls  │ /bin/ls                  │ false    │
│ 2 │ foo │ Nushell alias            │ false    │
╰───┴─────┴──────────────────────────┴──────────╯
```

# User-Facing Changes
Passing in an alias to `which` will no longer return `Nushell built-in
command`, `true` for `path` and `built-in` respectively.

# Tests + Formatting

# After Submitting
2023-07-08 10:48:42 +02:00
mike
8e38596bc9
allow tables to have annotations (#9613)
# Description

follow up to #8529 and #8914

this works very similarly to record annotations, only difference being
that

```sh
table<name: string>
      ^^^^  ^^^^^^
      |     | 
      |     represents the type of the items in that column
      |
      represents the column name
```
more info on the syntax can be found
[here](https://github.com/nushell/nushell/pull/8914#issue-1672113520)

# User-Facing Changes

**[BREAKING CHANGE]**
this change adds a field to `SyntaxShape::Table` so any plugins that
used it will have to update and include the field. though if you are
unsure of the type the table expects, `SyntaxShape::Table(vec![])` will
suffice
2023-07-07 11:06:09 +02:00
Yethal
440a0e960a
test-runner: Performance improvements + regex match for test include/exclude (#9622)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# 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.
-->
Test-runner performance improved by:
* Not loading user config or stdlib during ide parsing
* Not loading user config during test execution
* Running tests in parallel instead of serially
On my machine `toolkit test stdlib` execution time went from 38s to 15s
(with all code precompiled)

Use regex match for test include/exclude and module exclude to allow for
multiple tests/modules to be excluded.
# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-07 09:20:36 +02:00
Han Junghyuk
85d47c299e
Fix explore crashes on {} (#9623)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

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

Fixes: #8479 

Co-authored-by: Jan9103 <55753387+Jan9103@users.noreply.github.com>

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: Jan9103 <55753387+Jan9103@users.noreply.github.com>
2023-07-06 20:17:55 -05:00
Yassine Haouzane
628a47e6dc
Fix: update engine_state when history.isolation is true (#9268) (#9616)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
Fixes #9268, the issue was due to the fact that when `history_isolation`
was set to true the engine_state's `session_id` wasn't updated.

This PR mainly refactors the code that updates the line_editor's history
information into one function `update_line_editor_history` and also
updates the engine_state's `session_id` when `history_isolation` is set
to `true` by calling the function `store_history_id_in_engine`.
<!--
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. -->
None since it's a bug fix.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

I tried to extract the block that was updating the line_editor's
`session_id` to make it easier to add a test.
The test checks that after a call to the function
`update_line_editor_history`, the `engine_state` and the returned
`line_editor` do have the same `session_id`.
2023-07-06 20:16:17 -05:00
Ian Manske
f38657e6f3
Fix headers command handling of missing values (#9603)
# Description
This fixes the `headers` command handling of missing values (issue
#9602). Previously, each row in the table would have its columns set to
be exactly equal to the first row even if it had less columns than the
first row. This would cause to values magically change their column or
cause panics in other commands if rows ended up having more columns than
values.

# Tests
Added a missing values  test for the `headers` command
2023-07-06 19:54:59 +02:00
Antoine Stevan
504eff73f0
REFACTOR: move the 0% commands to nu-cmd-extra (#9404)
requires
- https://github.com/nushell/nushell/pull/9455

# ⚙️ Description
in this PR i move the commands we've all agreed, in the core team, to
move out of the core Nushell to the `extra` feature.

> **Warning**
> in the first commits here, i've
> - moved the implementations to `nu-cmd-extra`
> - removed the declaration of all the commands below from `nu-command`
> - made sure the commands were not available anymore with `cargo run --
-n`

## the list of commands to move
with the current command table downloaded as `commands.csv`, i've run
```bash
let commands = (
    open commands.csv
    | where is_plugin == "FALSE" and category != "deprecated"
    | select name category "approv. %"
    | rename name category approval
    | insert treated {|it| (
        ($it.approval == 100) or                # all the core team agreed on them
        ($it.name | str starts-with "bits") or  # see https://github.com/nushell/nushell/pull/9241
        ($it.name | str starts-with "dfr")      # see https://github.com/nushell/nushell/pull/9327
    )}
)
```
to preprocess them and then
```bash
$commands | where {|it| (not $it.treated) and ($it.approval == 0)}
```
to get all untreated commands with no approval, which gives
```
╭────┬───────────────┬─────────┬─────────────┬──────────╮
│  # │     name      │ treated │  category   │ approval │
├────┼───────────────┼─────────┼─────────────┼──────────┤
│  0 │ fmt           │ false   │ conversions │        0 │
│  1 │ each while    │ false   │ filters     │        0 │
│  2 │ roll          │ false   │ filters     │        0 │
│  3 │ roll down     │ false   │ filters     │        0 │
│  4 │ roll left     │ false   │ filters     │        0 │
│  5 │ roll right    │ false   │ filters     │        0 │
│  6 │ roll up       │ false   │ filters     │        0 │
│  7 │ rotate        │ false   │ filters     │        0 │
│  8 │ update cells  │ false   │ filters     │        0 │
│  9 │ decode hex    │ false   │ formats     │        0 │
│ 10 │ encode hex    │ false   │ formats     │        0 │
│ 11 │ from url      │ false   │ formats     │        0 │
│ 12 │ to html       │ false   │ formats     │        0 │
│ 13 │ ansi gradient │ false   │ platform    │        0 │
│ 14 │ ansi link     │ false   │ platform    │        0 │
│ 15 │ format        │ false   │ strings     │        0 │
╰────┴───────────────┴─────────┴─────────────┴──────────╯
```
# 🖌️ User-Facing Changes
```
$nothing
```

# 🧪 Tests + Formatting
-  `toolkit fmt`
-  `toolkit clippy`
-  `toolkit test`
-  `toolkit test stdlib`

# 📖 After Submitting
```
$nothing
```

# 🔍 For reviewers
```bash
$commands | where {|it| (not $it.treated) and ($it.approval == 0)} | each {|command|
    try {
        help $command.name | ignore
    } catch {|e|
        $"($command.name): ($e.msg)"
    }
}
```
should give no output in `cargo run --features extra -- -n` and a table
with 16 lines in `cargo run -- -n`
2023-07-06 08:31:31 -07:00
Yethal
fbc1408913
test-runner: Add option to exclude single test and module (#9611)
# Description
This PR adds two additional flags to the test runner `--exclude` and
`--exclude-module` which as the name suggests allow to exclude tests
from a run
The now options only support a single test / module to exclude.

# User-Facing Changes

# Tests + Formatting

# After Submitting
2023-07-06 11:21:37 +02:00
mike
544c46e0e4
improve subtyping (#9614)
# Description

the current subtyping rule needs you to define the record entries in the
same order as declared in the annotation. this pr improves that

now
```nushell
{ name: 'Him', age: 12 } 

# ,

{ age: 100, name: 'It' }

# and

{ name: 'Red', age: 69, height: "5-8" }

# will all match

record<name: string, age: int>

# previously only the first one would match
```

however, something like

```nushell
{ name: 'Her' } # will not


# and

{ name: 'Car', wheels: 5 }
```

EDIT: applied JT's suggestion
2023-07-06 10:25:39 +02:00
nibon7
687b0e16f7
Replace users with nix crate (#9610)
# Description
The `users` crate hasn't been updated for a long time, this PR tries to
replace `users` with `nix`.
See [advisory
page](https://rustsec.org/advisories/RUSTSEC-2023-0040.html) for
additional details.
2023-07-06 00:07:07 +02:00
Stefan Holderbach
881c3495c1
Exclude deprecated commands from completions (#9612)
# Description
We previously simply searched all commands in the working set. As our
deprecated/removed subcommands are documented by stub commands that
don't do anything apart from providing a message, they were still
included.
With this change we check the `Signature.category` to not be
`Category::Deprecated`.

## Note on performance
Making this change will exercise `Command.signature()` more
frequently! As the rust-implemented commands include their builders here
this probably will cause a number of extra allocations. There is
actually no valid reason why the commands should construct a new
`Signature` for each call to `Command.signature()`.
This will introduce some overhead to generate the completions for
commands.
# User-Facing Changes
Example: `str <TAB>`


![grafik](https://github.com/nushell/nushell/assets/15833959/4d5ec5fe-aa93-45af-aa60-3854a20fcb04)
2023-07-05 23:13:16 +02:00
WindSoilder
406b606398
dependency: use notify-debouncer-full(based on notify v6) instead of notify v4 (#9606)
# Description

Closes: #9324

I have done some manually test locally on MacOS, and it seems fine for
me.

cc: @rgwood
2023-07-05 14:14:55 +02:00
Stefan Holderbach
168e7f7b16
Document fn pipeline() used with nu! tests (#9609)
# Description
Its purpose and its limitation around statements are not too obvious but
ubiquituous in our `nu!` tests. Document its behavior as we remove it in
many places for #8670


# User-Facing Changes
None
2023-07-05 13:19:54 +02:00
Antoine Stevan
53cd4df806
simplify the nu! tests for last and first commands (#9608)
# Description
in most of the tests for `last` and `first`, we do not need to
- give `cwd` to `nu!`
- use pipeline as the tests are all short pipes
- use `r#" ... "#` as the pipes never contain quotes

this PR removes all these points from the tests for the `last` and
`first` commands.
2023-07-05 12:30:53 +02:00
Hofer-Julian
65a163357d
Add pwd command to stdlib (#9607)
Closes #9601
2023-07-04 19:25:01 +02:00
Stefan Holderbach
1bdec1cbb6
Remove unnecessary parentheses (#9605)
# Description
As seen on nightly
2023-07-04 11:12:46 +02:00
JT
7e39179b7f
Move to using a safer shell integration default setting (#9600)
# Description

We're seeing some issues in a few terminals with the shell integration
support. Moving shell_integration to off by default to help with the
default user experience, but it will remain easy to re-enable for folks
who want to have the integration experience and a terminal that supports
it well.

# User-Facing Changes

This turns off shell integration by default, requiring the user to edit
the config and re-enable it.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-04 06:26:49 +12:00
Artemiy
2bb0c1c618
Command to get individual keys (#9453)
# Description
Add a `keybindings get` command to listen and get individual "keyboard"
events. This includes different keyboard keys (see example of use) on
seemingly all terminals and mouse, resize, focus and paste events on
some special once. The record returned by this command is similar to
crossterm event structure and is documented in help message. For ease of
use, option `--types` can get a list of event types to filter only
desired events automatically. Additionally `--raw` options displays raw
code of char keys and numeric format of modifier flags.

Example of use, moving a character around a grid with arrow keys:
```nu
def test [] {
  mut x = 0
  mut y = 0
  loop {
    clear
    $x = ([([$x 4] | math min) 0] | math max)
    $y = ([([$y 4] | math min) 0] | math max)

    for i in 0..4 {
      for j in 0..4 {
        if $j == $x and $i == $y {
          print -n "*"
        } else {
          print -n "."
        }
      }
      print ""
    }
    
    let inp = (input listen-t [ key ])
    match $inp.key {
      {type: other key: enter} => (break)
      {type: other key: up} => ($y = $y - 1)
      {type: other key: down} => ($y = $y + 1)
      {type: other key: left} => ($x = $x - 1)
      {type: other key: right} => ($x = $x + 1)
      _ => ()
    }
  }
}

```

# User-Facing Changes
- New `keybindngs get` command
- `keybindings listen` is left as is
- New `input display` command in std, mirroring functionality of
`keybindings listen`

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-03 10:23:44 -05:00
Julian Aichholz
9c7e37f728
Fix: return all headers with the same name from http <method> (#9594)
# Description

Hi nushell!

Thanks so much for [adding http headers][headers]! I've been waiting for
this feature for a long time and it's great. However, I found that
`Record` as a return type and using `ureq`'s `response.header` api
results in missing header values when there are multiple with the same
name, as can occur with `set-cookie` and others.

This issue with http has been discussed at length [on
stackoverflow][stackoverflow] and in [`ureq` itself][ureq]. It seems
like concatenating header values with `,` is a common solution, but
tricky especially with `set-cookie` which may contain `,` in the
`Expires` field, as discussed in the former post.

I propose changing the return type to a `List` of `Record` so we can get
all of the header values without relying on ad-hoc mutation. This
solution does not return the headers in the same order as they appear in
the `Response` due to `ureq`'s `Response.all` API, but it's better than
dropping values imo.

This is a **breaking change**. I'm sure `ureq`'s
[`CookieStore`][cookiestore] is a better long-term solution for
returning cookies as a separate record on `http <method>`, but other
headers can be set multiple times as well.

# User-Facing Changes
- Changes the return type of an `http <method>` `header` field from
`Record` to `List` (Table with columns `name` and `value`)
- Returns all values of a header set multiple times instead of just the
first one duplicated

# Implementation

Quick note that running `header_names.dedup()` does not resolve the
necessity to iterate through the previously parsed headers since `dedup`
only removes identical values when they are next to each other in the
`Vec`. You could do a `sort` first, but header ordering can be important
in some cases, so I tried to avoid messing with that more than is
already the case with `Response.all`. Would love to see a better way of
doing this though!

# Tests + Formatting
No tests broke implementing this change. Not sure what endpoint to hit
or mock server to use to verify this in tests. I have some screenshots
to illustrate what I'm talking about.

Before:
![Screenshot 2023-07-03 at 12 50 17
AM](https://github.com/nushell/nushell/assets/39018167/41604bef-54c6-424b-91b2-6b89a020e4ff)

> `set-cookie` has the same value for every record field.
> Even if it did not I'm not sure how you would access the different
values since they all have the same key.

After:
![Screenshot 2023-07-03 at 12 49 45
AM](https://github.com/nushell/nushell/assets/39018167/4ee45e6e-3785-471f-aee7-5af185cd06c2)

> Actual values from the response returned for the same name

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

- [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 -A clippy::result_large_err` to check that
you're using the standard code style
- [x] `cargo test --workspace` to check that all tests pass
- [x] `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library <-- Note: I did not see a `crates/nu-std/test/run.nu`
file so I ran the snippet below which returned without error
```nushell
for $i in (ls crates/nu-std/tests/*.nu) {
   cargo run -- $i.name
}
```

# Code of Conduct

Apologies for not opening an issue first. Just did this fix for myself
because it seemed simple enough before deciding to open this 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.
-->
- [ ] update docs

[stackoverflow]:
https://stackoverflow.com/questions/3241326/set-more-than-one-http-header-with-the-same-name
[headers]: https://github.com/nushell/nushell/pull/8571
[ureq]: https://github.com/algesten/ureq/issues/95
[cookiestore]:
https://docs.rs/cookie_store/latest/cookie_store/struct.CookieStore.html
2023-07-03 10:20:39 -05:00
baehyunsol
227d1d9508
make the behaviours of last and first more consistent (#9582)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description

- fixes #9567 

I have fixed everything mentioned in the issue, and made their help
messages more similar.

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

- Previously, `last` on binary data returned an integer. Now it returns
a binary
- Now, `[] | last` and `[] | first` are both errors.
- Now, `ls | table | first` and `ls | table | last` are both errors.
2023-07-03 10:19:50 -05:00
dependabot[bot]
9d76bf97a3
Bump calamine from 0.19.1 to 0.21.2 (#9592) 2023-07-03 09:46:32 +00:00
dependabot[bot]
9cd494cdfa
Bump ureq from 2.6.2 to 2.7.1 (#9590) 2023-07-03 09:45:18 +00:00
JT
5d9e2455f7
Let with pipeline (#9589)
# Description

This changes the default behaviour of `let` to be able to take a
pipeline as its initial value.

For example:

```
> let x = "hello world" | str length
```

This is a change from the existing behaviour, where the right hand side
is assumed to be an expression. Pipelines are more general, and can be
more powerful.

My google foo is failing me, but this also fixes this issue:

```
let x = foo
```

Currently, this reads `foo` as a bareword that gets converted to a
string rather than running the `foo` command. In practice, this is
really annoying and is a really hard to spot bug in a script.

# User-Facing Changes

BREAKING CHANGE BREAKING CHANGE

`let` gains the power to be assigned via a pipeline. However, this
changes the behaviour of `let x = foo` from assigning the string "foo"
to `$x` to being "run the command `foo` and give the result to `$x`"

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-03 17:45:10 +12:00
JT
b70cce47e2
disallow blocks as first-class values (#9587)
# Description

This PR disallows blocks as first-class values by removing the ability
to create them using the `block` syntax shape or type. Now, the parser
will only ever be able to create closures as first-class values.

This means that `{ 3 }` will always be treated as a closure, unless used
in the specifically supported use case of the literal being given as an
arg to `for`, `if` and other built-in block users.

Note: first-class value here means "value that can be passed into
commands and held in variables"

# User-Facing Changes

This may break some user scripts as `: block` is no longer allows as a
type annotation. Note: these cases were not actually supported before,
as, for example, passing a block that accessed a variable would have
errored when the block was later evaluated.

Closures do not have the restriction mentioned above and are the much
safer value to pass as first-class, so now they are the only block-like
value to be allowed to be passed.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-03 07:40:56 +12:00
WindSoilder
4acf21cdcf
Bracketed paste refactor (#9547)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
This pr is a completion of https://github.com/nushell/reedline/pull/598

After that pr is merged, we no longer need to disable bracketed mode in
nushell

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-02 14:11:12 -05:00
Yethal
9ef1203ef9
Implement annotations support in test runner (#9406)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
Test runner now uses annotations instead of magic function names to pick
up code to run. Additionally skipping tests is now done on annotation
level so skipping and unskipping a test no longer requires changes to
the test code

In order for a function to be picked up by the test runner it needs to
meet following criteria:
* Needs to be private (all exported functions are ignored)
* Needs to contain one of valid annotations (and only the annotation)
directly above the definition, all other comments are ignored

Following are considered valid annotations:
* \# test
* \# test-skip
* \# before-all
* \# before-each
* \# after-each
* \# after-all

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-02 10:41:33 +02:00
JT
7c80067900
use an easier-to-read date format in prompt (#9585)
# Description

Switches the right prompt to use an easier-to-read date format
(YYYY-MM-DD)

It's currently using (MM-DD-YYYY) which is only used in a few countries
but it is unfortunately ambiguous with countries that use (DD-MM-YYYY)
format (most countries). While YYYY-MM-DD is used in fewer countries
than DD-MM-YYYY it's at least unambiguous to MM-DD-YYYY countries.

More info: https://en.wikipedia.org/wiki/Date_format_by_country

Alternatively, we could spell out the month name (even abbreviated) to
make it clear as well.

# User-Facing Changes

Just changes the date in the default right prompt

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-02 20:25:22 +12:00
Darren Schroeder
49a1e22ba3
fix right prompt in the default_env.nu (#9581)
# Description

## Before

![image](https://github.com/nushell/nushell/assets/343840/4618c7b9-693c-4658-80e7-991464b8032f)

## After

![image](https://github.com/nushell/nushell/assets/343840/81305e69-fe47-46d9-b573-d9d1992f5088)


# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-02 12:47:26 +12:00
Darren Schroeder
ebd89d8b21
fix typo in deprecated message: $nu should be $env (#9579)
# Description

This PR fixes a small typeo where it has `$nu` and it should be `$env`.
2023-07-01 17:55:25 +02:00
Brian Mortenson
9547c106d3
Add useful example to http options documentation (#9576)
This PR adds a more real-world example of how the new http options is
used, as well as some additional information in the description.
2023-07-01 10:04:30 +02:00
JT
88b22a9248
fix a few clippy issues (#9578)
# Description

A couple clippy fixes

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-01 19:52:04 +12:00
JT
4af24363c2
remove let-env, focus on mutating $env (#9574)
# Description

For years, Nushell has used `let-env` to set a single environment
variable. As our work on scoping continued, we refined what it meant for
a variable to be in scope using `let` but never updated how `let-env`
would work. Instead, `let-env` confusingly created mutations to the
command's copy of `$env`.

So, to help fix the mental model and point people to the right way of
thinking about what changing the environment means, this PR removes
`let-env` to encourage people to think of it as updating the command's
environment variable via mutation.

Before:

```
let-env FOO = "BAR"
```

Now:

```
$env.FOO = "BAR"
```

It's also a good reminder that the environment owned by the command is
in the `$env` variable rather than global like it is in other shells.

# User-Facing Changes

BREAKING CHANGE BREAKING CHANGE

This completely removes `let-env FOO = "BAR"` so that we can focus on
`$env.FOO = "BAR"`.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After / Before Submitting
integration scripts to update:
- ✔️
[starship](https://github.com/starship/starship/blob/master/src/init/starship.nu)
- ✔️
[virtualenv](https://github.com/pypa/virtualenv/blob/main/src/virtualenv/activation/nushell/activate.nu)
- ✔️
[atuin](https://github.com/ellie/atuin/blob/main/atuin/src/shell/atuin.nu)
(PR: https://github.com/ellie/atuin/pull/1080)
- 
[zoxide](https://github.com/ajeetdsouza/zoxide/blob/main/templates/nushell.txt)
(PR: https://github.com/ajeetdsouza/zoxide/pull/587)
- ✔️
[oh-my-posh](https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/src/shell/scripts/omp.nu)
(pr: https://github.com/JanDeDobbeleer/oh-my-posh/pull/4011)
2023-07-01 07:57:51 +12:00
WindSoilder
cd56b97587
fix cd permissions when user belongs to folder group (#9531)
# Description

Fixes: #9498

Actually we don't need this pr if the upstream pr is merged:
https://github.com/ogham/rust-users/pull/45

But it doesn't have any commit since 2021, and the author seems not
active on github now, I think we have to copy the function into nushell
to get relative issue fixed...
2023-06-30 11:03:26 +02:00
WindSoilder
18fdc5a229
rename: add -b flag to support closure input (#8948)
# Description
Closes: #8108 

Adding a new `-b` flag to `rename` command. I have thought about making
it as a positional argument, but I don't think it's ok because we alredy
have `...rest` parameters

Here are how they works:
```
#  Rename fields based on a given closure
> {a: 1, b: 2} | rename -b {str upcase}
  ╭───┬───╮
  │ A │ 1 │
  │ B │ 2 │
  ╰───┴───╯

#  Rename fields based on fields' value
> {a: abc, b: def} | rename -b {|it| $it.value | str upcase}
  ╭─────┬─────╮
  │ ABC │ abc │
  │ DEF │ def │
  ╰─────┴─────╯
```
# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-29 10:24:34 -05:00
dependabot[bot]
3699188586
Bump open from 4.1.0 to 5.0.0 (#9526) 2023-06-29 13:30:07 +00:00
Darren Schroeder
88acc11501
add input_output type to input list to return string (#9557)
# Description

This PR fixes a bug that @amtoine found. It adds an input_output type so
that `input list`'s signature supports `string` as an output.

## Before

![image](https://github.com/nushell/nushell/assets/343840/7ee2b672-9976-4c69-a9a2-686ddbd3a60d)
```
Signatures:
  list<any> | input list <string?> -> list<any>
```

## After

![image](https://github.com/nushell/nushell/assets/343840/f86747cf-a134-4bb0-b89c-2e28f590f3c3)
```
Signatures:
  list<any> | input list <string?> -> list<any>
  list<string> | input list <string?> -> <string>
```

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-29 08:27:25 -05:00
Maxim Zhiburt
b52e31fac2
Fix #9548 (#9552)
close #9548

Could you verify @fdncred the fix?

PS: Maybe a test shall be created (to test proper colors)?

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-06-28 17:52:04 -05:00
Darren Schroeder
3fd92b6437
convert a string to a raw binary string of 0s and 1s (#9534)
# Description

This PR converts a string into a raw binary represented by a string of
0s and 1s padded to 8 digits with zeros.

This is useful for encoding data.

![image](https://github.com/nushell/nushell/assets/343840/66864c79-3da1-4007-a62b-306ed85f4df4)

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-28 13:04:07 -05:00
A. Taha Baki
d80abb20a4
A new subcommand to str, str-expand. (#9290)
# 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.
-->

Description can be found [here:
https://github.com/nushell/nushell/discussions/9277#discussioncomment-5997793](https://github.com/nushell/nushell/discussions/9277#discussioncomment-5997793)

# User-Facing Changes

Again, examples can be found in the discussion #9277

<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting

I've written tests that cover the changes I've made.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-06-28 12:57:44 -05:00
JT
9068093081
Improve type hovers (#9515)
# Description

This PR does a few things to help improve type hovers and, in the
process, fixes a few outstanding issues in the type system. Here's a
list of the changes:

* `for` now will try to infer the type of the iteration variable based
on the expression it's given. This fixes things like `for x in [1, 2, 3]
{ }` where `x` now properly gets the int type.
* Removed old input/output type fields from the signature, focuses on
the vec of signatures. Updated a bunch of dataframe commands that hadn't
moved over. This helps tie things together a bit better
* Fixed inference of types from subexpressions to use the last
expression in the block
* Fixed handling of explicit types in `let` and `mut` calls, so we now
respect that as the authoritative type

I also tried to add `def` input/output type inference, but unfortunately
we only know the predecl types universally, which means we won't have
enough information to properly know what the types of the custom
commands are.

# User-Facing Changes

Script typechecking will get tighter in some cases
Hovers should be more accurate in some cases that previously resorted to
any.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-06-29 05:19:48 +12:00
Darren Schroeder
9d247387ea
update sqlparser dep to 0.34 (#9549)
# Description

This PR updates the sqlparser dep to 0.34.0.

closes #9525

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-28 09:54:08 -05:00
dependabot[bot]
283589dc2f
Bump rust-embed from 6.6.1 to 6.7.0 (#9528) 2023-06-27 21:09:04 +00:00
Stefan Holderbach
088e6dffbe
Bump to 0.82.1 dev version (#9543)
# Description
Marks development or hotfix
2023-06-27 21:33:53 +02:00
Stefan Holderbach
ecdb023e2f
Bump version for 0.82.0 release (#9530)
# Checklist

- `nu-ansi-term` remains the same
- [x] `reedline` is released and updated
- [x] release scripts are updated for `nu-cmd-base`
- [x] info blog post is online
- [ ] release notes are ready
2023-06-27 19:11:46 +02:00
Stefan Holderbach
63aba5feb7
Pin reedline to 0.21 for release (#9532)
# Description
See changelog:
https://github.com/nushell/reedline/releases/tag/v0.21.0
2023-06-26 12:47:59 +02:00
Taylor C. Richberger
08449e174c
Format negative datetimes with rfc3339 (#9501) (#9502)
- fixes #9501 

# Description

`chrono::Datetime::to_rfc2822()` panics when it would format a negative
year. 3339 does not. This makes negative-year datetimes inconsistent
compared to positive ones, but it's better than a panic.
2023-06-25 13:53:17 -05:00
Stefan Holderbach
971f9ae0f0
Skip strum in regular nu-protocol build (#9445)
# Description
`derive(EnumIter)` is only required to run completeness tests.
Thus make the derive conditional on test and move `strum` and
`strum_macros` to the dev dependencies.

## Is it worth it?

Removing this derive does not change the binary size (checked via `cargo
bloat --crates` from `cargo-bloat`).
Compile time change is below a second so hard to judge based on a single
run of `cargo clean --profile dev; cargo build --timings`
Unsure if this negatively impacts how incremental compilation can
recompile when you switch between `cargo build`/`run` and `cargo test`
in your local workflow.

To get rid of `strum`/`strum_macros` as a proc macro crate we would need
to also remove it from `reedline`.
Further more a crate in the `polars` dependency tree uses `strum`
(curently not as relevant for the 1.0 build).
2023-06-25 20:28:37 +02:00
JT
33535c514e
Better error message if env var is used as var (#9522)
# Description

This PR improves the error message if an environment variable (that's
visible before the parser begins) is used in the form of `$PATH` instead
of `$env.PATH`.

Before:

```
Error: nu::parser::variable_not_found

  × Variable not found.
   ╭─[entry #31:1:1]
 1 │ echo $PATH
   ·      ──┬──
   ·        ╰── variable not found.
   ╰────
```

After:

```
Error: nu::parser::env_var_not_var

  × Use $env.PATH instead of $PATH.
   ╭─[entry #1:1:1]
 1 │ echo $PATH
   ·      ──┬──
   ·        ╰── use $env.PATH instead of $PATH
   ╰────
```

# User-Facing Changes

Just the improvement to the error message

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-26 05:59:56 +12:00
TrMen
b74d508c0b
Test examples of use (#9032)
# Description
Add `test_examples()` to `use` that verifies its examples. For that, add
the necessary definitions and the `PWD` to the `nu-cmd-lang` test
support.

Note: `let-env` is a `nu-command` and thus not accessible from the
`nu-cmd-lang` tests. So replace `let-env` with `$env.<var> =`. This
should be fine, since `let-env` is supposed to be removed before 1.0
anyway.


# User-Facing Changes
Nothing

# Question for reviewer
Is there any particular reason why so many core commands (parser
keywords) don't verify their examples with tests? E.g. `break`, `hide`,
`overlay use`, etc. (I think most of them?). If there is no particular
reason, I'd make a follow up PR to enable tests for as many of them as
possible.
2023-06-25 07:43:48 -05:00
Michael Angerman
14daa93a19
Modify the bits command in nu-cmd-extra to improve visibility (#9516)
In the spirit of #9509 we are changing the visibility of the bits
commands
to align with the way they are correctly done in the bytes commands...

Thanks to @sholderbach for pointing out this nice improvement
to me in my PR earlier in the day...

```rust
mod and;
mod bits_;
mod not;
mod or;
mod rotate_left;
mod rotate_right;
mod shift_left;
mod shift_right;
mod xor;
```
2023-06-23 21:41:14 -07:00
Darren Schroeder
761946c522
add the ability to combine columns with detect columns (#9511)
# Description

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

For example, if you want to parse the output of bash's `ls` command, the
output passed into `detect columns` would look similar to this.
```
❯ ^ls -lh
total 242K
-rw-r--r-- 1 dschroeder 197121 3.5K Mar 30 10:10 CODE_OF_CONDUCT.md
-rw-r--r-- 1 dschroeder 197121  11K Jun 21 14:16 CONTRIBUTING.md
-rw-r--r-- 1 dschroeder 197121 153K Jun 21 14:16 Cargo.lock
-rw-r--r-- 1 dschroeder 197121 5.7K Jun 21 08:47 Cargo.toml
-rw-r--r-- 1 dschroeder 197121  371 Mar 30 10:10 Cross.toml
-rw-r--r-- 1 dschroeder 197121 1.1K Apr  3 08:37 LICENSE
-rw-r--r-- 1 dschroeder 197121  13K Jun 21 14:16 README.md
drwxr-xr-x 1 dschroeder 197121    0 May 24 08:06 assets
drwxr-xr-x 1 dschroeder 197121    0 Jun 21 14:16 benches
-rw-r--r-- 1 dschroeder 197121  310 Mar 30 10:10 codecov.yml
drwxr-xr-x 1 dschroeder 197121    0 Jun  1 15:30 crates
drwxr-xr-x 1 dschroeder 197121    0 May  4 07:55 dict
drwxr-xr-x 1 dschroeder 197121    0 Mar 30 10:10 docker
-rw-r--r-- 1 dschroeder 197121 1.1K Jun 12 07:03 rust-toolchain.toml
drwxr-xr-x 1 dschroeder 197121    0 May 26 07:11 scripts
drwxr-xr-x 1 dschroeder 197121    0 Jun 15 07:14 src
drwxr-xr-x 1 dschroeder 197121    0 Jun 21 09:48 target
drwxr-xr-x 1 dschroeder 197121    0 Jun 21 12:30 tests
-rw-r--r-- 1 dschroeder 197121  16K Jun 21 14:16 toolkit.nu
drwxr-xr-x 1 dschroeder 197121    0 Jun  1 15:30 wix
```
Running it through `detect columns` is helpful but notice how the Month,
Day, and Time are in their own columns.
```
❯ ^ls -lh | detect columns --no-headers --skip 1
╭────┬────────────┬─────────┬────────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────────────────╮
│  # │  column0   │ column1 │  column2   │ column3 │ column4 │ column5 │ column6 │ column7 │       column8       │
├────┼────────────┼─────────┼────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────────────────┤
│  0 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 3.5K    │ Mar     │ 30      │ 10:10   │ CODE_OF_CONDUCT.md  │
│  1 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 11K     │ Jun     │ 21      │ 14:16   │ CONTRIBUTING.md     │
│  2 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 153K    │ Jun     │ 21      │ 14:16   │ Cargo.lock          │
│  3 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 5.7K    │ Jun     │ 21      │ 08:47   │ Cargo.toml          │
│  4 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 371     │ Mar     │ 30      │ 10:10   │ Cross.toml          │
│  5 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 1.1K    │ Apr     │ 3       │ 08:37   │ LICENSE             │
│  6 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 13K     │ Jun     │ 21      │ 14:16   │ README.md           │
│  7 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May     │ 24      │ 08:06   │ assets              │
│  8 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 21      │ 14:16   │ benches             │
│  9 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 310     │ Mar     │ 30      │ 10:10   │ codecov.yml         │
│ 10 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 1       │ 15:30   │ crates              │
│ 11 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May     │ 4       │ 07:55   │ dict                │
│ 12 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Mar     │ 30      │ 10:10   │ docker              │
│ 13 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 1.1K    │ Jun     │ 12      │ 07:03   │ rust-toolchain.toml │
│ 14 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May     │ 26      │ 07:11   │ scripts             │
│ 15 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 15      │ 07:14   │ src                 │
│ 16 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 21      │ 09:48   │ target              │
│ 17 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 21      │ 12:30   │ tests               │
│ 18 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 16K     │ Jun     │ 21      │ 14:16   │ toolkit.nu          │
│ 19 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 1       │ 15:30   │ wix                 │
├────┼────────────┼─────────┼────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────────────────┤
│  # │  column0   │ column1 │  column2   │ column3 │ column4 │ column5 │ column6 │ column7 │       column8       │
╰────┴────────────┴─────────┴────────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────────────────╯
```
Now you can add `--combine-columns <range>` and get something like this.
```
❯ ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7
╭────┬────────────┬─────────┬────────────┬─────────┬─────────┬──────────────┬─────────────────────╮
│  # │  column0   │ column1 │  column2   │ column3 │ column4 │   column5    │       column6       │
├────┼────────────┼─────────┼────────────┼─────────┼─────────┼──────────────┼─────────────────────┤
│  0 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 3.5K    │ Mar 30 10:10 │ CODE_OF_CONDUCT.md  │
│  1 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 11K     │ Jun 21 14:16 │ CONTRIBUTING.md     │
│  2 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 153K    │ Jun 21 14:16 │ Cargo.lock          │
│  3 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 5.7K    │ Jun 21 08:47 │ Cargo.toml          │
│  4 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 371     │ Mar 30 10:10 │ Cross.toml          │
│  5 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 1.1K    │ Apr 3 08:37  │ LICENSE             │
│  6 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 13K     │ Jun 21 14:16 │ README.md           │
│  7 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May 24 08:06 │ assets              │
│  8 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 21 14:16 │ benches             │
│  9 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 310     │ Mar 30 10:10 │ codecov.yml         │
│ 10 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 1 15:30  │ crates              │
│ 11 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May 4 07:55  │ dict                │
│ 12 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Mar 30 10:10 │ docker              │
│ 13 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 1.1K    │ Jun 12 07:03 │ rust-toolchain.toml │
│ 14 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May 26 07:11 │ scripts             │
│ 15 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 15 07:14 │ src                 │
│ 16 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 21 09:48 │ target              │
│ 17 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 21 12:30 │ tests               │
│ 18 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 16K     │ Jun 21 14:16 │ toolkit.nu          │
│ 19 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 1 15:30  │ wix                 │
├────┼────────────┼─────────┼────────────┼─────────┼─────────┼──────────────┼─────────────────────┤
│  # │  column0   │ column1 │  column2   │ column3 │ column4 │   column5    │       column6       │
╰────┴────────────┴─────────┴────────────┴─────────┴─────────┴──────────────┴─────────────────────╯
```
Then you can fancy-it-up by tweaking the other columns and renaming
columns.
```
❯ ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7 | update column5 {|r| $r.column5 | into datetime} | into int column1 column3 | into filesize column4 | rename perms links user inode filesize datetime name
╭────┬────────────┬───────┬────────────┬────────┬──────────┬──────────────┬─────────────────────╮
│  # │   perms    │ links │    user    │ inode  │ filesize │   datetime   │        name         │
├────┼────────────┼───────┼────────────┼────────┼──────────┼──────────────┼─────────────────────┤
│  0 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │   3.5 KB │ 2 months ago │ CODE_OF_CONDUCT.md  │
│  1 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │  11.0 KB │ 2 days ago   │ CONTRIBUTING.md     │
│  2 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │ 153.0 KB │ 2 days ago   │ Cargo.lock          │
│  3 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │   5.7 KB │ 2 days ago   │ Cargo.toml          │
│  4 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │    371 B │ 2 months ago │ Cross.toml          │
│  5 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │   1.1 KB │ 2 months ago │ LICENSE             │
│  6 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │  13.0 KB │ 2 days ago   │ README.md           │
│  7 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ a month ago  │ assets              │
│  8 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 days ago   │ benches             │
│  9 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │    310 B │ 2 months ago │ codecov.yml         │
│ 10 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 3 weeks ago  │ crates              │
│ 11 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 months ago │ dict                │
│ 12 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 months ago │ docker              │
│ 13 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │   1.1 KB │ 2 weeks ago  │ rust-toolchain.toml │
│ 14 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 4 weeks ago  │ scripts             │
│ 15 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ a week ago   │ src                 │
│ 16 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 days ago   │ target              │
│ 17 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 days ago   │ tests               │
│ 18 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │  16.0 KB │ 2 days ago   │ toolkit.nu          │
│ 19 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 3 weeks ago  │ wix                 │
├────┼────────────┼───────┼────────────┼────────┼──────────┼──────────────┼─────────────────────┤
│  # │   perms    │ links │    user    │ inode  │ filesize │   datetime   │        name         │
╰────┴────────────┴───────┴────────────┴────────┴──────────┴──────────────┴─────────────────────╯
```
# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-23 16:19:08 -05:00
WMR
0c888486c9
Add custom datetime format through strftime strings (#9500)
- improves usability of datetime's in displayed text
- 
# Description
Creates a config point for specifying long / short date time formats.
Defaults to humanized as we have today.

Provides for adding strftime formats into config.nu such as:
```nu
  datetime_format: {
    normal: "%Y-%m-%d %H:%M:%S"
    table: "%Y-%m-%d"
  }
```

Example:
```bash
> $env.config.datetime_format                                                                                                                         
┏━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ normal ┃ %a, %d %b %Y %H:%M:%S %z ┃
┃ table  ┃ %m/%d/%y %I:%M:%S%p      ┃
┗━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━┛
> let a = (date now)                                                                                                                                  
> echo $a                                                                                                                                             
Thu, 22 Jun 2023 10:21:23 -0700
> echo [$a]                                                                                                                                           
┏━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ 0 ┃ 06/22/23 10:21:23AM ┃
┗━━━┻━━━━━━━━━━━━━━━━━━━━━┛
```

# User-Facing Changes
Any place converting a datetime to a user displayed value should be
impacted.

# Tests + Formatting

- `cargo fmt --all -- --check` Done
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` Done
- `cargo test --workspace` Done 
- `cargo run -- crates/nu-std/tests/run.nu` Not done - doesn't seem to
work

```bash
> use toolkit.nu  # or use an `env_change` hook to activate it automatically
> toolkit check pr
``` - Done

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Co-authored-by: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
2023-06-23 15:05:04 -05:00
Michael Angerman
d1449c4ee7
cratification: move the bytes command to nu-cmd-extra (#9509)
now that #9455 has landed we can move the bytes command to nu-cmd-extra

in concert with

moving nu_command::util to nu-cmd-base
2023-06-23 12:23:08 -07:00
David Scholberg
81abb17b38
Add multiline regex flag to str replace (#9508)
# Description

This change adds a new flag to the `str replace` command: `--multiline`,
`-m`. This flag will automatically add the multiline regex flag `(?m)`
to the beginning of the supplied regex, allowing for the `^` and `$`
regex characters to match the beginnings and ends of lines,
respectively.

The main advantage of this addition is to make `str replace` more
closely match sed's default behavior of performing matches per-line with
a simple cli flag as opposed to forcing the user to add the {somewhat
clunky) regex flag themselves. This could be an especially valuable
addition since [`str replace` is listed as an alternative to sed in the
official
documentation](https://www.nushell.sh/book/coming_from_bash.html).

With this change, the following two commands would be functionally
equivalent:

```bash
# bash
printf "non-matching line\n123. one line\n124. another line\n" | sed -r 's/^[0-9]+\. //'
```

```bash
# nu
"non-matching line\n123. one line\n124. another line\n" | str replace -am '^[0-9]+\. ' ''
```

both producing the following output:

```
non-matching line
one line
another line
```

# User-Facing Changes

1. Adds a new flag to the `str replace` command: `--multiline`, `-m`.

# Tests + Formatting

I have update the unit tests to test this flag.
<!--
Don't forget to add tests that cover your changes.

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
I will submit a PR for all relevant documentation changes as soon as
this PR is approved.
2023-06-23 20:08:02 +02:00
Darren Schroeder
cbb9f8efe4
clean up config by removing legacy options (#9496)
# Description

This PR cleans up the deprecated legacy config options that were
deprecated in nushell version 0.72.0. These are the config points that
were in the root of the config but also duplicated in the nested
structures. For instance `use_ls_colors` was in the root of the config
and also in the `ls.use_ls_colors` nested structure. This was originally
done to preserve backwards compatibility when nested structures were
introduced in the config file.

Here's a list of the legacy config points that were removed.

- `use_ls_colors` - previously replaced with `ls.use_ls_colors`
- `rm_always_trash` - previously replaced with `rm.always_trash`
- `history_file_format` - previously replaced with `history.file_format`
- `sync_history_on_enter` - previously replaced with
`history.sync_on_enter`
- `max_history_size` - previously replaced with `history.max_size`
- `quick_completions` - previously replaced with `completions.quick`
- `partial_completions` - previously replaced with `completions.partial`
- `max_external_completion_results` - previously replaced with
`completions.external.max_results`
- `completion_algorithm` - previously replaced with
`completions.algorithm`
- `case_sensitive_completions` - previously replaced with
`completions.case_sensitive`
- `enable_external_completion` - previously replaced with
`completions.external.enable`
- `external_completer` - previously replaced with
`completions.external.completer`
- `table_mode` - previously replaced with `table.mode`
- `table_index_mode` - previously replaced with `table.index_mode`
- `table_trim` - previously replaced with `table.trim`
- `show_clickable_links_in_ls` - previously replaced with
`ls.clickable_links`
- `cd_with_abbreviations` - previously replaced with `cd.abbreviations`
- `filesize_metric` - previously replaced with `filesize.metric`
- `filesize_format` - previously replaced with `filesize.format`
- `cursor_shape_vi_insert` - previously replaced with
`cursor_shape.vi_insert`
- `cursor_shape_vi_normal` - previously replaced with
`cursor_shape.vi_normal`
- `cursor_shape_emacs` - previously replaced with `cursor_shape.emacs`

Removes log_level from the config since it doesn't do anything any
longer. We moved log-level to a nushell parameter some time ago.

Renames history_isolation to isolation in the config.nu for consistency.

Fixes a couple bugs where values weren't being set in the "//
Reconstruct" sections (history_isolation, table_show_empty).

Reorganized/Moved things around a tiny bit and added a few comments.

# User-Facing Changes

history.histor_isolation is now history.isolation.
If anyone is still using the legacy config points, deprecated since
0.72.0 2022-11-29, their config will break.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-23 06:17:10 -05:00
Darren Schroeder
a0dafcb0f8
make history.max_size bigger (#9494)
# Description

make history.max_size bigger so it doesn't eat history

closes #9493

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-22 19:42:55 -05:00
Antoine Stevan
78697bb8cf
move common tools from nu-command to nu-cmd-base (#9455)
related to 
- https://github.com/nushell/nushell/pull/9404

# Description
to support our cratification effort and moving non-1.0 commands outside
of the main focus, this PR
- creates a new `nu-cmd-base` crate to hold the common structs, traits
and functions used by all command-related crates
- to start the transition, moves the `input_handler` module from
`nu-command` to `nu-cmd-base`

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

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

# After Submitting
```
$nothing
```
2023-06-22 14:45:54 -07:00
JT
fbf3f7cf1c
split $nu variable into scope commands and simpler $nu (#9487)
# Description

This splits off `scope` from `$nu`, creating a set of `scope` commands
for the various types of scope you might be interested in.

This also simplifies the `$nu` variable a bit.

# User-Facing Changes

This changes `$nu` to be a bit simpler and introduces a set of `scope`
subcommands.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-21 09:33:01 +12:00
Antoine Stevan
aaa21c1619
make *dots* tests easier to read (#9467)
related to
- https://github.com/nushell/nushell/pull/8544

cc/ @jntrnr @ahkrr 

# Description
some of the tests in the `dots.rs` file are a bit hard to read because
some of the paths look like command calls 🤔

in an attempt to making them easier to read, in the tests of `dots.rs`,
this PR
- replaces `file .../` with `not_a_cmd.../` because it's not a call to
the `file` command
- removes the space in `not_a_cmd .../` to see it's not a command call
- adds a bit more `not a cmd` to the last tests, to be consistent with
the other tests

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

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
-  `toolkit test`
-  `toolkit test stdlib`
2023-06-20 20:28:10 +12:00
Stefan Holderbach
1be4eaeae3
Revert #8395 "Treat empty pipelines as pass-through" (#9472)
In my view we should revert nushell/nushell#8395 for now

## Potentially inconsistent application of semantic change
#8395 (1d5e7b441b) was loosening the type
coercion rules significantly, to let missing data / void returns that
were either expressed by `PipelineData::Empty` or the `Value::nothing`
be accept by specifically those commands/operations that made use of
`PipelineData::into_iter_strict()`. This could apply the new rules
inconsistently.

## Turning explicit failures into silent continuations
Furthermore the effect of this breaking change to the missing data
semantics could make previous errors into silent failures.
This could either just reduce the effectiveness of teaching error
messages in interactive use:

### Contrived example before
```bash
> cd . | where blah
Error: nu:🐚:only_supports_this_input_type

  × Input type not supported.
   ╭─[entry #13:1:1]
 1 │ cd . | where blah
   ·        ──┬──┬
   ·          │  ╰── input type: null
   ·          ╰── only list, binary, raw data or range input data is supported
   ╰────
```
### ...after, with #8395
```bash
> cd . | where blah
╭────────────╮
│ empty list │
╰────────────╯
```

In rare cases people could already try to rely on catching an error of a
downstream command to actually deal with the missing data, so it would
be a breaking change for their existing code.

## Problem with `PipelineData::into_iter_strict()`

Maybe this makes `_strict` a bit of a misnomer for this particular
iterator construction.
Further we did not actively test the `PipelineData::empty` branch before

![grafik](https://github.com/nushell/nushell/assets/15833959/c377bf1d-d47c-4c25-a342-9a348539f242)

## Parsimonious solution exists

For the motivating issue https://github.com/nushell/nushell/issues/8393
there already exists a fix that makes `ls` more consistent with the type
system by returning an empty `Value::List`
https://github.com/nushell/nushell/pull/8439
2023-06-20 20:27:18 +12:00
Maxim Zhiburt
2ec1364925
nu-table/ Fix indexing issue for table --expand (#9484)
close #9481

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-06-20 20:27:00 +12:00
nibon7
69bf43ef56
Apply nightly clippy fixes (#9482)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
This PR fixes the following nightly clippy warnings.

```
warning: you should consider adding a `Default` implementation for `HjsonFormatter<'a>`
   --> crates/nu-json/src/ser.rs:700:5
    |
700 | /     pub fn new() -> Self {
701 | |         HjsonFormatter::with_indent(b"  ")
702 | |     }
    | |_____^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
    = note: `#[warn(clippy::new_without_default)]` on by default
help: try adding this
    |
698 + impl<'a> Default for HjsonFormatter<'a> {
699 +     fn default() -> Self {
700 +         Self::new()
701 +     }
702 + }
    |

warning: `nu-json` (lib) generated 1 warning
warning: private item shadows public glob re-export
  --> crates/nu-command/src/strings/mod.rs:8:1
   |
8  | mod str_;
   | ^^^^^^^^^
   |
note: the name `str_` in the type namespace is supposed to be publicly re-exported here
  --> crates/nu-command/src/strings/mod.rs:17:9
   |
17 | pub use str_::*;
   |         ^^^^^^^
note: but the private item here shadows it
  --> crates/nu-command/src/strings/mod.rs:8:1
   |
8  | mod str_;
   | ^^^^^^^^^
   = note: `#[warn(hidden_glob_reexports)]` on by default

warning: incorrect NaN comparison, NaN cannot be directly compared to itself
   --> crates/nu-command/src/formats/to/nuon.rs:186:20
    |
186 |                 && val != &f64::NAN
    |                    ^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(invalid_nan_comparisons)]` on by default
help: use `f32::is_nan()` or `f64::is_nan()` instead
    |
186 -                 && val != &f64::NAN
186 +                 && !val.is_nan()
    |

warning: `nu-command` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p nu-command` to apply 1 suggestion)
   Compiling nu v0.81.1 (/data/source/nushell)
warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> crates/nu-command/tests/commands/rm.rs:392:27
    |
392 |             dir_to_clean: &test_dir,
    |                           ^^^^^^^^^ help: change this to: `test_dir`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
    = note: `#[warn(clippy::needless_borrow)]` on by default

warning: `nu-command` (test "main") generated 1 warning (run `cargo clippy --fix --test "main"` to apply 1 suggestion)
warning: `nu-command` (lib test) generated 2 warnings (2 duplicates)
warning: `nu-json` (lib test) generated 1 warning (1 duplicate)
    Finished dev [unoptimized + debuginfo] target(s) in 3.89s

```

# User-Facing Changes
N/A

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-20 10:17:33 +02:00
Sygmei
d25fb3ad56
Fix/input suppress output on windows (#9459)
this PR should close #9018

# Description
This PR aims to fix the `input` command with `--suppress-output` on
Windows
This fixes two separates issues : 
- Keypresses being duplicated in output due to "Release" event not being
ignored
- "Return" event from entering the `input -s "blah :"` still being in
the event buffer (need to be cleared before reading keypresses)

# Tests + Formatting

- `cargo fmt --all -- --check` ✔️ 
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` ✔️
- `cargo test --workspace` ✔️
- `cargo run -- crates/nu-std/tests/run.nu` ✔️
2023-06-19 19:04:37 +02:00
dependabot[bot]
d78e3c3b0d
Bump shadow-rs from 0.22.0 to 0.23.0 (#9473) 2023-06-19 12:40:17 +00:00
dependabot[bot]
de41c9eaf7
Bump percent-encoding from 2.2.0 to 2.3.0 (#9475) 2023-06-19 07:00:12 +00:00
dependabot[bot]
63e30899f7
Bump quick-xml from 0.28.2 to 0.29.0 (#9477) 2023-06-19 06:17:37 +00:00
dependabot[bot]
379260b110
Bump mockito from 1.0.2 to 1.1.0 (#9476) 2023-06-19 06:16:55 +00:00
dependabot[bot]
d2629293e8
Bump once_cell from 1.17.1 to 1.18.0 (#9474) 2023-06-19 06:16:00 +00:00
ahkrr
fa957a1a07
fix: 3 or more dots in file paths (#8544)
# Description
In cases that a path contained 3 or more `.` in succession followed by a
path-separator, the dots would be expanded.
This logic didn't take into account the cases where characters other
than a separator could appear before the `...`, which would lead to
`...` in filenames being expanded.
This PR changes the behavior so that path-segments consisting of 3 or
more dots only will be expanded.
This PR fixes issue #8386


# User-Facing Changes
Paths with filenames like `.../folder.../file.txt` will be correctly
expanded.

# Tests + Formatting

I added tests that cover a number of cases.
2023-06-18 15:21:57 +02:00
JT
1d5e7b441b
Treat empty pipelines as pass-through (#8395)
# Description

This allows empty pipelines to pass their emptiness through a filter.
This helps fix issues like trying to run a filter on an `ls` in an empty
directory. It also feels a bit more reasonable that a filter filters
what is *there* but doesn't require something to be there.

fixes #8393

# User-Facing Changes

No breaking changes (that I know of). Should allow filtering to be a
little less surprising with emptiness.

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

---------

Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-18 11:40:18 +02:00
Michael Albers
c12b211075
Fix missing file names from rm errors (#9120)
# Description
Fixes a small bug with `rm` where names of files which couldn't be
deleted due to error were not printed.

Fixes https://github.com/nushell/nushell/issues/9004

# User-Facing Changes
Slightly different error message than previously. Nothing significant,
though.

The new error message looks like this
```
~/Projects/rust/nushell> rm /proc/1/mem                                                                                                                                                            05/06/2023 01:13:23 PM
Error: nu:🐚:remove_not_possible

  × Remove not possible
   ╭─[entry #3:1:1]
 1 │ rm /proc/1/mem
   ·    ─────┬─────
   ·         ╰── Could not delete /proc/1/mem: Operation not permitted (os error 1)
   ╰────

```

or when using a glob (only showing a single entry for brevity)

```
Error: nu:🐚:remove_not_possible

  × Remove not possible
   ╭─[entry #2:1:1]
 1 │ rm --recursive --force --verbose /proc/1/*
   ·                                  ────┬────
   ·                                      ╰── Could not delete /proc/1/comm: Operation not permitted (os error 1)
   ╰────
```

# Tests + Formatting
No new unit tests were added for this change as it is pretty difficult
to test this particular case. However, manual testing was run with the
following commands

```
rm /proc/1/mem
rm --recursive --force --verbose /proc/1/*
```

# After Submitting
N/A
2023-06-18 10:00:12 +02:00
JT
6c730def4b
revert: move to ahash (#9464)
This PR reverts https://github.com/nushell/nushell/pull/9391

We try not to revert PRs like this, though after discussion with the
Nushell team, we decided to revert this one.

The main reason is that Nushell, as a codebase, isn't ready for these
kinds of optimisations. It's in the part of the development cycle where
our main focus should be on improving the algorithms inside of Nushell
itself. Once we have matured our algorithms, then we can look for
opportunities to switch out technologies we're using for alternate
forms.

Much of Nushell still has lots of opportunities for tuning the codebase,
paying down technical debt, and making the codebase generally cleaner
and more robust. This should be the focus. Performance improvements
should flow out of that work.

Said another, optimisation that isn't part of tuning the codebase is
premature at this stage. We need to focus on doing the hard work of
making the engine, parser, etc better.

# User-Facing Changes

Reverts the HashMap -> ahash change.

cc @FilipAndersson245
2023-06-18 15:27:57 +12:00
Stefan Holderbach
f032e28657
Remove duplicated feature in nu-cmd-dataframe dep (#9461)
Minor fixup
2023-06-17 12:55:29 +02:00
Antoine Stevan
bb30051006
add a "capture" example to str replace, before the fancy ones (#9447)
closes https://github.com/nushell/nushell/issues/9437
cc/ @Sygmei 😉 

# Description
the syntax of *captures* used in `str replace` can be confusing for
people not used to the `regex` syntax.
there is already a capture example in `help str replace`
```bash
  Find and replace with fancy-regex
  > 'a successful b' | str replace '\b([sS])uc(?:cs|s?)e(ed(?:ed|ing|s?)|ss(?:es|ful(?:ly)?|i(?:ons?|ve(?:ly)?)|ors?)?)\b' '${1}ucce$2'
  a successful b
```
but it's really not trivial to understand the *capture* syntax...

this PR adds a simpler example only focused on *captures*
🥳
```bash
  Use captures to manipulate the input text
  > "abc-def" | str replace "(.+)-(.+)" "${2}_${1}"
  def_abc
```

# User-Facing Changes
an example in `help str replace` to understand the syntax of *captures*.

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

# After Submitting
```
$nothing
```
2023-06-16 13:23:44 -05:00
Stefan Kupresak
67b1dcae44
Fix a panic bug in platform ansi logic (Closes #9448) (#9458)
Fixes #9448 

# Description
Attempts to fix a bug from the linked issue.

# User-Facing Changes
 - The editor doesn't crash on wrong commands
# Tests + Formatting

Tests cover my changes.

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library
2023-06-16 11:40:03 -05:00
Brian London
d00a040da9
Plugin api docs (#9452)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

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

Added comments to support API docs for the `nu-plugin` crate. Removed a
few items that I'd expect should only be used internally to Nushell from
the documentation and reduced the visibility of some items that did not
need to be public.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
There should be no user facing 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

Standard tests run. Additionally numerous doctests were added to the
`nu-plugin` crate.

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

No changes to the website necessary.
2023-06-16 16:25:40 +02:00
Bram Geron
86f12ffe61
Fix bug in std dirs drop; improve documentation (#9449)
# Description

When the directory stack contains only two directories, then std dirs
drop
used to misbehave and (essentially) drop the other directory, instead of
dropping the current directory.

This is fixed by always cd'ing for std dirs drop.

Before:

    /tmp〉enter ..
    /〉dexit
    /〉

After:

    /tmp〉enter ..
    /〉dexit
    /tmp〉


Additionally, I propose to explain the relevant environment variables a
bit
more thoroughly.


# User-Facing Changes

- Fix bug in dexit (std dirs drop) when two directories are remaining

# Tests + Formatting

Added a regression test. Made the existing test easier to understand.
2023-06-16 10:42:50 +02:00
Bram Geron
df5dcdab64
Fix usage for the exit command. (#9450)
Since #8415 the `exit` command no longer manipulates shells.
2023-06-16 10:09:02 +02:00
Michael Angerman
e09d482fb7
nu-cmd-lang readme (#9446)
Add a Readme file to the crate nu-cmd-lang to better explain what this
crate is about.
2023-06-15 08:45:23 -07:00
Anas Alkhatib
b072d75300
http post --content-type should set Content-Type header (#9431)
Parse the data from string to json if the `--content-type
"application/json"` flag is used for the request.

Fixes: https://github.com/nushell/nushell/issues/9408

In the issue, the actual data is a string `'{ "query": "{ greeting }"
}'` representing json, and it would match the case `Value::String { val,
.. }`


-------------------------

The example in the issue does set the `content-type` to
`application/json` but sends the body as a string note the `'`.

```
(
::: http post
:::   -fer
:::   # -H [ "Content-Type" "application/json" ]
:::   --content-type "application/json"
:::   'http://127.0.0.1:3000/greetings/hello'
:::   '{ "query": "{ greeting }" }'
::: )
```

```
╭─────────┬───────────────────────╮
│ headers │ {record 14 fields}    │
│ body    │ {"content_type":null} │
│ status  │ 200                   │
╰─────────┴───────────────────────╯
```

If we send the same request but using actual json as the body, the
Header is set correctly.

```
(        
::: http post
:::   -fer
:::   # -H [ "Content-Type" "application/json" ]
:::   --content-type "application/json"
:::   'http://127.0.0.1:3000/greetings/hello'
:::   { "query": "{ greeting }" }
::: )
```
```

╭─────────┬─────────────────────────────────────╮
│ headers │ {record 14 fields}                  │
│ body    │ {"content_type":"application/json"} │
│ status  │ 200                                 │
╰─────────┴─────────────────────────────────────╯
```
2023-06-15 06:51:35 -05:00
Stefan Holderbach
d371a78a0b
Drop unused nu-color-config in nu-cmd-lang (#9444)
# Description
Unneeded dependency as `help` moved back to `nu-command`.
Currently probably won't provide a compile time benefit.
2023-06-15 13:12:01 +02:00
WindSoilder
90863439d1
allow comment in multiple line pipeline (#9436)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
- fixes: #5517
- fixes: #9250

For the following commands:
```
ls
# | le
| length
```

I found that it generates a bad lite parsing result:
```
LiteBlock { 
    block: [
        LitePipeline { 
            commands: [
                Command(None, LiteCommand { comments: [], parts: [Span { start: 138600, end: 138602 }] })
            ]
        },
        LitePipeline { 
            commands: [
                Command(Some(Span { start: 138610, end: 138611 }),
                LiteCommand { comments: [Span { start: 138603, end: 138609 }], parts: [Span { start: 138612, end: 138618 }] })
            ]
        }
    ]
}
```

Which should contains only one `LitePipeline`, and the second
`LitePipeline` is generated because of `Eol` lex token:
```
[
    Token { contents: Item, span: Span { start: 138600, end: 138602 } },
    Token { contents: Eol, span: Span { start: 138602, end: 138603 } },    // it generates the second LitePipeline
    Token { contents: Comment, span: Span { start: 138603, end: 138609 } },
    Token { contents: Pipe, span: Span { start: 138610, end: 138611 } },
    Token { contents: Item, span: Span { start: 138612, end: 138618 } }
]
```

To fix the issue, I remove the `Eol` token when we meet `Comment` right
after `Eol`, then it will generate a good LiteBlock, and everything will
work fine.

### After the fix:
Token:
```
[
  Token { contents: Item, span: Span { start: 138618, end: 138620 } },
  Token { contents: Comment, span: Span { start: 138622, end: 138628 } },
  Token { contents: Pipe, span: Span { start: 138629, end: 138630 } },
  Token { contents: Item, span: Span { start: 138631, end: 138637 } }
]
```

LiteBlock:
```
LiteBlock {
  block: [
    LitePipeline { 
      commands: [
        Command(
            None, 
            LiteCommand { 
                comments: [Span { start: 138622, end: 138628 }],
                parts: [Span { start: 138618, end: 138620 }] 
            }
        ),
        Command(
            Some(Span { start: 138629, end: 138630 }),
            LiteCommand { comments: [], parts: [Span { start: 138631, end: 138637 }] })] }] }
```
<!--
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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-15 13:11:42 +02:00
Anas Alkhatib
33ad2a36bd
Fix clippy errors (Mac) (#9440)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description

Was getting errors when running the clip checks on another PR.
Applied the suggested fixes.


<img width="1792" alt="image"
src="https://github.com/nushell/nushell/assets/432535/bec30bd9-307d-4877-9eb8-1f8f3ed3edd9">


<img width="1527" alt="image"
src="https://github.com/nushell/nushell/assets/432535/f540da61-aa81-4a9e-9948-46d8d45afecb">
2023-06-15 07:30:54 +02:00
Filip Andersson
2fd4a36c0d
Changes global allocator to mimalloc, improving performance. (#9415)
# 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.
-->

this PR makes nushell use mimalloc as the default allocator, this has
the benefit of reducing startup time on my machine. `17%` on linux and
`22%` on windows, when testing using hyperfine.
the overhead to compile seem to be quite small, aswell as the increase
of binary size quite small
on linux the binary went from `33.1mb` to `33.2mb`

linux

![image](https://github.com/nushell/nushell/assets/17986183/ba5379b4-2c08-483a-a9ff-a9d8524d2943)

windows 

![image](https://github.com/nushell/nushell/assets/17986183/fda5090f-96a9-48d1-ada4-617694b9d880)


# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-14 17:27:12 -05:00
Stefan Holderbach
46eebc644c
Break up interdependencies of command crates (#9429)
# Description
Make sure that our different crates that contain commands can be
compiled in parallel.
This can under certain circumstances accelerate the compilation with
sufficient multithreading available.

## Details
- Move `help` commands from `nu-cmd-lang` back to `nu-command`
- This also makes sense as the commands are implemented in an
ANSI-terminal specific way
- Make `nu-cmd-lang` only a dev dependency for `nu-command`
- Change context creation helpers for `nu-cmd-extra` and
`nu-cmd-dataframe` to have a consistent api used in
`src/main.rs`:`get_engine_state()`
- `nu-command` now indepedent from `nu-cmd-extra` and `nu-cmd-dataframe`
that are now dependencies of `nu` directly. (change to internal
features)
- Fix tests that previously used `nu-command::create_default_context()`
with replacement functions

## From scratch compilation times:

just debug (dev) build and default features
```
cargo clean --profile dev && cargo build --timings
```

### before

![grafik](https://github.com/nushell/nushell/assets/15833959/e49f1f42-2e53-4a6c-bc23-625b686af1bc)

### after

![grafik](https://github.com/nushell/nushell/assets/15833959/8dec4723-e625-4a86-b91e-e6e808f64726)

# User-Facing Changes
None direct, only change to compilation on multithreaded jobs expected.

# Tests + Formatting
Tests that previously chose to use `nu-command` for their scope will
still use `nu-cmd-lang` + `nu-command` (command list in the granularity
at the time)
2023-06-14 23:12:55 +02:00
Han Junghyuk
b14bdd865f
Remove ZB and ZiB from file size type (#9427)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# 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.
-->
This PR removes ZB and ZiB from file size type, as they 
were showing incorrect values due to an integer overflow.

Fixes: #9337
# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-14 10:53:32 -05:00
Stefan Holderbach
604aadc938
Move explore command out of nu-command deps (#9421)
# Description
For better parallel compilation, make sure that `nu-command` doesn't
depend on `nu-explore`.

Moves the `nu_protocol::Command` implementation into `nu-explore`. Adds
`nu_explore::add_explore_context()` which is used in `main.rs` to add
the `explore` command.

Minor improvement in compile time ~0.5 sec observed as `nu-command`
still blocks on `nu-cmd-lang` as well.

## `cargo build --timings` before


![grafik](https://github.com/nushell/nushell/assets/15833959/583aa56e-6a1e-47b9-ba00-6a86293a38db)

## `cargo build --timings` after


![grafik](https://github.com/nushell/nushell/assets/15833959/30687575-c1c8-4635-bcdd-7ce9488fcfff)


# User-Facing Changes
None
2023-06-14 01:18:36 +02:00
Darren Schroeder
2b181bf69c
update ini dependency (#9426)
# Description

This PR updates the ini dependency.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-13 13:33:00 -05:00
Darren Schroeder
cdb7b9d9b2
update dfr to polars 0.30.0 (#9424)
# Description

Update the polars dependency for dataframes to stay on-version.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-13 12:05:45 -05:00
Darren Schroeder
30f4cc1fef
allow empty string arguments (#9420)
# Description

I'm not sure if this is a good idea or now but I did it to fix #9418. It
allows you to pass empty string arguments like this.

file named foo.nu
```
def main [--arg: string = dog] {
  if ($arg | is-empty) {
    echo "empty string"
  } else {
   echo $arg
  }
}
```
`> nu foo.nu --arg ""`
or
`> nu foo.nu --arg=""`
this gives an error
`> nu foo.nu --arg`
this returns the default argument
`> nu foo.nu`

closes #9418 

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-13 07:30:30 -05:00
Darren Schroeder
8a52085ae2
allow paths to have brackets (#9416)
# Description

This PR is trying to allow you to have `[blah]` in your path and yet
still have `ls` work. This is done by trying to separate the path from
the pattern to be searched for. It may still need more work.

I've tested it with:
- mkdir "[test]"
- cd "[test]"
- ls

Related to #9307 
Hopefully fixes #9232 

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-13 07:30:10 -05:00
dependabot[bot]
f152858d83
Bump dtparse from 1.4.0 to 1.5.0 (#9412) 2023-06-12 14:52:49 +00:00
Maxim Zhiburt
85fbacb197
nu-table: Bump tabled to 0.12.1 (#9341)
close #9335 

I am not sure whether the fix was better to be delived as a minor bump
but it is what is is.

Could you @fdncred test it somehow?
I did it by checking out back the the original commit before the PR
refered in the issue.

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-06-11 17:33:54 -05:00
Amirhossein Akhlaghpour
73921f4bd7
chore: rename uid to user column in ls --long (#9407)
Fixes: #9389
2023-06-11 18:02:08 +02:00
Steven Xu
be53ecbbaa
refactor: merge repl_buffer_state, repl_cursor_pos into one mutex (#9031)
# Description
Merge `repl_buffer_state`, `repl_cursor_pos` into one mutex.

# User-Facing Changes

# Tests + Formatting

# After Submitting
2023-06-10 17:38:11 -05:00
Stefan Holderbach
374df9d69f
Enable history entry exclusion with leading space (#9371)
# Description
Makes use of the feature introduced by nushell/reedline#566

If we consider this to be problematic we can decide to add a config
point for this behavior, but at first I was a bit hesistant expanding
the config in this area.


# User-Facing Changes
Follows precedent found in bash/zsh/fish to exclude lines starting with
a space from the history.
Like in fish you can still recall the last entry once but it will not be
stored and will be forgotten after the next submitted entry.


# Tests + Formatting
(-)
2023-06-10 17:15:46 -05:00
ja-cop
9c84c01aef
Add "regex" search term to commands with regex functionality (#9402)
Just makes it easier to find these commands when using the `help` system
- the `find` command already has the "regex" search term.

Co-authored-by: ja_cop <ja_cop@hoshi>
2023-06-11 00:02:00 +02:00
Astrick
e9508b578a
Fix find puts extra cols into record (#9397)
# 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.
-->

Trying to fix #9394. 

The problem with PR #9159 seems to be when searching for multiple terms,
each term is checked against the original values. It outputs a new value
for each such check, thus introducing replication for each search term.
As a result, it works fine with num of search term = 1.
2023-06-10 16:57:26 -05:00
Yethal
0bdc362e13
std: refactor test-runner to no longer require tests to be exported (#9355)
# Description
Test runner now performs following actions in order to run tests:
* Module file is opened
* Public function with random name is added to the source code, this
function calls user-specified private function
* Modified module file is saved under random name in $nu.temp-path
* Modified module file is imported in subprocess, injected function is
called by the test runner
# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
* Test functions no longer need to be exported
* test functions no longer need to reside in separate test_ files
* setup and teardown renamed to before-each and after-each respectively
* before-all and after-all functions added that run before all tests in
given module. This matches the behavior of test runners used by other
languages such as JUnit/TestNG or Mocha
# Tests + Formatting

# After Submitting

---------

Co-authored-by: Kamil <skelly37@protonmail.com>
Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-10 20:16:17 +02:00
Astrick
a86f34d0ad
Add zip-into-record to std iter (#9395)
# Description
Adds a new iter feature `zip-into-record` (#9380)

# User-Facing Changes
User can use `[1 2] | iter zip-into-record [3 4]` to create a table `[[1
2]; [3 4]]`

# Tests + Formatting

I noticed trailing spaces in std library that may wish to be cleaned in
the future.

Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-10 20:15:30 +02:00
Antoine Stevan
9fcc49e556
REFACTOR: simplify the declaration of extra commands (#9398)
cc/ @stormasm 

# Description
i was about to start the cratification of the 0% commands and thought i
could refactor and simplify a bit the declaration of the `bits`
commands, having hopefully a simpler structure to work with the other
commands 😌

this PR:
- gives real names to all the `bits` commands, instead of `SubCommand`
- make them publicly available inside the `nu-cmd-extra` crate to
declare them through `add_extra_decls`
- move the declaration code to the top-level `mod.nu` of `nu-cmd-extra`
so that all commands can be declared there as in `default_context` in
`nu-command`

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

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

# After Submitting
```
$nothing
```
2023-06-10 10:33:33 -07:00
Filip Andersson
1433f4a520
Changes HashMap to use aHash instead, giving a performance boost. (#9391)
# Description

see https://github.com/nushell/nushell/issues/9390
using `ahash` instead of the default hasher. this will not affect
compile time as we where already building `ahash`.


# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-10 11:41:58 -05:00
WindSoilder
6e638ab381
disable bracketed paste during evaluation (#9399)
# Description
Fixes: #9218

When user execute some commands involve user input, currently if we
enable `bracketed_paste`, it will results strange behavior (Pasting `0~`
and `1~` around texts, e.g: `aaa` -> `0~aaa1~`) And this is why `gpg`
with paste failed.

Sorry that it's hard to make relative testing...

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-10 09:42:13 -05:00
WindSoilder
5afd74f0b9
don't allow save command to save both stdout and stderr to the same file (#9368)
# Description
It's not a good idea to save `stdout` and `stderr` to the same file from
`save` command directly.

Because it saves `stdout` and `stderr` in different thread, which leads
to in-consistent output. As replace, we can use `o+e` redirection to fix
the issue

# User-Facing Changes
```
❯ do -i { "aa" } | save foo.txt -e foo.txt
Error:   × input and stderr input to same file
   ╭─[entry #3:1:1]
 1 │ do -i { "aa" } | save foo.txt -e foo.txt
   ·                                  ───┬───
   ·                                     ╰── can't save both input and stderr input to the same file
   ╰────
  help: you should use `o+e> file` instead
```

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-10 10:09:19 +02:00
WindSoilder
191cd2c970
save command: Don't use BufWriter to write external strem to a file (#9377)
# Description
Fixes: #9293

The problem is caused by `save` makes a `BufferWriter` for output file,
when external commands redirect it's output to a file, the content is
bufferred first...

To fix the issue, I'd like to introduce a `--no-buf` flag for `save`
command, and it's only used in redirection scenario.

Sorry it's hard to test against it in test, because it requires external
command to sleep or pause...

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-06-10 10:07:26 +02:00
WindSoilder
1edd3e7c3b
add http options command (#9365)
# Description
closes: #9344

Different to other http commands, `http options` command always returns
header, according to
[MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS),
the response information is included in header.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-09 08:00:40 -05:00
Stefan Holderbach
a5dd93d154
Apply nightly clippy fixes (#9381)
# Description
New lints coming from `cargo +nightly clippy`

Manually checked for problems.


# User-Facing Changes
None

# Tests + Formatting
(-)
2023-06-08 18:49:58 +02:00
Gurpreet Singh
15a15c123e
Add a check for empty params for url join (#9356)
# 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.
-->

Fix for #9347 

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->
- [x] Add unit tests
- [x] Run all cargo tests + fmt commands

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-07 19:08:21 +02:00
Stefan Holderbach
20b697f722
Fix internal module reexports (#9378)
# Description
`cargo +stable check` was complaining about ambiguous wildcard
reexports. Fixed by making the reexport of modules not pub as only the
explicitly named symbols are actually needed in the current state.


# User-Facing Changes
None
2023-06-07 16:36:34 +02:00
nibon7
a1a3ef4608
Fix typos (#9372)
# Description
Fix typo
2023-06-07 15:07:14 +02:00
Stefan Holderbach
d15859dd86
Bump to 0.81.1 as development version (#9379)
# Description
Primarily used as a marker on issues and if necessary as a patch release
version.
2023-06-07 15:06:42 +02:00
JT
63cb01e83b
bump to 0.81 (#9374)
# 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-07 10:08:11 +12:00
Stefan Holderbach
ef38805ef9
Pin reedline to 0.20.0 release (#9370)
# Description
See release notes

https://github.com/nushell/reedline/releases/tag/v0.20.0
2023-06-06 13:16:18 +02:00
Jakub Žádník
82e6873702
Fix config creation during printing (#9353) 2023-06-04 22:04:28 +03:00
Kamil
df15fc24fe
Logger constants refactored, format argument added, better formatting of failed (non) equality assertions (#9315)
# Description
I have (hopefully) simplified the `log.nu` internal structure and added
customizable log format for all `log` commands

# User-Facing Changes
- [x] Replaced constants with env records for: 
    - ansi (newly added)
    - log level
    - prefix
    - short prefix
- [x] Added `format` argument to all log commands
- [x] Assertions for (not) equality (equal, not equal, greater,
lesser...) now put left and right values inside `'` quotes, so the
assertions for strings are more meaningful
- [x] Documented the %-formatting of log messages

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
Darren Schroeder
7ca62b7b35
fix is-admin example (#9350)
# Description

closes #9348 

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-03 15:11:14 -05:00
Alex Saveau
8f4c182a0c
Explain how to do time based bash watch (#9345) 2023-06-03 11:15:47 -05:00
Darren Schroeder
acd2fe8c51
bump rust toolchain to 1.68.2 (#9346)
# Description

In keeping with our tradition of staying 2 versions behind the latest
rust compiler version, this PR bump the toolchain to 1.68.2.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-02 17:30:15 -05:00
Darren Schroeder
5c57d6a74d
add the ability to have a list of glob excludes (#9343)
# Description

This change allows you to have a list of exclude globs such as:
```
glob **/* --not [**/target/** **/.git/**]
```

TODO: Allow the input glob to be multiples too with
`wax::any(patterns)?`

The breaking change part is that the excludes have to be supplied as a
list, between [ and ].

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-02 12:37:17 -05:00
ShinyZero0
2ac63910f6
stdlib: add termux clipboard suport for clip (#9334)
# Description

Added `termux-clipboard-set` to `std clip`
2023-06-01 16:26:22 -05:00
solodov
55689ddb50
use "search_result" style to colorize matching strings (fixes #9275) (#9326)
This change introduces new `search_result` style supported in the color
config. The change also removes obsolete check for `config.ls_colors`
for computing the style. `config.ls_colors` has been removed last year,
so this removes the reference to the obsolete flag, along with a cleanup
that removes all the code that used to rely on ls_colors for
highlighting search results.


# 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-01 15:51:18 -05:00
Darren Schroeder
3aab69110e
Some tests added with github copilot preview (#9332)
# Description

This PR adds some tests that were generated in GitHub Copilot Chat
Preview. I was just playing around and figured that more tests couldn't
hurt.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-01 15:24:36 -05:00
Michael Angerman
b9e65e35b8
include the nu-cmd-extra crate in the version command features (#9333)
We needed to include the nu-cmd-extra crate in the version command's
features...

In the style of this PR which fixed the dataframe feature upon adding
the nu-cmd-dataframe crate...

https://github.com/nushell/nushell/pull/9262
2023-06-01 13:10:39 -07:00
Michael Angerman
356e05177c
nu-cmd-extra crate infrastructure in place with the Bits command as the model for adding other commands (#9327)
I wanted to get the infrastructure in place for starters for our
*nu-cmd-extra* crate...

The plan is to put inside here the following commands...

* bits
* bytes
* math

I thought it would be easier to do one at a time as well as get the
nu-cmd-extra crate out there on crates.io
for this upcoming release...

Once this lands the infrastructure will be in place to move over the
other noted commands for now...
And then add other stuff we do NOT want to be in 1.0.
2023-06-01 10:46:16 -07:00
simdimdim
2f731fa1ae
Adding more math constants (and a small correction to the description of an existing one) (#9181)
Adding more float constants for when
https://github.com/rust-lang/rust/issues/103883 is accepted and merged.
And fixing a small conflation in the description of the Euler number.
Please take a look and let me know if I've missed or screwed up
anything.
2023-05-31 20:28:08 -05:00
Carter Reeb
e6be167797
fix padding when running input list on tables (#9316)
# Description
Improves the output when running `input list` on tabular data by
aligning each column.

# User-Facing Changes
## Before

![before](https://github.com/nushell/nushell/assets/39879966/b6a93568-f37c-4bd3-93eb-efa41cac1baf)
## After

![after](https://github.com/nushell/nushell/assets/39879966/35d74bc7-6f72-42c4-89e7-f54692ccd3ff)

<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-31 18:31:46 +02:00
WindSoilder
bfe7133e7c
make insert, update, upsert support lazy records (#9323)
# Description
Fixes: #9165
It's because `sys` returns a lazy record, and `insert`, `update`,
`upsert` can't operate on lazy record yet.

# 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-31 06:27:55 -05:00
Maxim Zhiburt
5f8d8b4a4b
nu-explore/ Fix recursive table issue; (#9321)
close #9318

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-05-30 09:59:56 -05:00
WMR
b67b6f7fc5
Add a datepart expression for dfr to be used with dfr with-column (#9285)
# Description

Today the only way to extract date parts from a dfr series is the dfr
get-* set of commands. These create a new dataframe with just the
datepart in it, which is almost entirely useless. As far as I can tell
there's no way to append it as a series in the original dataframe. In
discussion with fdncred on Discord we decided the best route was to add
an expression for modifying columns created in dfr with-column. These
are the way you manipulate series within a data frame.

I'd like feedback on this approach - I think it's a fair way to handle
things. An example to test it would be:

```[[ record_time]; [ (date now)]]  | dfr into-df | dfr with-column [ ((dfr col record_time) | dfr datepart nanosecond | dfr as "ns" ), (dfr col record_time | dfr datepart second | dfr as "s"), (dfr col record_time | dfr datepart minute | dfr as "m"), (dfr col record_time | dfr datepart hour | dfr as "h") ]```

I'm also proposing we deprecate the dfr get-* commands.  I've not been able to figure out any meaningful way they could ever be useful, and this approach makes more sense by attaching the extracted date part to the row in the original dataframe as a new column.

<!--
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

add in dfr datepart as an expression
<!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. -->

# Tests + Formatting
Need to add some better assertive tests.  I'm also not sure how to properly write the test_dataframe at the bottom, but will revisit as part of this PR.  Wanted to get feedback early.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->

---------

Co-authored-by: Robert Waugh <robert@waugh.io>
2023-05-30 09:41:18 -05:00
nibon7
560c2e63ac
restore cursor shape when exits (#9314)
# Description
This PR restores cursor shape when nushell exists.

Fixes #9243 

Related
[nushell/reedline#574](https://github.com/nushell/reedline/pull/574)

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

* windows


https://github.com/nushell/nushell/assets/15247421/ede8d1c0-ecd1-40b0-87b0-6393c1a7160f


* linux


https://github.com/nushell/nushell/assets/15247421/b428f17e-05cb-45ad-aa5f-3a9753fd9176

* macos


https://github.com/nushell/nushell/assets/15247421/5170dabd-8b9f-4bad-a7a2-bdabfca45cca

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-30 09:38:45 -05:00
Maxim Zhiburt
7f758d3e51
Merge stack before printing (#9304)
Could you @fdncred try it?

close?: #9264

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-05-29 19:03:00 -05:00
mike
cc04b9a916
fix conflict between filesize and hexadecimal numbers (#9309)
closes #9278 

# Description

removes ambiguity between the `b` the filesize `bytes` unit and `b` the
hex digit
2023-05-28 12:56:58 +02:00
Antoine Stevan
3005fe10e5
REFACTOR: move run-tests and fix the std assert namespace (#9303)
related to the namespace bullet point in
- https://github.com/nushell/nushell/issues/8450

# Description
this was the last module of the standard library with a broken
namespace, this PR takes care of this.

- `run-tests` has been moved to `std/mod.nu`
- `std/testing.nu` has been moved to `std/assert.nu`
- the namespace has been fixed
- `assert` is now called `main` and used in all the other `std assert`
commands
- for `std assert length` and `std assert str contains`, in order not to
shadow the built-in `length` and `str contains` commands, i've used
`alias "core ..." = ...` to (1) define `foo` in `assert.nu` and (2)
still use the builtin `foo` with `core foo` (replace `foo` by `length`
or `str contains`)
  - tests have been fixed accordingly

# User-Facing Changes
one can not use
```
use std "assert equal"
```
anymore because `assert ...` is not exported from `std`.
`std assert` is now a *real* module.

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

# After Submitting
```
$nothing
```

# Notes for reviewers
to test this, i think the easiest is to
- run `toolkit test stdlib` and see all the tests pass
- run `cargo run -- -n` and try `use std assert` => are all the commands
available in scope?
2023-05-27 07:45:04 -05:00
Michel Alexandre Salim
34b3a49cae
[nu-explore] fix Cargo description (#9297)
# Description
The old description ("Nushell table printing") is identical to that of
`nu-table`. Per `explore --help` it is probably more accurate to say
"Nushell table pager".

# User-Facing Changes
N/A

# Tests + Formatting
```
❯ cargo metadata --no-deps | from json | get packages | get 14 | get description
warning: please specify `--format-version` flag explicitly to avoid compatibility problems
Nushell table pager
```

# After Submitting
N/A - change will go out when `0.82.0` is released

Signed-off-by: Michel Alexandre Salim <salimma@fedoraproject.org>
2023-05-27 10:18:39 +02:00
Jack Wright
8144926dc7
Adding JSON lines file support to dataframes (#9291)
# Description
Provides the ability to read and write [JSON
lines](https://jsonlines.org/) files. This is accomplished by exposing
the support already in Polars.

## Opening a JSON lines file 
<img width="1668" alt="Screenshot 2023-05-25 at 5 25 30 PM"
src="https://github.com/nushell/nushell/assets/56345/3b213c3d-eea1-440a-8425-4ce4b39ab7d1">

## Saving a dataframe to a JSON lines file
<img width="848" alt="Screenshot 2023-05-25 at 5 15 57 PM"
src="https://github.com/nushell/nushell/assets/56345/56089990-e14b-4f01-b676-5abab9333d7e">
2023-05-26 16:32:37 -05:00
Darren Schroeder
5f92fd20e9
update most dependencies except where deeper code changes are needed (#9296)
# Description

This PR updates most dependencies and tries to get in sync with
reedline.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-26 10:32:48 -05:00
Antoine Stevan
6481bf272c
REFACTOR: build help pages instead of printing them (#9253)
# Description
in order to write tests for the `std help` commands, as we currently
have in the Rust source base, we need to be able to manipulate the
output of the `std help` commands.

however, until now they've all been directly printing the help pages as
they go...

this PR tries to build the help pages and return them at the end instead
of printing them on the fly 👍

> **Note**
> this is quite a rewrite of the `help.nu` module 🤔 
> i think it might be best to either
> - look at the commits in order
> - test the changes by testing the commands in the REPL and comparing
them to their previous `std help` versions

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

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

# After Submitting
```
$nothing
```
2023-05-26 11:22:51 +02:00
Mel Massadian
9e667cc879
feat: (stdlib) add os record support to path add (#9238)
# 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.
-->
Add "os record" support.


# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
This don't change how path add works but just adds support for "os
records" aka records whose key are at least one of:
- linux
- macos
- windows

Check the
[test](a917f1a924/crates/nu-std/tests/test_std.nu (L31-L32))
if that's not clear enough

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-05-26 09:24:53 +02:00
Antoine Stevan
3e55addbdd
refactor the lib.rs of nu-std after the new virtual files PR (#9289) 2023-05-25 22:43:07 +03:00
Access
e5ff72120a
check if is homedir first when rm (#9117)
I don't want to rm my home again.. sadly..


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

check if there is unique argument

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

user will not easily rm their home

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-05-25 09:45:50 -05:00
JT
43108de547
move over to reedline git version (#9283)
# Description
Moves us over to dogfooding the git version of reedline ahead of the
next release.

# User-Facing Changes

With luck, you should see fewer bugs :D

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-25 11:53:57 +12:00
JT
fa113172da
Fix clippy warnings (upcoming) (#9282)
# Description

Fixes the clippy warnings we're about to get hit with next time we
upgrade Rust.

The big one was shrinking ShellError and related under 128 bytes.

# User-Facing Changes

Shouldn't notice much difference. In theory, we could see a tiny perf
improvement, but I didn't notice one.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-25 10:58:18 +12:00
JT
7ead89844a
Cut down on unnecessary parsing for SyntaxShape::Any (#9280)
# Description

This removes some unnecessary SyntaxShapes when parsing a
SyntaxShape::Any. Recent updates to the parser look for `{` and then
handle the logic for that separately.

# User-Facing Changes

This may have a slight parser speedup.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-25 07:53:57 +12:00
Jakub Žádník
74724dee80
Add virtual path abstraction layer (#9245) 2023-05-23 23:48:50 +03:00
Darren Schroeder
db4b26c1ac
some minor color fixups (#9270)
# Description

This PR cleans a couple things up. Nothing major, just a few things that
caught my eye looking for something else.
1. less macros
2. hidden and italic styles weren't fully available
3. lookup_color function didn't lookup all the colors available

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-23 09:33:03 -05:00
Bob Hyman
8e7405bf49
std dirs simply stays in sync with CD changes to PWD (#9267)
# 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.
-->
Fixes https://github.com/nushell/nushell/issues/9229.
Supersedes #9234

The reported problem was that `shells` list of active shells (a.k.a `std
dirs show` would show an inaccurate active
working directory if user changed it via `cd` command.

The fix here is for the `std dirs` module to let `$env.PWD` mask the
active slot of `$env.DIRS_LIST`. The user is free to invoke CD (or write
to `$env.PWD`) and `std dirs show` will display that as the active
working directory.

When user changes the active slot (via `n`, `p`, `add` or `drop`) `std
dirs` remembers the then current PWD in the about-to-be-vacated active
slot in `$env.DIRS_LIST`, so it is there if you come back to that slot.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
None. It just works™️

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> [x] 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-05-23 06:24:39 -05:00
Mel Massadian
77aee7e543
docs: 📝 "http get", add an example with more than one header (#9240)
# 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.
-->

I was trying `-H [key-A val-A] -H [key-B val-B]` but thanks to @Dorumin
I discovered how it should be used.
This PR just adds an extra example to the help with multiple headers.
Feel free to edit it either to merge both header examples into one or
rename the key value used, but I think it would be nice to have a sample
as the multiple -H variant doesn't error out it wasn't obvious to me.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
One more help example in `help http get`

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-22 13:55:19 -05:00
Tilen Gimpelj
60041879f3
throw an error instead of a panic if no input is provided to inspect (#9259)
# Description

This is a small PR to fix Nu crashing when calling `inspect` with no
data piped in(#9255).


# User-Facing Changes

none.
2023-05-22 13:54:04 -05:00
pwygab
a6e455efc3
upserting data of a cellpath that doesn't exist into a record creates the cellpath (#9257)
# Description
Fixes #9254.

# User-Facing Changes
upserting data of a cellpath that doesn't exist into a record now
creates the cellpath.

# Tests + Formatting

```
~/CodingProjects/nushell> mut a = {}                                                                       
~/CodingProjects/nushell> $a.b.c = 99                                                                            
~/CodingProjects/nushell> $a                                                                                    
╭───┬────────────╮
│   │ ╭───┬────╮ │
│ b │ │ c │ 99 │ │
│   │ ╰───┴────╯ │
╰───┴────────────╯
```

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-22 18:51:07 +02:00
WMR
8e538c650e
Fix version to show build features after crateification (#9262)
# Description

Addresses missing features per #9261 

# User-Facing Changes

Fixes output of version.  Adds wasi feature output

 # Tests + Formatting

No tests written

Co-authored-by: Robert Waugh <robert@waugh.io>
2023-05-22 08:42:38 -07:00
WindSoilder
5a34671343
add -u flag to cp, mv command (#9214)
# Description
Closes: #7853

I found that I want this feature too...

So I take over it, sorry for that @VincenzoCarlino 

# 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-20 09:48:57 -07:00
Antoine Stevan
9b139330f8
stdlib: fix the names of the help commands in help.nu (#9252)
related to the changes in
- #9193

# Description
when we change the namespace of a module, the internal calls to the
`export`ed commands needs to be updated as well 👀 😆

without this, we have the following pretty error:
```
> std help ansi
Error:   × std::help::item_not_found
   ╭─[entry #1:1:1]
 1 │ std help ansi
   ·          ──┬─
   ·            ╰── item not found
   ╰────
```
2023-05-20 17:37:17 +02:00
pwygab
6564ed710d
allow view-source to read rest arguments (#9247)
# Description
Fixes #8896. Also went back and cleaned up the code slightly.

# User-Facing Changes
`view-source` now is more comprehensive when viewing definitions. 

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-05-20 08:56:21 -05:00
Maria José Solano
4954a762b7
Allow duration defaults (#9249)
# 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.
-->
Fixes #9217 (some cases, still can't accept all default expressions)

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
- Follow-up of #8940, expanding `eval_constant` so that it can also
evaluate values with units.

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->
- A unit test was added to verify that defaults like `1sec` are
accepted.
2023-05-20 08:23:25 -05:00
Jakub Žádník
429c4332b1
Make aliased call not look up predeclarations (#9244) 2023-05-20 00:46:22 +03:00
pwygab
01a00641f9
Allow input to take a specified number of characters (#9242)
# Description
Title; fixes #9208.


# User-Facing Changes
`input` now can specify a certain number of characters to read.

# Tests + Formatting
No CI tests; can't find a way to implement.
```
~/CodingProjects/nushell> let user_input = (input --numchar 2)                                           
~/CodingProjects/nushell> echo $user_input                                                        
te
```

# 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-05-19 15:28:35 -05:00
Antoine Stevan
55bb501c71
FEATURE: fix the namespace of the standard library (not testing) (#9193) 2023-05-19 23:27:45 +03:00
Michael Angerman
c55b5c0a55
move dataframe commands to nu-cmd-dataframe (#9241)
All of the dataframe commands ported over with no issues...

### 11 tests are commented out (for now)

So 100 of the original 111 tests are passing with only 11 tests being
ignored for now..

As per our conversation in the core team meeting on Wednesday
I took @jntrnr  suggestion and just commented out the tests dealing
with
[IntoDatetime](https://github.com/nushell/nushell/blob/main/crates/nu-command/src/conversions/into/mod.rs)

Later on we can move this functionality out of nu-command if we decide
it makes sense...

### The following tests were ignored...

```rust
modified:   crates/nu-cmd-dataframe/src/dataframe/series/date/get_day.rs
modified:   crates/nu-cmd-dataframe/src/dataframe/series/date/get_hour.rs
modified:   crates/nu-cmd-dataframe/src/dataframe/series/date/get_minute.rs

modified:   crates/nu-cmd-dataframe/src/dataframe/series/date/get_month.rs
modified:   crates/nu-cmd-dataframe/src/dataframe/series/date/get_nanosecond.rs
modified:   crates/nu-cmd-dataframe/src/dataframe/series/date/get_ordinal.rs

modified:   crates/nu-cmd-dataframe/src/dataframe/series/date/get_second.rs
modified:   crates/nu-cmd-dataframe/src/dataframe/series/date/get_week.rs
modified:   crates/nu-cmd-dataframe/src/dataframe/series/date/get_weekday.rs

modified:   crates/nu-cmd-dataframe/src/dataframe/series/date/get_year.rs
modified:   crates/nu-cmd-dataframe/src/dataframe/series/string/strftime.rs
```
2023-05-19 10:56:08 -07:00
Kamil
ca275f59da
Added assert not command (assertion that the value/expression is false) (#9235)
# Description
A new command to simplify assertions for `false`.

The name is just a draft, though I could not come up with a better name.
I have rejected `assert false`, because I would have to rename `assert`
to `assert true` which would break the compatibility and worsen the
shell experience of the good old `assert`.

Another idea I have rejected was something like `assert_false` to keep
it consistent with the naming convention of our stdlib.

I am open to suggestions :)

# User-Facing Changes
Just a new command

# Tests + Formatting
- [x] Done

# 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-05-19 11:33:19 +02:00
Darren Schroeder
e752d8a964
remove unused dependencies (#9230)
# Description

This is a test PR to see if we can remove dependencies. The crates to
remove was generated from cargo machete. If ci works, I'll update the PR
to remove deps instead of comment them out.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-18 11:37:20 -05:00
Maxim Uvarov
fe1174bf16
add the no-strip flag to the clip command (#9216)
# 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.
-->
`ansi strip` (used in the clip command by default) removes tab symbols,
which is sometimes not useful (for example, when using the `[[a b]; [1
2]] | to tsv | clip` command). Therefore, I added a flag to prevent
using `ansi strip` in the clip command.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-18 13:07:47 +02:00
Mel Massadian
1de57eb2b6
fix: 🐛 handle windows Path casing (#9210)
# 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.
-->

PATH and Path are different (in nushell at least) based on the OS

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
None the command now works as expected

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-17 18:55:46 -05:00
nicolb2305
acd7c98c39
Removes unnecessary cwd and pipeline from various tests (#9202)
# 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.
-->
Cleans up various tests that unnecessarily use the `cwd` argument of
`nu!`, and the `pipeline` function for single line commands. Also
replaces some unnecessary raw strings with normal strings. Part of
#8670.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->
All checks 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-05-17 18:55:26 -05:00
mike
0e4729b203
improve parsing of values with units (#9190)
closes #9111 

# Description

this pr improves parsing of values with units (`filesizes`, `durations`
and any other **future values**) by:

1. allowing underscores in the value part
```nu
> 42kb          # okay
> 42_sec        # okay
> 1_000_000mib  # okay
> 69k_b         # not okay, underscores not allowed in the unit
```

2. improving error messages involving these values
```nu
> sleep 40-sec

# before
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[entry #42:1:1]
 1 │ sleep 40-sec
   ·       ──┬──
   ·         ╰── expected duration with valid units
   ╰────

# now
Error:
  × duration value must be a number
   ╭─[entry #41:1:1]
 1 │ sleep 40-sec
   ·       ─┬─
   ·        ╰── not a number
   ╰────
```

3. unifying parsing of these values. now all of these use one function

# User-Facing Changes

filesizes and durations can now have underscores for readability
2023-05-17 18:54:35 -05:00
Amirhossein Akhlaghpour
6a0c88d516
Fmt f64 (#9142)
Fixes: #9131 
As octal and some other format not valid for f64 we have to specify it .
just wonder if need for generic impl or no for just one type ?
2023-05-17 18:49:07 -05:00
Doru
dacf80f34a
Feature: Userland LazyRecords (#8332)
# Description
Despite the innocent-looking title, this PR involves quite a few backend
changes as the existing LazyRecord trait was not at all friendly towards
the idea of these values being generated on the fly from Nu code.

In particular, here are a few changes involved:
- The LazyRecord trait now involves a lifetime `'a`, and this lifetime
is used in the return value of `get_column_names`. This means it no
longer returns `'static str`s (but implementations still can return
these). This is more stringent on the consumption side.
- The LazyRecord trait now must be able to clone itself via a new
`clone_value` method (as requiring `Clone` is not object safe). This
pattern is borrowed from `Value::CustomValue`.
- LazyRecord no longer requires being serde serializable and
deserializable.

These, in hand, allow for the following:
- LazyRecord can now clone itself, which means that they don't have to
be collected into a Record when being cloned.
- This is especially useful in Stack, which is cloned on each repl line
and in a few other cases. This would mean that _every_ LazyRecord
instance stored in a variable would be collected in its entirety and
cloned, which can be catastrophic for performance. See: `let nulol =
$nu`.
- LazyRecord's columns don't have to be static, they can have the same
lifetime of the struct itself, so different instances of the same
LazyRecord type can have different columns and values (like the new
`NuLazyRecord`)
- Serialization and deserialization are no longer meaningless, they are
simply less.

I would consider this PR very "drafty", but everything works. It
probably requires some cleanup and testing, though, but I'd like some
eyes and pointers first.

# User-Facing Changes
New command. New restrictions are largely internal. Maybe there are some
plugins affected?

Example of new command's usage:
```
lazy make --columns [a b c] --get-value { |name| print $"getting ($name)"; $name | str upcase }
```

You can also trivially implement something like `lazy make record` to
take a record of closures and turn it into a getter-like lazy struct:
```
def "lazy make record" [
    record: record
] {
    let columns = ($record | columns)

    lazy make --columns $columns --get-value { |col| do ($record | get $col) }
}
```

Open to bikeshedding. `lazy make` is similar to `error make` which is
also in the core commands. I didn't like `make lazy` since it sounded
like some transformation was going on.

# Tour for reviewers
Take a look at LazyMake's examples. They have `None` as the results, as
such they aren't _really_ correct and aren't being tested at all. I
didn't do this because creating the Value::LazyRecord is a little tricky
and didn't want to risk messing it up, especially as the necessary
variables aren't available when creating the examples (like stack and
engine state).

Also take a look at NuLazyRecord's get_value implementation, or in
general. It uses an Arc<Mutex<_>> for the stack, which must be accessed
mutably for eval_block but get_value only provides us with a `&self`.
This is a sad state of affairs, but I don't know if there's a better
way.

On the same code path, we also have pipeline handling, and any pipeline
that isn't a Pipeline::Value will return Value::nothing. I believe
returning a Value::Error is probably better, or maybe some other
handling. Couldn't decide on which ShellError to settle with for that
branch.

The "unfortunate casualty" in the columns.rs file. I'm not sure just how
bad that is, though, I simply had to fight a little with the borrow
checker.

A few leftover comments like derives, comments about the now
non-existing serde requirements, and impls. I'll definitely get around
to those eventually but they're in atm

Should NuLazyRecord implement caching? I'm leaning heavily towards
**yes**, this was one of the main reasons not to use a record of
closures (besides convenience), but maybe it could be opt-out. I'd
wonder about its implementation too, but a simple way would be to move a
HashMap into the mutex state and keep cached values there.
2023-05-17 18:35:22 -05:00
Reilly Wood
9ce61dc677
Change group-by to accept cell paths (#9020)
Closes #9003.

This PR changes `group-by` so that its optional argument is interpreted
as a cell path. In turn, this lets users use `?` to ignore rows that are
missing the column they wish to group on. For example:

```
> [{foo: 123}, {foo: 234}, {bar: 345}] | group-by foo
Error: nu:🐚:column_not_found

  × Cannot find column
   ╭─[entry #3:1:1]
 1 │ [{foo: 123}, {foo: 234}, {bar: 345}] | group-by foo
   ·                          ─────┬────             ─┬─
   ·                               │                  ╰── cannot find column 'foo'
   ·                               ╰── value originates here
   ╰────

> [{foo: 123}, {foo: 234}, {bar: 345}] | group-by foo?
╭─────┬───────────────╮
│ 123 │ [table 1 row] │
│ 234 │ [table 1 row] │
╰─────┴───────────────╯
```

~~This removes the ability to pass `group-by` a closure or block (I
wasn't able to figure out how to make the 2 features coexist), and so it
is a breaking change. I think this is OK; I didn't even know `group-by`
could accept a closure or block because there was no example for that
functionality.~~
2023-05-17 18:34:44 -05:00
WindSoilder
b150f9f5d8
Avoid blocking when o+e> redirects too much stderr message (#8784)
# Description

Fixes: #8565

Here is another pr #7240 tried to address the issue, but it works in a
wrong way.

After this change `o+e>` won't redirect all stdout message then stderr
message and it works more like how bash does.

# User-Facing Changes

For the given python code:
```python
# test.py
import sys

print('aa'*300, flush=True)
print('bb'*999999, file=sys.stderr, flush=True)
print('cc'*300, flush=True)
```

Running `python test.py out+err> a.txt` shoudn't hang nushell, and
`a.txt` keeps output in the same order

## About the change
The core idea is that when doing lite-parsing, introduce a new variant
`LiteElement::SameTargetRedirection` if we meet `out+err>` redirection
token(which is generated by lex function),

During converting from lite block to block,
LiteElement::SameTargetRedirection will be converted to
PipelineElement::SameTargetRedirection.

Then in the block eval process, if we get
PipelineElement::SameTargetRedirection, we'll invoke `run-external` with
`--redirect-combine` flag, then pipe the result into save command

## What happened internally?

Take the following command as example:
`^ls o+e> log.txt`

lex parsing result(`Tokens`) are not changed, but `LiteBlock` and
`Block` is changed after this pr.
### LiteBlock before
```rust
LiteBlock {
    block: [
        LitePipeline { commands: [
            Command(None, LiteCommand { comments: [], parts: [Span { start: 39041, end: 39044 }] }),
            // actually the span of first Redirection is wrong too..
            Redirection(Span { start: 39058, end: 39062 }, StdoutAndStderr, LiteCommand { comments: [], parts: [Span { start: 39050, end: 39057 }] }),
        ]
    }]
}
```
### LiteBlock after
```rust
LiteBlock { 
    block: [
        LitePipeline {
            commands: [
                SameTargetRedirection {
                    cmd: (None, LiteCommand { comments: [], parts: [Span { start: 147945, end: 147948}]}),
                    redirection: (Span { start: 147949, end: 147957 }, LiteCommand { comments: [], parts: [Span { start: 147958, end: 147965 }]})
                }
            ]
        }
    ]
}
```
### Block before
```rust
Pipeline {
    elements: [
        Expression(None, Expression {
            expr: ExternalCall(Expression { expr: String("ls"), span: Span { start: 39042, end: 39044 }, ty: String, custom_completion: None }, [], false),
            span: Span { start: 39041, end: 39044 },
            ty: Any, custom_completion: None 
        }),
        Redirection(Span { start: 39058, end: 39062 }, StdoutAndStderr, Expression { expr: String("out.txt"), span: Span { start: 39050, end: 39057 }, ty: String, custom_completion: None })] }
```
### Block after
```rust
Pipeline {
    elements: [
        SameTargetRedirection { 
            cmd: (None, Expression {
                expr: ExternalCall(Expression { expr: String("ls"), span: Span { start: 147946, end: 147948 }, ty: String, custom_completion: None}, [], false),
                span: Span { start: 147945, end: 147948},
                ty: Any, custom_completion: None
            }),
            redirection: (Span { start: 147949, end: 147957}, Expression {expr: String("log.txt"), span: Span { start: 147958, end: 147965 },ty: String,custom_completion: 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
- `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-05-17 17:47:03 -05:00
WindSoilder
9c435fee75
fix clippy warning on clippy 0.1.69 (#9204)
# Description
As title, when I run clippy locally, I get something like following
warning:
<img width="1383" alt="Screenshot 2023-05-15 at 22 34 57"
src="https://github.com/nushell/nushell/assets/22256154/4d4254bc-9e42-437e-9169-d15e9a97aa57">

This pr is going to fix it

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-17 17:44:08 -05:00
Bob Hyman
ce071f2498
fix spurious 'item not found' error in std help (#9197)
…ses).


# 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.
-->
See title.  
Fixes #9154 
(despite name of branch)

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
n/a
# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> [x] 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-05-17 20:02:23 +02:00
Darren Schroeder
057de06613
bump nushell from release version to development version (#9215)
# Description

Bump nushell to 0.80.1 development version

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-17 07:59:01 -05:00
Stefan Holderbach
8695b57584
Bump version for 0.80.0 release (#9212)
# Checklist

- [x] merged reedline PR
- [ ] release notes
2023-05-17 10:11:13 +12:00
Stefan Holderbach
c9652bce00
Pin reedline to 0.19.1 for 0.80 release (#9211)
# Description
This just includes the bracketed paste bugfix in nushell/reedline#577


# User-Facing Changes
None

# Tests + Formatting

# After Submitting
2023-05-17 10:05:24 +12:00
Antoine Stevan
bf86cd50a5
REFACTOR: remove the shell commands (#8415)
Related to #8368.

# Description
as planned in #8311, the `enter`, `shells`, `g`, `n` and `p` commands
have been re-implemented in pure-`nushell` in the standard library.
this PR removes the `rust` implementations of these commands.

- all the "shells" tests have been removed from
`crates/nu-commnand/tests/commands/` in
2cc6a82da6, except for the `exit` command
- `cd` does not use the `shells` feature in its source code anymore =>
that does not change its single-shell behaviour
- all the command implementations have been removed from
`crates/nu-command/src/shells/`, except for `exit.rs` => `mod.rs` has
been modified accordingly
- the `exit` command now does not compute any "shell" related things
- the `--now` option has been removed from `exit`, as it does not serve
any purpose without sub-shells

# User-Facing Changes
users may now not use `enter`, `shells`, `g`, `n` and `p`
now they would have to use the standard library to have access to
equivalent features, thanks to the `dirs.nu` module introduced by @bobhy
in #8368

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

# After Submitting
the website will have to be regenerated to reflect the removed commands
👍
2023-05-13 12:40:11 -05:00
Jakub Žádník
8d8304cf91
Allow recursive module dirs; Require mod.nu in dirs (#9185) 2023-05-13 01:20:33 +03:00
Antoine Stevan
92c1051143
fix the span of the global std help item (#9184)
related to 
- #9101
- #9039

# Description
i actually forgot to fix in #9039 the new "*item*" introduced by
#9101... 👀
there it is 😇 

# User-facing changes
going from
```
> std help git-commiteuwqi
Help pages from external command git-commiteuwqi:
No manual entry for git-commiteuwqi
Error:
  × std::help::item_not_found
     ╭─[help:721:1]
 721 │
 722 │     let item = ($item | str join " ")
     ·     ─┬─
     ·      ╰── item not found
 723 │
     ╰────
```
to
```
> std help git-commiteuwqi
Help pages from external command git-commiteuwqi:
No manual entry for git-commiteuwqi
Error:
  × std::help::item_not_found
   ╭─[entry #2:1:1]
 1 │ std help git-commiteuwqi
   ·          ───────┬───────
   ·                 ╰── item not found
   ╰────
```

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

# After Submitting
```
$nothing
```
2023-05-12 20:30:38 +02:00
Antoine Stevan
9ebb61fc2d
FIX: correct bad span in std help errors (#9039)
# Description
##  before this PR
```
>_ std help modules euwioq
Error: nu:🐚:external_command

  × External command failed
     ╭─[help:259:1]
 259 │         if ($found_module | is-empty) {
 260 │             module_not_found_error (metadata $module | get span)
     ·                                    ──────────────┬──────────────
     ·                                                  ╰── Cannot convert record<start: int, end: int> to a string
 261 │         }
     ╰────
  help: All arguments to an external command need to be string-compatible
```
```
>_ std help externs euwioq
Error:
  × std::help::extern_not_found
     ╭─[help:401:1]
 401 │
 402 │     let extern = ($extern | str join " ")
     ·     ─┬─
     ·      ╰── extern not found
 403 │
     ╰────
```
> **Note**
> same kind of error with all the others

## ✔️ after this PR
```
> std help modules euwioq                                                                                         04/28/2023 05:45:50 PM
Error:
  × std::help::module_not_found
   ╭─[entry #2:1:1]
 1 │ std help modules euwioq
   ·                  ───┬──
   ·                     ╰── module not found
   ╰────
```
```
> std help externs euwioq                                                                                         04/28/2023 05:45:53 PM
Error:
  × std::help::extern_not_found
   ╭─[entry #3:1:1]
 1 │ std help externs euwioq
   ·                  ───┬──
   ·                     ╰── extern not found
   ╰────
```
> **Note**
> same with the others

# User-Facing Changes
fixes the errors to have proper messages

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

# After Submitting
```
$nothing
```
2023-05-12 19:44:39 +02:00
mike
2254805a6d
make the pattern-matcher and eval engine use the same unit computation (#8973)
# Description
this pr adresses
[this](7413ef2824/crates/nu-protocol/src/engine/pattern_match.rs (L149))
'fix me'
2023-05-12 12:18:11 -05:00
tesla232
8584aa79a2
Span fixes during duration conversion (#9143)
Description: Fix of #8945.


# 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: jpaldino <jpaldino@zaloni.com>
2023-05-12 18:57:50 +02:00
mike
a3bf2bff49
improve error when name and parameters are not space-separated (#8958)
# Description
closes #8934

this pr improves the diagnostic emitted when the name and parameters of
either `def`, `def-env` or `extern` are not separated by a space

```nu
Error:
  × no space between name and parameters
   ╭─[entry #1:1:1]
 1 │ def err[] {}
   ·        ▲
   ·        ╰── expected space
   ╰────
  help: consider adding a space between the `def` command's name and its parameters
```

from

```nu
Error: nu::parser::missing_positional

  × Missing required positional argument.
   ╭─[entry #1:1:1]
 1 │ def err[] {}
   ╰────
  help: Usage: def <def_name> <params> <body>
```

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Co-authored-by: Jelle Besseling <jelle@pingiun.com>
2023-05-12 09:10:40 -05:00
Hofer-Julian
5e8754bd85
Start to move to polars 0.29 (#9145)
This does part of the work of porting to polars 0.29.
However, I am not familiar enough with this part of the codebase to
finish it.

Things to be done:
- We match two times over `polars::Expr` but `Expr::Cache` isn't
handled. I don't know what should be done here
- `ArgExpr:::List` was renamed to `ArgExpr::Implode`. Does that mean
that `dfr list` should be renamed to `dfr implode`?

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-05-12 07:44:35 -05:00
JT
a45bd0301a
remove a few unnecessary allocations (#9176)
# Description

Change the parser a little bit so it does less allocations when it's
parsing, specifically when parsing lists/tables

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-12 05:10:54 +02:00
Darren Schroeder
39cdf56214
Update default_env.nu to work with windows (#9172)
# Description
This PR fixes the `create_left_prompt` custom command to work with
Windows.
Before:

![image](https://github.com/nushell/nushell/assets/343840/5a78fc3b-3c2a-4c2f-9c1d-2451063273af)
After:

![image](https://github.com/nushell/nushell/assets/343840/c3785767-5000-454e-9b7b-b0094c3d0834)


# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-11 15:48:56 -05:00
Bob Hyman
9e9fe83bfd
Parameter defaults to $nu.scope.commands (#9152)
(*third* try at posting this PR, #9104, like #9084, got polluted with
unrelated commits. I'm never going to pull from the github feature
branch again!)

# 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.
-->
Show parameter defaults in scope command signature, where they're
available for display by help.
per https://github.com/nushell/nushell/issues/8928.

I found unexpected ramifications in one completer (NuHelpCompleter) and
plugins, which both use the flag-formatting routine from builtin help.
For the moment I made the minimum necessary changes to get the mainline
scenario to pass tests and run. But we should circle back on what to do
with plugins and help completer..

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
1. New `parameter_default` column to `signatures` table in
`$nu.scope.commands`
It is populated with whatever parameters can be defaulted: currently
positional args and named flags.
2. Built in help (both `help <command>` and `<command> --help` will
display the defaults
3. Help completer will display defaults for flags, but not for
positionals.

Example:
A custom command with some default parameters:
```
〉cat ~/work/dflts.nu 
# sample function to show defaults in help
export def main [
    arg1: string        # mandatory positional
    arg2:string=abc     # optional positional
    --switch            # no default here
    --named:int         # named flag, no default
    --other:string=def  # flag 
    --hard:record<foo:int bar:string, bas:bool> # default can be compound type
            = {foo:22, bar:"other worlds", bas:false}
] { {arg1: $arg1,
    arg2: $arg2,
    switch: $switch,
    named: $named,
    other: $other,
    hard: $hard, }
}

〉use ~/work/dflts.nu

〉$nu.scope.commands | where name == 'dflts' | get signatures.0.any | reject short_flag description custom_completion
╭───┬────────────────┬────────────────┬──────────────────────────────────────────┬─────────────┬───────────────────────────╮
│ # │ parameter_name │ parameter_type │               syntax_shape               │ is_optional │     parameter_default     │
├───┼────────────────┼────────────────┼──────────────────────────────────────────┼─────────────┼───────────────────────────┤
│ 0 │                │ input          │ any                                      │ false       │                           │
│ 1 │ arg1           │ positional     │ string                                   │ false       │                           │
│ 2 │ arg2           │ positional     │ string                                   │ true        │ abc                       │
│ 3 │ switch         │ switch         │                                          │ true        │                           │
│ 4 │ named          │ named          │ int                                      │ true        │                           │
│ 5 │ other          │ named          │ string                                   │ true        │ def                       │
│ 6 │ hard           │ named          │ record<foo: int, bar: string, bas: bool> │ true        │ ╭───────┬───────────────╮ │
│   │                │                │                                          │             │ │ foo   │ 22            │ │
│   │                │                │                                          │             │ │ bar   │ other worlds  │ │
│   │                │                │                                          │             │ │ bas   │ false         │ │
│   │                │                │                                          │             │ ╰───────┴───────────────╯ │
│ 7 │                │ output         │ any                                      │ false       │                           │
╰───┴────────────────┴────────────────┴──────────────────────────────────────────┴─────────────┴───────────────────────────╯

〉help dflts
sample function to show defaults in help

Usage:
  > dflts {flags} <arg1> (arg2) 

Flags:
  --switch - switch -- no default here
  --named <Int> - named flag, typed, but no default
  --other <String> - flag with default (default: 'def')
  --hard <Record([("foo", Int), ("bar", String), ("bas", Boolean)])> - default can be compound type (default: {foo: 22, bar: 'other worlds', bas: false})
  -h, --help - Display the help message for this command

Parameters:
  arg1 <string>: mandatory positional
  arg2 <string>: optional positional (optional, default: 'abc')
```

Compared to (relevant bits of) help output previously:
```
Flags:
  -h, --help - Display the help message for this command
  -, --switch - no default here
  -, --named <int> - named flag, no default
  -, --other <string> - flag
  -, --hard <record<foo: int, bar: string, bas: bool>> - default can be compound type

Signatures:
  <any> | dflts <string> <string> -> <any>

Parameters:
  arg1 <string>: mandatory positional
  (optional) arg2 <string>: optional positional
```

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> [x] 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-05-11 13:59:56 -05:00
juanPabloMiceli
e735d0c561
Fix find -v command on tables (issue #9043) (#9159)
# Description
This PR fixes issue #9043 where find -v was returning empty tables
and/or wrong output.
It also refactors some big code chunks with repetitions into it's own
functions.

# User-Facing Changes

# Tests + Formatting
Unit tests added for asserting changes.

# After Submitting
2023-05-11 13:39:21 -05:00
mike
39e51f1953
add more commands to std iter (#9129)
# Description

this pr adds the following commands to `std iter`
- `iter find-index` -> returns the index of the first element that
matches the predicate or `-1` if none
- `iter flat-map` -> maps a closure to each nested structure and
flattens the result
- `iter zip-with` -> zips two structures and applies a closure to each
of the zips

it also fixes some \*\*very minor\*\* inconsistencies in the module
2023-05-10 19:18:42 +02:00
Antoine Stevan
43a3983d36
REFACTOR: move the banner from the rust source to the standard library (#8406)
Related to:
- #8311 
- #8353

# Description
with the new `$nu.startup-time` from #8353 and as mentionned in #8311,
we are now able to fully move the `nushell` banner from the `rust`
source base to the standard library.

this PR
- removes all the `rust` source code for the banner
- rewrites a perfect clone of the banner to `std.nu`, called `std
banner`
- call `std banner` from `default_config.nu`

# User-Facing Changes
see the demo: https://asciinema.org/a/566521

- no config will show the banner (e.g. `cargo run --release --
--no-config-file`)
- a custom config without the `if $env.config.show_banner` block and no
call to `std banner` would never show the banner
- a custom config with the block and `config.show_banner = true` will
show the banner
- a custom config with the block and `config.show_banner = false` will
NOT show the banner

# Tests + Formatting
a new test line has been added to `tests.nu` to check the length of the
`std banner` output.
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting
```
$nothing
```

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-05-10 07:05:01 -05:00
Darren Schroeder
a8b4e81408
add a negation glob option to the glob command (#9153)
# Description
This PR adds the ability to add a negation glob.

Normal Example:
```
> glob **/tsconfig.json
╭───┬────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 0 │ C:\Users\username\source\repos\forks\vscode-nushell-lang\client\node_modules\big-integer\tsconfig.json │
│ 1 │ C:\Users\username\source\repos\forks\vscode-nushell-lang\client\tsconfig.json                          │
│ 2 │ C:\Users\username\source\repos\forks\vscode-nushell-lang\node_modules\fastq\test\tsconfig.json         │
│ 3 │ C:\Users\username\source\repos\forks\vscode-nushell-lang\node_modules\jszip\tsconfig.json              │
│ 4 │ C:\Users\username\source\repos\forks\vscode-nushell-lang\server\tsconfig.json                          │
│ 5 │ C:\Users\username\source\repos\forks\vscode-nushell-lang\tsconfig.json                                 │
╰───┴────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```
Negation Example:
```
> glob **/tsconfig.json --not **/node_modules/**
╭───┬───────────────────────────────────────────────────────────────────────────────╮
│ 0 │ C:\Users\username\source\repos\forks\vscode-nushell-lang\client\tsconfig.json │
│ 1 │ C:\Users\username\source\repos\forks\vscode-nushell-lang\server\tsconfig.json │
│ 2 │ C:\Users\username\source\repos\forks\vscode-nushell-lang\tsconfig.json        │
╰───┴───────────────────────────────────────────────────────────────────────────────╯
```

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-10 06:31:34 -05:00
Michael Albers
6c13c67528
Ensure consistent map ordering when reading YAML (#9155)
# Description

This change ensures that the ordering of map keys when reading YAML
files is consistent. Previously a `HashMap` was used to store the
mappings, but that would result in non-deterministic ordering of the
keys. Switching to an `IndexMap` fixes this.

Fixes https://github.com/nushell/nushell/issues/8662

# User-Facing Changes

User's can rely on consistent ordering of map keys from YAML.

# Tests + Formatting

A unit test ensuring the ordering has been added.

# After Submitting

None.
2023-05-10 06:30:55 -05:00
Steven Xu
2a484a3e7e
fix: use buffer.len() instead of cursor_pos, so the .expect() isn't useless (#9053)
# Description
Use `buffer.len()` instead of `cursor_pos`, so the `.expect()` isn't
useless.

# User-Facing Changes

# Tests + Formatting

# After Submitting
2023-05-08 13:02:01 -05:00
Antoine Stevan
a78cd6e231
FIX: add a space after the default left prompt (#9074)
# Description
when running `nushell` with the `--no-config-file` option, the left
prompt does not have a space to separate the directory path from the
user input.
in this PR i add a space there to make the prompt easier to read when
using `--no-config-file`!

# User-Facing Changes
before: https://asciinema.org/a/581733
after: https://asciinema.org/a/581734

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

# After Submitting
```
$nothing
```
2023-05-08 13:00:44 -05:00
Antoine Stevan
a528c043fe
REFACTOR: fix typos and simplify external std help (#9100)
followup to #9025
cc/ @YummyOreo 

# Description
this PR simply fixes some typos and simplifies the logic of the external
help page opening 😋

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

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

# After Submitting
```
$nothing
```
2023-05-08 12:59:52 -05:00
Antoine Stevan
47f9fd3644
FIX: have consistent errors between std help and std help ... (#9101)
# Description
an example should show what happens quite clearly 😋 

> **Note**
> the ugly spanned errors you'll see below are fixed in
https://github.com/nushell/nushell/pull/9039 😌

in all cases we get
```
> std help commands does-not-exist-anywhere
Help pages from external command does-not-exist-anywhere:
No manual entry for does-not-exist-anywhere
Error:
  × std::help::command_not_found
     ╭─[help:662:1]
 662 │
 663 │     let command = ($command | str join " ")
     ·     ─┬─
     ·      ╰── command not found
 664 │
     ╰────
```
but

##  before this PR
```
> std help does-not-exist-anywhere
Help pages from external command does-not-exist-anywhere:
No manual entry for does-not-exist-anywhere
```
without any error, which makes it inconsistent with all the other `std
help` commands which give errors when not finding an item 🤔

## ✔️ with this PR
```
> std help does-not-exist-anywhere
Help pages from external command does-not-exist-anywhere:
No manual entry for does-not-exist-anywhere
Error:
  × std::help::item_not_found
     ╭─[help:740:1]
 740 │
 741 │     let item = ($item | str join " ")
     ·     ─┬─
     ·      ╰── item not found
 742 │
     ╰────
```

# User-Facing Changes
more consistent errors when using `std help` and `std help commands`, as
shown 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
```
$nothing
```
2023-05-08 12:58:49 -05:00
Antoine Stevan
fe9f732c5f
REFACTOR: make input list a tiny bit tighter (#9115)
related to #8963
cc/ @melMass 

# Description
just a little refactoring attempt for `input list` 😌 

i wanted to refactor even more, but `Select`, `MultiSelect` and
`FuzzySelect` do not share a common trait, i could not find a nice way
to reduce the big `if` block...

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

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

# After Submitting
```
$nothing
```
2023-05-08 12:45:55 -05:00
Maxim Zhiburt
a5d02a0737
nu-explore: Fix repeated char issue in cmdline (#9139)
Must be fixed; (though I'd test it)

Thanks for the reference [fdncred](https://github.com/fdncred).

close #9128

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-05-08 12:38:42 -05:00
Antoine Stevan
7a945848de
swap the date and the log level in the std log format (#9138)
related to
https://github.com/nushell/nushell/issues/8588#issuecomment-1538624565

# Description
this PR switches the date and log level in `std log` 👍 

# User-Facing Changes
the date and log level are now swapped in the `std log` format.

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

# After Submitting
```
$nothing
```
2023-05-08 12:29:18 -05:00
Maxim Zhiburt
a92949b5c3
nu-explore: Fix pipeline rendering (#9137)
Must be fixed (but I would check).

I wonder if it was a regression caused by `Value::LazyRecord`.
I mean likely the issue was before the refactoring I did.

close #9130

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-05-08 11:17:14 -05:00
Hofer-Julian
d5ae979094
Update polars to 0.28 (#9136)
# Description
Update polars to 0.28.
Luckily, it didn't require major changes.

# User-Facing Changes
None.
(Apart from the fact that certain error messages will stop breaking
table formatting)
2023-05-08 10:42:53 -05:00
Darren Schroeder
388e84e7ef
update nu-glob based on latest glob 0.3.1 changes (#9099)
# Description
This PR updates `nu-glob` to add the latest changes and updates from
`rust-lang/glob` [v0.3.1](https://github.com/rust-lang/glob).

With these changes you can do this type of globbing
```rust
/// - `?` matches any single character.
///
/// - `*` matches any (possibly empty) sequence of characters.
///
/// - `**` matches the current directory and arbitrary subdirectories. This
///   sequence **must** form a single path component, so both `**a` and `b**`
///   are invalid and will result in an error.  A sequence of more than two
///   consecutive `*` characters is also invalid.
///
/// - `[...]` matches any character inside the brackets.  Character sequences
///   can also specify ranges of characters, as ordered by Unicode, so e.g.
///   `[0-9]` specifies any character between 0 and 9 inclusive. An unclosed
///   bracket is invalid.
///
/// - `[!...]` is the negation of `[...]`, i.e. it matches any characters
///   **not** in the brackets.
///
/// - The metacharacters `?`, `*`, `[`, `]` can be matched by using brackets
///   (e.g. `[?]`).  When a `]` occurs immediately following `[` or `[!` then it
///   is interpreted as being part of, rather then ending, the character set, so
///   `]` and NOT `]` can be matched by `[]]` and `[!]]` respectively.  The `-`
///   character can be specified inside a character sequence pattern by placing
///   it at the start or the end, e.g. `[abc-]`.
```
Example - with character sequences

![image](https://user-images.githubusercontent.com/343840/236266670-03bf9384-4917-4074-9687-2c1c0d8ef34a.png)

Example - with character sequence negation

![image](https://user-images.githubusercontent.com/343840/236266421-73c3ee2c-1d10-4da0-86be-0afb51b50604.png)

Example - normal globbing

![image](https://user-images.githubusercontent.com/343840/236267138-60f22228-b8d3-4bf2-911b-a80560fdfa4f.png)

Example - with character sequences

![image](https://user-images.githubusercontent.com/343840/236267475-8c38fce9-87fe-4544-9757-34d319ce55b8.png)

Not that, if you're using a character sequence by itself, you need to
enclose it in quotes, otherwise nushell will think it's a range. But if
you already have a type of a bare word already, no quotes are necessary,
as in the last example.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-08 09:07:01 -05:00
Emily Grace Seville
a2dd948e71
FEATURE: format std log and add --short option (#9091)
# Description
- prettify formatting
- move message formatting to a private function
- allow short prefixes for loggers via `--short|-s` flag

# User-Facing Changes
- allow short prefixes for loggers via `--short|-s` flag

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-05-08 10:13:21 +02:00
Jakub Žádník
250071939b
Reuse parsed modules (#9125) 2023-05-07 14:41:40 +03:00
Jakub Žádník
0ea973b78b
Fix exported module not found (#9121) 2023-05-06 23:55:10 +03:00
Jakub Žádník
a2a346e39c
Allow creating modules from directories (#9066) 2023-05-06 21:39:54 +03:00
Antoine Stevan
6dc7ff2335
FEATURE: return tables with std help ... --find ... (#9040)
# Description
this PR makes `std help` commands return a table no matter the number of
matches when using `--find`.
as proposed by Darren, this would allow users to still rely on things
like
```nushell
let blah = (std help modules -f weather | get name)
```
even if there is a single match.

# User-Facing Changes
`std help ... --find ...` now returns a table as `help ... --find ...`

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

# After Submitting
```
$nothing
```
2023-05-05 18:06:48 +02:00
Mel Massadian
10d65b611f
adds a list subcommand to input (interactive selections) (#8963)
# Description
Adds a subcommand `list` to `input` (can be migrated wherever if needed)
that allows interactive single and multi selection from an input list.

![image](https://user-images.githubusercontent.com/7041726/236072161-5954dad9-8152-4752-ae3b-b21577711fd1.png)



https://user-images.githubusercontent.com/7041726/233747242-1ca6c44b-e32c-48f1-8fa8-ae50f813be16.mp4


In case it's not clear, only the results are captured (for now the
results are also printed to stderr next to the prompt)


https://user-images.githubusercontent.com/7041726/233785814-f2c8c584-9dd4-4b26-9ae9-c819ed6aa954.mp4


# User-Facing Changes
- Adds a new command `input list`
# Tests + Formatting
Not sure how we can test interactives any ideas?

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-05-04 19:14:41 +02:00
YummyOreo
edb61fc1d5
Try to show help pages for external commands w/ help command (#9025)
# 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.
-->
Makes in so if you run `std help <external>` it will run `man <command>`
to get help pages. This command is configurable w/ the `$env.NU_HELPER`
var.

This will close #8032

Examples:
`std help rg` will display the ripgrep help pages

Todo:
- [x] Make flags and fallback configurable
- [x] Improve the warning that it is external
- [ ] Implement `--find` for external commands

# User-Facing Changes
Users will now be able to run `std help` on external commands

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-04 18:34:07 +02:00
Kamil
155de9f6fc
Added log custom command & exported log levels (#9055)
# Description
- Log levels are now exported members of `std log`, e.g. `std log
CRITICAL_LEVEL`
- Added `std log custom` command that allows to declare custom message
format (actual message replaces `%MSG%` in the template) with
user-defined log level.


# User-Facing Changes
New possibilities included in description

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-04 18:30:15 +02:00
Antoine Stevan
b82e279f9d
REFACTOR: remove deprecated commands (old-alias) (#9056)
# Description
as stated in the `0.79` release note, this PR removes the `old-alias`
and `export old-alias` commands, which were deprecated before.

# User-Facing Changes
`old-alias` is gone for good 😌 

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

# After Submitting
already mentionned in the `0.79` release note.
2023-05-04 00:08:07 +02:00
Antoine Stevan
6bbe5b6255
REFACTOR: move source out of deprecated commands (#9060)
# Description
the plan of deprecating `source` never really came to conclusion, so i
propose to move it out of the deprecated commands in this PR.
i've moved it to `nu-command::misc`, which can be changed 👍 

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

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

# After Submitting
```
$nothing
```
2023-05-04 00:02:03 +02:00
Emily Grace Seville
1019acb7a3
FEATURE: highlight some prompt parts (#9094)
# Description
- highlight directory separators with light green (for regular user) and
light red (for admin) colors respectively
- highlight colons and slashes in the right prompt with light magenta
- underline AM/PM in the right prompt
- use long options to enhance readability

How it looks in MATE Terminal with Tango color theme:


![image](https://user-images.githubusercontent.com/42812113/236052908-fc80def9-9117-4b87-8ce4-321b937f3339.png)



# User-Facing Changes
- highlight directory separators in light green (for regular user) and
red colors (for admin)
- highlight colons and slashes in the right prompt with light magenta
- underline AM/PM in the right prompt

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-03 16:36:27 -05:00
Erich Gubler
83b1ec83c9
feat(rm)!: use arg. spans for I/O errors (#8964)
# Description

Currently, error spans for I/O errors in an `rm` invocation always point
to the `rm` argument. This isn't ideal, because the user loses context
as to which “target” actually had a problem:


![image](https://user-images.githubusercontent.com/658538/235723366-50db727e-9ba2-4d16-afc6-6a2406c584e0.png)

Shadow the existing `span` variable in outer scope in `rm`'s
implementation for the errors that may be detected while handling I/O
results. This is desired, because all failures from this point are
target-specific, and pointing at the argument that generated the target
instead is better. The end user should now see this:


![image](https://user-images.githubusercontent.com/658538/235724345-1d2e98e0-6b20-4bf5-b8a2-8b4368cdfb05.png)

# User-Facing Changes
* When `rm` encounters I/O errors, their spans now point to the “target”
argument associated with the error, rather than the `rm` token.

# Tests + Formatting


No tests currently cover this. I'm open to adding tests, but adding as
follow-up sounds better ATM, since this wasn't covered before.

# After Submitting

Nothing needs to be done here, AFAIK. No I/O errors are currently
demonstrated in official docs, though maybe they should be?
2023-05-03 23:12:16 +02:00
Maria José Solano
d9a00a876b
Change type of flag defaults to Option<Value> (#9085)
# Description
Follow-up of #8940. As @bobhy pointed out, it makes sense for the
behaviour of flags to match the one for positional arguments, where
default values are of type `Option<Value>` instead of
`Option<Expression>`.

# User-Facing Changes
The same ones from the original PR:
- Flag default values will now be parsed as constants.
- If the default value is not a constant, a parser error is displayed.

# Tests + Formatting

A [new
test](e34e2d35f4/src/tests/test_engine.rs (L338-L344))
has been added to verify the new restriction.
2023-05-03 23:09:36 +02:00
WindSoilder
e4625acf24
support bracketed paste (#8907)
# Description

Relative: #8113, #7630
It works on non-windows system

This pr depends on https://github.com/nushell/reedline/pull/571
2023-05-03 23:08:47 +02:00
juanPabloMiceli
7fb48b9a2f
Fix negative precision round with ints (issue #9049) (#9073)
# Description
Before this PR, `math round` ignores the input if it's an `int`. This
results in the following behaviour:
```
> 123 | math round --precision -1
123
```
When the correct result is 120.

Now `int values` are converted to `float values` before actually
rounding up the number in order to take advantage of the float
implementation.

Fixes #9049.
2023-05-03 23:07:32 +02:00
Amirhossein Akhlaghpour
5fcbefb7b4
Feat: listen for signal on glob command (#9088)
Fixes : #9002 

listen for signal cancel .
other way is in listening parallel for ctrl+c wit Arc and mps channels
if this way is not a profit
2023-05-03 21:51:25 +02:00
WindSoilder
345cdef113
Fix overlay's help message lead to internal error (#9087) 2023-05-03 14:08:54 +03:00
Jelle Besseling
a7c1b363eb
Don't run .sh files with /bin/sh (#8951)
# Description

The previous behaviour broke for me because I didn't have `sh` in my
path for my nu script. I think we shouldn't assume that just because a
file ends with `.sh` it should be executed with `sh`. `sh` might not be
available or the script might contain a hashbang for a different shell.

The idea with this PR is that nushell shouldn't assume anything about
executable files and just execute them. Later on we can think about how
non-executable files should be executed if we detect they are a script.

# User-Facing Changes

This may break some people's scripts or habits if they have wrong
assumptions about `.sh` files. We can tell them to add a hashbang and +x
bit to execute shell scripts, or prepend `bash`. If this a common
assumption something like this should be added to the book

# Tests + Formatting

I only tested manually and that did work

# After Submitting

Co-authored-by: Jelle Besseling <jelle@bigbridge.nl>
2023-05-02 17:56:35 -05:00
sam schick
d45e9671d4
Suggest existing variables on not found (#8902) 2023-05-02 18:17:14 +03:00
Antoine Stevan
517dc6d39e
pass std bench into table -e in the example (#9075)
cc/ @fdncred 

# Description
in the examples of `std bench` there is an expanded table without
explicitely expanding it...
this PR adds a `table -e` to the `std bench` call in the example.

# User-Facing Changes
the help page of `std bench` now does make sense 😌 

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

# After Submitting
```
$nothing
```
2023-05-01 08:18:51 -05:00
Darren Schroeder
e590d3587c
enable history isolation (#9063)
# Description
This PR impacts the nushell sqlite history only.

This is the first PR that enables history isolation in nushell for the
sqlite history. Hopefully, we can continue building on this.

This PR allows "history isolation" which means that other nushell
session's history won't be available in the current session when using
the uparrow/downarrow history navigation. This change only impacts the
uparrow downarrow history navigation.

What remains to be done is making ctrl+r history menu respect this
setting too. Right now, the history menu will still show you all entries
from all sessions.

The history command also shows all history items from all sessions. This
may remain unchanged since you can just filter by history session right
now.

This also fixes a bug where the session id is 0 in the sqlite history
since my April 18th reedline PR.

Closes #9064

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-05-01 08:11:38 -05:00
Maxim Zhiburt
9804cd82f8
Fix #9038 (#9042)
close #9038

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-04-28 12:50:42 -05:00
Antoine Stevan
59b85e549c
FIX: filter the std help ... by name, usage and search terms (#9035)
Should close on of the points in
- https://github.com/nushell/nushell/issues/8813

# Description
this PR uses the new `--columns` option for `find` to filter the results
of the `std help` commands on the `usage`, `name` and `search_terms`
columns.

# User-Facing Changes
the `--find` option of `std help` commands should match more closely the
built-in `help` commands output.

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

# After Submitting
```
$nothing
```
2023-04-28 12:29:47 -05:00
Antoine Stevan
dae4a9b091
FIX: give same order in std help ... as in help ... (#9034)
Should close on of the points in
- https://github.com/nushell/nushell/issues/8813

# Description
before this PR, we had a problem
```
cargo run -- -c '{
     modules: ((help modules | get name) == (std help modules | get name))
     aliases: ((help aliases | get name) == (std help aliases | get name))
     externs: ((help externs | get name) == (std help externs | get name))
     operators: ((help operators | get name) == (std help operators | get name))
     commands: ((help commands | get name) == (std help commands | get name))
}'
```
would give
```
╭───────────┬───────╮
│ modules   │ false │
│ aliases   │ true  │
│ externs   │ true  │
│ operators │ false │
│ commands  │ true  │
╰───────────┴───────╯
```

this PR removes the `name` sorting so that the orders are the same
between the `std` implementation and the built-in one.

> **Note**
> run the same `cargo run` command as above and see
> ```
> ╭───────────┬──────╮
> │ modules   │ true │
> │ aliases   │ true │
> │ externs   │ true │
> │ operators │ true │
> │ commands  │ true │
> ╰───────────┴──────╯
> ```

# User-Facing Changes
the operators in `std help ...` will be sorted just as the built-in
`help ...`.

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

# After Submitting
```
$nothing
```
2023-04-28 09:22:23 -05:00
Jelle Besseling
4ca47258a0
Add --redirect-combine option to run-external (#8918)
# Description

Add option that combines both output streams to the `run-external`
command.

This allows you to do something like this:

```nushell
let res = do -i { run-external --redirect-combine <command that prints to stdout and stderr> } | complete

if $res.exit_code != 0 {
  # Only print output when command has failed.
  print "The command has failed, these are the logs:"
  print $res.stdout
}
```

# User-Facing Changes

No breaking changes, just an extra option.

# Tests + Formatting

Added a test that checks the new option

# 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: Jelle Besseling <jelle@bigbridge.nl>
2023-04-28 07:55:48 -05:00
Steven Xu
b37662c7e1
fix: fix cursor position when cursor is at the end of the commandline (#9030)
# Description
Fix getting the cursor position, when it's at the end of the
commandline.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting

# After Submitting
2023-04-28 07:02:45 -05:00
Reilly Wood
3076378373
Slim down tests (#9021)
This PR just tidies up some tests by removing unused code:

1. If the filesystem is not touched, don't use the filesystem
playground/sandbox
2. If the filesystem is not touched, don't specify the `cwd`
3. If the command is short, don't bother wrapping it in `pipeline()`
4. If the command doesn't have quotes, don't bother with a `r#"..."#`
raw string

Part of #8670.
2023-04-28 13:25:44 +02:00
Antoine Stevan
35c8485442
FEATURE: add --expand to std clip (#8970)
# Description
i use `std clip` to copy everything from `nushell`.
however i have the auto-expand on tables enabled and when i use `clip`
on large tables, it does not copy what i see but the collapsed data => i
have to edit the line and add `| table --expand` manually, which is a
pain to do regularly 😱

in this PR, i just add `--expand` to `std clip` to automatically expand
the data before copying it 😋

# User-Facing Changes
exploring the `Cargo.toml` of `nushell` with auto-expand, one might see
```
> open Cargo.toml | get package.metadata.binstall.overrides
╭────────────────────────┬───────────────────╮
│                        │ ╭─────────┬─────╮ │
│ x86_64-pc-windows-msvc │ │ pkg-fmt │ zip │ │
│                        │ ╰─────────┴─────╯ │
╰────────────────────────┴───────────────────╯
```
but then
```
open Cargo.toml | get package.metadata.binstall.overrides | clip
```
would only copy
```
╭────────────────────────┬──────────────────╮
│ x86_64-pc-windows-msvc │ {record 1 field} │
╰────────────────────────┴──────────────────╯
```
...

now 
```
open Cargo.toml | get package.metadata.binstall.overrides | clip --expand
```
will copy the expanded record 👍 

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

# After Submitting
```
$nothing
```
2023-04-28 09:07:38 +02:00
Antoine Stevan
3268ecd116
FEATURE: add the bench command to the standard library (#8969)
Should address the first point of
- https://github.com/nushell/nushell/issues/8696.

# Description
i've seen a few appearances of this `benchmark` idea in recent works on
`nu-std`, so i thought it would be great to add it finally.

# User-Facing Changes
a new `std bench` command to measure the performance of `nushell`
closures and code blocks.

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

# After Submitting
```
$nothing
```
2023-04-28 09:07:23 +02:00
Jelle Besseling
44493dac51
Add extern def which allows raw arguments (#8956)
# Description

Extends the `extern` syntax to allow commands that accept raw arguments.
This is mainly added to allow wrapper type scripts for external
commands.

This is an example on how this can be used:

```nushell
extern foo [...rest] { 
  print ($rest | str join ',' ) 
}
foo --bar baz -- -q -u -x
# => --bar,baz,--,-q,-u,-x
```

(It's only possible to accept a single ...varargs argument in the
signature)

# User-Facing Changes

No breaking changes, just extra possibilities.

# Tests + Formatting

Added a test for this new behaviour and ran the toolkit pr checker

# After Submitting

This is advanced functionality but it should be documented, I will open
a new PR on the book for that

Co-authored-by: Jelle Besseling <jelle@bigbridge.nl>
2023-04-28 09:06:43 +02:00
TrMen
6f9b9914cf
Add more examples to help use (#9024)
# Description
The `members` parameter of `use` is specified as type `any`, but it's
really a string or list of strings or `*`. So add some examples that
mention what you can specify for `members`.

Also mention `help modules` and `help std`, since you probably want to
use the standard library or another defined modules.

Sidenote: I tried to run the examples for `use` as tests like is done
for the other commands. That panics with `missing module command`. I
assume this is known.

# User-Facing Changes
`help use` now looks like this:
```nushell
Use definitions from a module, making them available in your shell.

See `help std` for the standard library module.
See `help modules` to list all available modules.

This command is a parser keyword. For details, check:
  https://www.nushell.sh/book/thinking_in_nu.html

Usage:
  > use <module> (members)

Flags:
  -h, --help - Display the help message for this command

Parameters:
  module <string>: Module or module file
  (optional) members <any>: Which members of the module to import

Examples:
  Define a custom command in a module and call it
  > module spam { export def foo [] { "foo" } }; use spam foo; foo
  foo

  Define a custom command that participates in the environment in a module and call it
  > module foo { export def-env bar [] { let-env FOO_BAR = "BAZ" } }; use foo bar; bar; $env.FOO_BAR
  BAZ

  Use a plain module name to import its definitions qualified by the module name
  > module spam { export def foo [] { "foo" }; export def bar [] { "bar" } }; use spam; (spam foo) + (spam bar)
  foobar

  Specify * to use all definitions in a module
  > module spam { export def foo [] { "foo" }; export def bar [] { "bar" } }; use spam *; (foo) + (bar)
  foobar

  To use commands with spaces, like subcommands, surround them with quotes
  > module spam { export def 'foo bar' [] { "baz" } }; use spam 'foo bar'; foo bar
  baz

  To use multiple definitions from a module, wrap them in a list
  > module spam { export def foo [] { "foo" }; export def 'foo bar' [] { "baz" } }; use spam ['foo', 'foo bar']; (foo) + (foo bar)
  foobaz
```
2023-04-27 15:58:07 -05:00
Darren Schroeder
ffb9ab9eef
Update rust-toolchain.toml to 1.67.1 (#9012)
# Description
This PR bumps the rust toolchain from 1.66.1 to 1.67.1

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-04-27 09:31:29 -05:00
TrMen
ecc820a8c1
Fix unexpected flattening of data by par-each (Issue #8497) (#9007)
# Description
Previously, `par-each` acted like a `flatmap`: first mapping the data,
then applying a `flatten`. This is unlike `each`, which just maps the
data. Now `par-each` works like `each` in this regard, leaving nested
data unflattened.

Fixes #8497

# User-Facing Changes
Previously:
`[1 2 3] | par-each {|e| [$e, $e] }` --> `[1,1,2,2,3,3]` 
Now:
`[1 2 3] | par-each {|e| [$e, $e] }` --> `[[1,1],[2,2],[3,3]]`

# Tests
This adds one test that verifies the lack of flattening for `par-each`.
2023-04-26 23:27:27 +02:00
Darren Schroeder
6047b04208
fix compilation error (#9016)
# Description
This PR fixes a problem due to me landing an out of date PR that stopped
nushell from compiling.

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-04-26 14:38:09 -05:00
Maxim Zhiburt
8d8b011702
Bump tabled dependency to 0.11 (#8922)
close? #8060

Quite a bit of refactoring took place.
I believe a few improvements to collapse/expand were made.

I've tried to track any performance regressions and seems like it is
fine.

I've noticed something different now with default configuration path or
something in this regard?
So I might missed something while testing because of this.

Requires some oversight.

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-04-26 13:56:10 -05:00
goldfish
c422c6cc3d
Fix completion on $nu to show correct menus (#8919)
I'm still new to nushell and Rust, so please let me know if there are
any omissions and/or mistakes.

# Description

fixed #8863
`$nu` completion shows wrong completion menus at this time.
This PR fixes the problem to show the correct ones.

# User-Facing Changes

Users can use the correct menus on `$nu` completion like this
[recording](https://asciinema.org/a/KCwfpdAoMFsQODFBnb3NwmufC).

# Tests + Formatting

```
$ use toolkit.nu
$ toolkit check pr

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
```

# After Submitting

nothing
2023-04-26 09:15:27 -05:00
Maria José Solano
e251f3a0b4
Change type of parameter default values to Option<Value> (#8940)
# Description

Fixes #8939.

# User-Facing Changes

- Parameter default values will now be parsed as constants.
- If the default value is not a constant, a parser error is displayed.

# Tests + Formatting

The [only affected
test](d42c2b2dbc/src/tests/test_engine.rs (L325-L328))
has been updated to reflect the new behavior.
2023-04-26 09:14:02 -05:00
mike
77ca73f414
allow records to have type annotations (#8914)
# Description
follow up to #8529
cleaned up version of #8892 

- the original syntax is okay
```nu
def okay [rec: record] {}
```
- you can now add type annotations for fields if you know
  them before hand
```nu
def okay [rec: record<name: string>] {}
```

- you can specify multiple fields
```nu
def okay [person: record<name: string age: int>] {}

# an optional comma is allowed
def okay [person: record<name: string, age: int>] {}
```

- if annotations are specified, any use of the command will be type
  checked against the specified type
```nu
def unwrap [result: record<ok: bool, value: any>] {}

unwrap {ok: 2, value: "value"}

# errors with

Error: nu::parser::type_mismatch

  × Type mismatch.
   ╭─[entry #4:1:1]
 1 │ unwrap {ok: 2, value: "value"}
   ·         ───────┬─────
   ·                    ╰── expected record<ok: bool, value: any>, found record<ok: int, value: string>
   ╰────
```
> here the error is in the `ok` field, since `any` is coerced into any
type
> as a result `unwrap {ok: true, value: "value"}` is okay

- the key must be a string, either quoted or unquoted
```nu
def err [rec: record<{}: list>] {}

# errors with
Error:
  × `record` type annotations key not string
   ╭─[entry #7:1:1]
 1 │ def unwrap [result: record<{}: bool, value: any>] {}
   ·                            ─┬
   ·                             ╰── must be a string
   ╰────
```

- a key doesn't have to have a type in which case it is assumed to be
`any`
```nu
def okay [person: record<name age>] {}

def okay [person: record<name: string age>] {}
```

- however, if you put a colon, you have to specify a type
```nu
def err [person: record<name: >] {}

# errors with
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[entry #12:1:1]
 1 │ def unwrap [res: record<name: >] { $res }
   ·                             ┬
   ·                             ╰── expected type after colon
   ╰────
```

# User-Facing Changes
**[BREAKING CHANGES]**
- this change adds a field to `SyntaxShape::Record` so any plugins that
used it will have to update and include the field. though if you are
unsure of the type the record expects, `SyntaxShape::Record(vec![])`
will suffice
2023-04-26 08:16:55 -05:00
Amirhossein Akhlaghpour
48c75831fc
Flags and args on def (#8953)
# Description

Fixes #8916 
Fix flags and args on def which were call wrong .
Added some tests too .
2023-04-26 08:16:32 -05:00
Darren Schroeder
4b8a259916
update ast to support output to json (#8962)
# Description
This PR changes the `ast` command to be able to output `--json` as well
as `nuon` (default) with "pretty" and "minified" output. I'm hoping this
functionality will be usable in the vscode extension for semantic
tokenization and highlighting.

# User-Facing Changes
There's a new `--json`/`-j` option. Prior version output of nuon is
maintained as default.

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-04-26 08:15:42 -05:00
WindSoilder
5733a13409
support blink cursor, and fix underscore's cursorshape (#8990)
# Description
Close: #8988

Thanks to new crossterm version, nushell can support blink cursor shape.
It can be config with the following value:
1. blink_block
2. blink_line
3. blink_underscore

And original block, line, underscore will be steady. It also fixes wrong
shape of `underscore`.

# User-Facing Changes
Here is a little breaking change, before the change: `line` cursor shape
is blinking line, but after this pr, it will be `steady line`. To make a
blink line, we need to change the value to `blink_line`.

But I think it's ok, because after the change, we have a good naming
convention about the name of shape

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-04-26 08:14:50 -05:00
Steven Xu
66b5931438
fix: set the initial repl cursor pos, fixes #8943 (#8955)
# Description
Set the initial repl cursor pos, so running `commandline --insert`
inserts at the current cursor position of the input buffer.



Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
2023-04-26 01:08:11 +02:00
WindSoilder
503052b669
using ratatui instead of tui (#8952)
# Description

Refer to https://github.com/fdehau/tui-rs/issues/654, I found that tui
maybe un-maintained, instead, I'd suggest to use an actively fork
https://github.com/tui-rs-revival/ratatui

cc: @zhiburt 

# User-Facing Changes
NaN
2023-04-26 01:07:23 +02:00
Stefan Holderbach
7d6a32c5f8
Bump to 0.79.1 dev version (#8998)
# Description

For development or hotfixes
2023-04-26 01:05:23 +02:00
Stefan Holderbach
a1b7261121
Bump version for 0.79.0 release (#8980) 2023-04-25 23:06:17 +03:00
Stefan Holderbach
5a4b6f0f7f
Pin reedline to 0.19.0 release (#8996)
# Description
See release notes:

https://github.com/nushell/reedline/releases/tag/v0.19.0
2023-04-25 20:58:33 +02:00
Reilly Wood
7413ef2824
Tweak run-external signature so command must be a string (#8971)
Tiny fix: clarify in `run-external`'s signature that the external
command must be a string.

### Before
```
Signatures:
  <any> | run-external <any> -> <any>

Parameters:
  command <any>: external command to run
  ...args <any>: arguments for external command
```

### After
```
Signatures:
  <any> | run-external <string> -> <any>

Parameters:
  command <string>: external command to run
  ...args <any>: arguments for external command
```


### Notes

I was hoping to change more `any`s to more specific types, but alas I
think we can only change `command` right now. The input can be any type
and it gets rendered to a string before being passed to the external.
The args can be any value type and they get converted to strings. The
output can be either binary or a string.
2023-04-22 10:57:16 -07:00
JT
d00038eb4b
Reuse the cached parse results of parsed files (#8949)
# Description

This does a lookup in the cache of parsed files to see if a span can be
found for a file that was previously loaded with the same contents, then
uses that span to find the parsed block for that file. The end result
should, in theory, be identical but doesn't require any reparsing or
creating new blocks/new definitions that aren't needed.

This drops the sg.nu benchmark from:
```
╭───┬───────────────────╮
│ 0 │ 280ms 606µs 208ns │
│ 1 │ 282ms 654µs 416ns │
│ 2 │ 252ms 640µs 541ns │
│ 3 │  250ms 940µs 41ns │
│ 4 │ 241ms 216µs 375ns │
│ 5 │ 257ms 310µs 583ns │
│ 6 │ 196ms 739µs 416ns │
╰───┴───────────────────╯
```

to:
```
╭───┬───────────────────╮
│ 0 │ 118ms 698µs 125ns │
│ 1 │       121ms 327µs │
│ 2 │ 121ms 873µs 500ns │
│ 3 │  124ms 94µs 708ns │
│ 4 │ 113ms 733µs 291ns │
│ 5 │ 108ms 663µs 125ns │
│ 6 │  63ms 482µs 625ns │
╰───┴───────────────────╯
```

I was hoping to also see some startup time improvements, but I didn't
notice much there.

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-04-22 07:00:33 +12:00
Bob Hyman
24b4ac692e
std run-tests: Rename --command switch to --test; and likewise in --list output (#8895)
# 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.
-->
As described in #8893, switch `std run-tests --module` is ambiguous, but
`--command` is misleading. Fix that, and rename `--list` output column
to match.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
* `std run-tests --command test_foo_1` changes to `std run-tests --test
test_foo_1`, users may have to change existing scripts (or muscle
memory).
*
  ```
  〉std run-tests --list | columns
  ╭───┬────────╮
  │ 0 │ module │
  │ 1 │ name   │
  │ 2 │ file   │
  ╰───┴────────╯
  ```
  Changes to:
  
  ```
  〉std run-tests --list | columns
  ╭───┬────────╮
  │ 0 │ module │
  │ 1 │ test   │
  │ 2 │ file   │
  ╰───┴────────╯
  
  ```
# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-04-20 19:41:33 -05:00
mike
fb72da0e82
unify the *-BuiltinVar parser errors (#8944)
# Description

this pr condenses `MutBuiltinVar`, `LetBuiltinVar` and `ConstBuiltinVar`
into one error:
```nu
Error: nu::parser::name_is_builtin_var

  × `in` used as variable name.
   ╭─[entry #69:1:1]
 1 │ let in = 420
   ·     ─┬
   ·      ╰── already a builtin variable
   ╰────
  help: 'in' is the name of a builtin Nushell variable and cannot be used
        as a variable name
```

it also fixes this case which was previously not handled
```nu
let $nu = 420 # this variable would have been 'lost'
```
2023-04-20 19:44:31 +02:00
Antoine Stevan
d339902dc6
stdlib: fix the clip command with integer values (#8898)
# Description
this PR fixes the `std clip` command which would not copy integer data
😮
and, as all the input data is now treated as raw `string` with the
`table | into string` conversion, i've removed the "stripped" print when
done clipping the data 👍

 from the `main` on which this PR is based (cbedc8403)
> **Note**
> from inside`cargo run` and with a `use std clip`
- ✔️ `'foo' | clip`
- ✔️ `ls | get 0 | clip`
-  `123 | clip`
 
# User-Facing Changes
✔️ from the tip of the PR branch
> **Note**
> from inside`cargo run` and with a `use std clip`
- ✔️ `'foo' | clip`
- ✔️ `ls | get 0 | clip`
- ✔️ `123 | clip`

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

# After Submitting
```
$nothing
```
2023-04-20 18:59:34 +02:00
Darren Schroeder
393f424f1c
allow find command to look in specified columns only (#8937)
# Description
This PR allows the `find` command to search in specific columns using
`--columns [col1 col2 col3]`. This is really meant to help with the
`help` command in the std.nu.

There are a few more things I want to look at so this is a draft for
now.
- [x] add example
- [x] look at regex part

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-04-20 08:13:12 -05:00
Jelle Besseling
c8f54476c9
Set env in exec command (#8917)
# Description

Previously variables with `let-env` were not available after doing an
`exec` command. This PR fixes that

# User-Facing Changes

Can now use environment variables set with nushell after `exec`

# Tests + Formatting

No tests made but formatting has been checked

# 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: Jelle Besseling <jelle@bigbridge.nl>
2023-04-20 22:10:46 +12:00
Antoine Stevan
d42c2b2dbc
refactor the CONTRIBUTING.md guidelines for nu-std (#8912)
## Description
just a little refactor of `CONTRIBUTING.md` of the standard library in
`nu-std`.
- see the new version
[here](https://github.com/amtoine/nushell/blob/stblib/refactor/CONTRIBUTING-guidelines/crates/nu-std/CONTRIBUTING.md).

> **Note**
> actually, that one might be best reviewed commit by commit 😋 
> i tried to be as explicit as possible 😌 

- i fixed the width to `80` columns
- cc/ @bobhy, if you want to jump in and find broken links / bad changes
2023-04-19 22:21:27 +02:00
mike
ed64a44b82
add filter-map command to std iter (#8926)
# Description
as title says
2023-04-19 19:09:10 +02:00
Máté FARKAS
1855dfb656
Fix into decimal command category (#8932)
Commands like this one belong to conversions category

Fixes #8931

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-04-19 11:39:12 -05:00
mike
91c01bf6b3
add iter module to standard library (#8899)
# Description
 
this pr introduces an `iter` module
to the standard library.

the module is aimed at extending the filter commands.
2023-04-18 16:01:36 -05:00
Darren Schroeder
29256b161c
fix reedline breaking changes due to PR562 (#8921)
# Description
This PR fixes the breaking changes to the reedline API due to
https://github.com/nushell/reedline/pull/562. It does not implement any
new features but just gets nushell back to compiling again.

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-04-18 08:35:10 -05:00
JT
32f098d91d
Hopefully speedup startup (#8913)
# Description

Trying a few different things to hopefully speedup startup a bit. I'm
seeing some improvement on my box for the profiles I have, but the data
I'm seeing is noisy.

- Remove allocations in a few places where we created vec's but could
use iterators
- Pre-allocate space for blocks based on the lite block
- Removed a few extra clones

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-04-18 20:19:08 +12:00
Bob Hyman
f82a1d8e4e
Replace #8824: CONTRIBUTING.md for standard library (#8894)
# 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.
-->

Replaces #8824, which was languishing in review limbo and becoming
increasingly difficult to keep current with upstream changes.

In addition to all the edits, this PR includes updated documentation for
running unit tests via `std run-tests`.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
A CONTRIBUTING.md documenting guidelines and getting started info for
potential stdlib contributors.
# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-04-17 19:13:50 +02:00
Darren Schroeder
f0e0ab35fc
allow custom commands to show up in $nu.scope.commands better (#8910)
# Description
This PR allows our custom commands to show up in `$nu.scope.commands`
better. It still needs work because this PR hard code the input and
output types as `Type::Any` but the reason they're being missed in the
first place is that they are not assigned an input and output type.

This allows things like this now. Note the `where is_custom == true` 

![image](https://user-images.githubusercontent.com/343840/232523925-97eeef78-9722-4184-b60f-9d06f994c8e3.png)

Another example.

![image](https://user-images.githubusercontent.com/343840/232525706-d4d088d8-6597-43ba-97c8-ab03c2c7408c.png)

![image](https://user-images.githubusercontent.com/343840/232525797-b7e9ded3-b299-489e-af33-7390f4291bfd.png)


# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-04-17 11:19:37 -05:00
Darren Schroeder
3b20d6890c
remove debug print bug (#8909)
# Description
Oops. Someone just found a eprintln that I left in the code 3 weeks ago.
This removes that debug message.
2023-04-17 14:47:08 +02:00
Vaishaag Subhagan
6eb00f6c60
Fix strange error on unbalanced curly braces (#8906)
# Description

Fixes issue https://github.com/nushell/nushell/issues/8400 

# User-Facing Changes

Before

![image](https://user-images.githubusercontent.com/5063945/232443913-a8fe9f50-2014-4edd-95b0-516058566f64.png)

After

![image](https://user-images.githubusercontent.com/5063945/232444266-375d9438-0688-4f49-a884-b8650110f7fe.png)
2023-04-17 21:51:10 +12:00
Reilly Wood
4ecec59224
Upgrade open crate to fix WSL bug (#8905)
This PR upgrades the [`open`](https://github.com/Byron/open-rs) crate
(used in the `start` command) from 4.0.1 to 4.0.2. This fixes a bug
where `open` doesn't always work properly on WSL:
https://github.com/Byron/open-rs/pull/71
2023-04-16 22:05:40 -07:00
JT
bf3bb66c3e
Allocate less when doing a capture discovery (#8903)
# Description

This should be a little more efficient when running the algorithm to
find the captured variables.

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-04-17 10:24:56 +12:00
WindSoilder
cbedc8403f
update command: make $in(in closure body) takes cell path (#8610)
# Description

Make `$in` takes cell path in `update` command

The reason behind the change:
https://discord.com/channels/601130461678272522/615329862395101194/1088405671080370196
> when i use update on some cell path, it's almost always because i want
to start with its previous value and change it.

cc @amtoine 

# User-Facing Changes

## Before
```
open Cargo.toml | get package | update metadata.binstall.pkg-fmt {|| $in.metadata.binstall.pkg-fmt | str replace "g" "FOO"}
```

## After
```
open Cargo.toml | get package | update metadata.binstall.pkg-fmt {|| str replace "g" "FOO"}
```

If use want to access original raw, it can be accessed by parameters in
closure:
```
open Cargo.toml | get package | update metadata.binstall.pkg-fmt {|$it| $it.metadata.binstall.pkg-fmt | str replace "g" "FOO"}
```
For this reason, I don't think we need to add a flag like `--whole`

# 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-04-15 10:26:21 +02:00
Maria José Solano
1d68c48a92
Allow arguments for the last flag in short flag batch (#8808)
# Description
_Fixes #5923_

Currently `nushell` doesn't allow short flag batches to contain
arguments, despite this being a common pattern in commands like `git
commit -am 'My commit message'`. This PR relaxes this so that the last
flag in the batch can take an argument.

# User-Facing Changes
- `nu::parser::short_flag_arg_cant_take_arg` has been replaced by
`nu::parser::only_last_flag_in_batch_can_take_arg` and is displayed when
a flag other then the last in a short flag batch takes an argument.

# Tests + Formatting
- Both
[`test_parser.rs`](48af0ebc3c/crates/nu-parser/tests/test_parser.rs (L640-L704))
and
[`test_known_external.rs`](48af0ebc3c/src/tests/test_known_external.rs (L42-L61))
have been updated to test the new allowed and disallowed scenarios.

---------

Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
2023-04-15 10:24:51 +02:00
Amirhossein Akhlaghpour
fff4de5c44
Apply continue to each (#8889)
# Description
Fixes #8878
Add continue command on each and added new tests too .
2023-04-15 17:11:02 +12:00
goldfish
45d33e70db
Change NU_LIB_DIRS not to depend on $nu.config-path (#8887) 2023-04-14 23:16:00 +03:00
WindSoilder
9b35d59023
Update crossterm version to 0.26 (#8623)
# Description

This pr is a companion to https://github.com/nushell/reedline/pull/560

Fortunally, we don't need to change too much nushell code.

## Additional note about lscolor dependency
https://github.com/sharkdp/lscolors/pull/58~~
lscolor is using 0.26 for now
2023-04-14 22:14:57 +02:00
Sygmei
71611dec4f
feat: added items command for Records (#8640)
# Description

This PR adds an `items` command which allows the user to iterate over
both `columns` and `values` of a `Record<>` type at the same time.


![image](https://user-images.githubusercontent.com/3835355/227976277-c9badbb2-2e31-4243-8d00-7e28f2289587.png)

# User-Facing Changes

No breaking changes, only a new `items` command.

# Formatting

- `cargo fmt --all -- --check` 👌 
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` 👌
- `cargo test --workspace` 👌
2023-04-14 14:42:33 -05:00
mike
a122e55129
use let-else syntax where possible (#8886)
# Description
this pr changes some `if-let`s to `let-else`s

# User-Facing Changes
none
2023-04-14 20:51:38 +02:00
Stefan Holderbach
6cedc05384
Fix span of multibyte short flags (#8866)
# Description

Follow up to #8849

Work for #8821
Should unblock work on #8808

Missing is a restriction to printables or identifiers according to
[UAX31](https://www.unicode.org/reports/tr31/)

# User-Facing Changes

Non ASCII characters should be allowed in shortflags.

# Tests + Formatting

Want to add some tests for the error reporting cases
2023-04-14 18:53:14 +02:00
Bob Hyman
8efbb48cb0
Pick up fix in dtparse for nanosec truncation noted at bottom of #8337 (#8805)
# Description

Pick up [enhancement in
`dtparse`](https://github.com/bspeice/dtparse/pull/41), to preserve
nanoseconds in string-to-date conversions.

# User-Facing Changes

An especially eagle-eyed user might notice that prior versions of
nushell were losing nanosecond precision when converting string format
date/time to datetime.

Before:
```nushell
〉'2023-03-02T01:02:03.987654321' | into datetime | date to-record
╭────────────┬───────────╮
│ year       │ 2023      │
│ month      │ 3         │
│ day        │ 2         │
│ hour       │ 1         │
│ minute     │ 2         │
│ second     │ 3         │
│ nanosecond │ 987654000 │
│ timezone   │ -04:00    │
╰────────────┴───────────╯
```
Now, it just works(tm)
```nushell
〉'2023-03-02T01:02:03.987654321' | into datetime | date to-record
╭────────────┬───────────╮
│ year       │ 2023      │
│ month      │ 3         │
│ day        │ 2         │
│ hour       │ 1         │
│ minute     │ 2         │
│ second     │ 3         │
│ nanosecond │ 987654321 │
│ timezone   │ -04:00    │
╰────────────┴───────────╯
```

# Tests + Formatting

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

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

- [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  
Some (unrelated) tests did fail [^err]
- [x] `cargo run -- crates/nu-std/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.

# (Unrelated) test failures noted
[^err]: Several tests are failing, unrelated to this PR

```
failures:

---- modules::module_import_env_1 stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env main.nu; use main.nu foo; foo
   ·            ───┬───
   ·               ╰── file not found
   ╰────


thread 'modules::module_import_env_1' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"foo"`', tests/modules/mod.rs:316:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- modules::module_import_env_2 stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env main.nu; $env.FOO
   ·            ───┬───
   ·               ╰── file not found
   ╰────


thread 'modules::module_import_env_2' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"foo"`', tests/modules/mod.rs:341:9

---- overlays::overlay_use_do_cd_file_relative stdout ----
=== stderr

thread 'overlays::overlay_use_do_cd_file_relative' panicked at 'assertion failed: `(left == right)`
  left: `"nushell"`,
 right: `"test1"`', tests/overlays/mod.rs:919:9

---- overlays::overlay_use_dont_cd_overlay stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env test1/test2/spam.nu; $env.PWD | path basename
   ·            ─────────┬─────────
   ·                     ╰── file not found
   ╰────


thread 'overlays::overlay_use_dont_cd_overlay' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"overlay_use_dont_cd_overlay"`', tests/overlays/mod.rs:946:9

---- parsing::parse_file_relative_to_parsed_file_dont_use_cwd_1 stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env lol/lol.nu; $env.FOO
   ·            ─────┬────
   ·                 ╰── file not found
   ╰────


thread 'parsing::parse_file_relative_to_parsed_file_dont_use_cwd_1' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"good"`', tests/parsing/mod.rs:177:9

---- parsing::parse_file_relative_to_parsed_file_simple stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env lol/lol/lol.nu; $env.LOL
   ·            ───────┬──────
   ·                   ╰── file not found
   ╰────


thread 'parsing::parse_file_relative_to_parsed_file_simple' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"lol"`', tests/parsing/mod.rs:99:9

---- shell::const_nu_lib_dirs_relative stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[main.nu:1:1]
 1 │ const NU_LIB_DIRS = [ 'scripts' ]
 2 │ source-env foo.nu
   ·            ───┬──

thread 'shell::const_nu_lib_dirs_relative' panicked at 'assertion failed: outcome.err.is_empty()', tests/shell/mod.rs:166:9

---- shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_lines stdout ----
=== stderr

thread 'shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_lines' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"AndrásWithKitKat"`', tests/shell/pipeline/commands/external.rs:198:13

---- shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_strings stdout ----
=== stderr

thread 'shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_strings' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"jt_likes_cake.txt"`', tests/shell/pipeline/commands/external.rs:173:13


failures:
    modules::module_import_env_1
    modules::module_import_env_2
    overlays::overlay_use_do_cd_file_relative
    overlays::overlay_use_dont_cd_overlay
    parsing::parse_file_relative_to_parsed_file_dont_use_cwd_1
    parsing::parse_file_relative_to_parsed_file_simple
    shell::const_nu_lib_dirs_relative
    shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_lines
    shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_strings

test result: FAILED. 386 passed; 9 failed; 20 ignored; 0 measured; 0 filtered out; finished in 98.06s

error: test failed, to rerun pass `-p nu --test main`

failures:

---- modules::module_import_env_1 stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env main.nu; use main.nu foo; foo
   ·            ───┬───
   ·               ╰── file not found
   ╰────


thread 'modules::module_import_env_1' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"foo"`', tests/modules/mod.rs:316:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- modules::module_import_env_2 stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env main.nu; $env.FOO
   ·            ───┬───
   ·               ╰── file not found
   ╰────


thread 'modules::module_import_env_2' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"foo"`', tests/modules/mod.rs:341:9

---- overlays::overlay_use_do_cd_file_relative stdout ----
=== stderr

thread 'overlays::overlay_use_do_cd_file_relative' panicked at 'assertion failed: `(left == right)`
  left: `"nushell"`,
 right: `"test1"`', tests/overlays/mod.rs:919:9

---- overlays::overlay_use_dont_cd_overlay stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env test1/test2/spam.nu; $env.PWD | path basename
   ·            ─────────┬─────────
   ·                     ╰── file not found
   ╰────


thread 'overlays::overlay_use_dont_cd_overlay' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"overlay_use_dont_cd_overlay"`', tests/overlays/mod.rs:946:9

---- parsing::parse_file_relative_to_parsed_file_dont_use_cwd_1 stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env lol/lol.nu; $env.FOO
   ·            ─────┬────
   ·                 ╰── file not found
   ╰────


thread 'parsing::parse_file_relative_to_parsed_file_dont_use_cwd_1' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"good"`', tests/parsing/mod.rs:177:9

---- parsing::parse_file_relative_to_parsed_file_simple stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env lol/lol/lol.nu; $env.LOL
   ·            ───────┬──────
   ·                   ╰── file not found
   ╰────


thread 'parsing::parse_file_relative_to_parsed_file_simple' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"lol"`', tests/parsing/mod.rs:99:9

---- shell::const_nu_lib_dirs_relative stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[main.nu:1:1]
 1 │ const NU_LIB_DIRS = [ 'scripts' ]
 2 │ source-env foo.nu
   ·            ───┬──

thread 'shell::const_nu_lib_dirs_relative' panicked at 'assertion failed: outcome.err.is_empty()', tests/shell/mod.rs:166:9

---- shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_lines stdout ----
=== stderr

thread 'shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_lines' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"AndrásWithKitKat"`', tests/shell/pipeline/commands/external.rs:198:13

---- shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_strings stdout ----
=== stderr

thread 'shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_strings' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"jt_likes_cake.txt"`', tests/shell/pipeline/commands/external.rs:173:13


failures:
    modules::module_import_env_1
    modules::module_import_env_2
    overlays::overlay_use_do_cd_file_relative
    overlays::overlay_use_dont_cd_overlay
    parsing::parse_file_relative_to_parsed_file_dont_use_cwd_1
    parsing::parse_file_relative_to_parsed_file_simple
    shell::const_nu_lib_dirs_relative
    shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_lines
    shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_strings

test result: FAILED. 386 passed; 9 failed; 20 ignored; 0 measured; 0 filtered out; finished in 98.06s

error: test failed, to rerun pass `-p nu --test main`
failures:

---- modules::module_import_env_1 stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env main.nu; use main.nu foo; foo
   ·            ───┬───
   ·               ╰── file not found
   ╰────


thread 'modules::module_import_env_1' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"foo"`', tests/modules/mod.rs:316:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- modules::module_import_env_2 stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env main.nu; $env.FOO
   ·            ───┬───
   ·               ╰── file not found
   ╰────


thread 'modules::module_import_env_2' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"foo"`', tests/modules/mod.rs:341:9

---- overlays::overlay_use_do_cd_file_relative stdout ----
=== stderr

thread 'overlays::overlay_use_do_cd_file_relative' panicked at 'assertion failed: `(left == right)`
  left: `"nushell"`,
 right: `"test1"`', tests/overlays/mod.rs:919:9

---- overlays::overlay_use_dont_cd_overlay stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env test1/test2/spam.nu; $env.PWD | path basename
   ·            ─────────┬─────────
   ·                     ╰── file not found
   ╰────


thread 'overlays::overlay_use_dont_cd_overlay' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"overlay_use_dont_cd_overlay"`', tests/overlays/mod.rs:946:9

---- parsing::parse_file_relative_to_parsed_file_dont_use_cwd_1 stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env lol/lol.nu; $env.FOO
   ·            ─────┬────
   ·                 ╰── file not found
   ╰────


thread 'parsing::parse_file_relative_to_parsed_file_dont_use_cwd_1' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"good"`', tests/parsing/mod.rs:177:9

---- parsing::parse_file_relative_to_parsed_file_simple stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env lol/lol/lol.nu; $env.LOL
   ·            ───────┬──────
   ·                   ╰── file not found
   ╰────


thread 'parsing::parse_file_relative_to_parsed_file_simple' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"lol"`', tests/parsing/mod.rs:99:9

---- shell::const_nu_lib_dirs_relative stdout ----
=== stderr
Error: nu:🐚:file_not_found

  × File not found
   ╭─[main.nu:1:1]
 1 │ const NU_LIB_DIRS = [ 'scripts' ]
 2 │ source-env foo.nu
   ·            ───┬──

thread 'shell::const_nu_lib_dirs_relative' panicked at 'assertion failed: outcome.err.is_empty()', tests/shell/mod.rs:166:9

---- shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_lines stdout ----
=== stderr

thread 'shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_lines' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"AndrásWithKitKat"`', tests/shell/pipeline/commands/external.rs:198:13

---- shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_strings stdout ----
=== stderr

thread 'shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_strings' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"jt_likes_cake.txt"`', tests/shell/pipeline/commands/external.rs:173:13


failures:
    modules::module_import_env_1
    modules::module_import_env_2
    overlays::overlay_use_do_cd_file_relative
    overlays::overlay_use_dont_cd_overlay
    parsing::parse_file_relative_to_parsed_file_dont_use_cwd_1
    parsing::parse_file_relative_to_parsed_file_simple
    shell::const_nu_lib_dirs_relative
    shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_lines
    shell::pipeline::commands::external::it_evaluation::takes_rows_of_nu_value_strings

test result: FAILED. 386 passed; 9 failed; 20 ignored; 0 measured; 0 filtered out; finished in 98.06s

error: test failed, to rerun pass `-p nu --test main`
```
2023-04-14 07:24:46 -05:00
Máté FARKAS
0bfa769b7d
std: remove logging example (#8877)
The example is is going to be included in the documentation, so I think
we no longer need it here.
See: https://github.com/nushell/nushell.github.io/pull/870
2023-04-14 07:15:56 -05:00
dependabot[bot]
5afc49250f
Bump umask from 2.0.0 to 2.1.0 (#8835) 2023-04-14 12:15:22 +00:00
dependabot[bot]
efb81a1277
Bump winreg from 0.11.0 to 0.50.0 (#8837) 2023-04-14 12:15:01 +00:00
Jelle Besseling
8ddebcb932
Add $env.CURRENT_FILE variable (#8861)
Co-authored-by: Jelle Besseling <jelle@bigbridge.nl>
2023-04-13 23:33:29 +03:00
Máté FARKAS
b2d7427d2d
Move unit test runner to standard library (#8850)
Move test runner to standard library.
Originated from #8819 

# After Submitting

I'll update the documentation about testing:
http://www.nushell.sh/book/testing.html

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-04-13 21:46:37 +02:00
dependabot[bot]
b4400c4896
Bump rstest from 0.16.0 to 0.17.0 (#8836) 2023-04-13 18:58:37 +00:00
dependabot[bot]
5a8d4c628f
Bump sys-locale from 0.2.4 to 0.3.0 (#8838) 2023-04-13 18:57:25 +00:00
Vaishaag Subhagan
3603610026
Correct error description for unknown external commands (#8868)
# Description
Fixes issue https://github.com/nushell/nushell/issues/8643 

# User-Facing Changes

Before
<img width="442" alt="image"
src="https://user-images.githubusercontent.com/5063945/231624884-49a1ce4e-598d-4d19-882d-c22d168e6a5a.png">

After
<img width="449" alt="image"
src="https://user-images.githubusercontent.com/5063945/231625076-5f1becd7-7477-4d2f-b765-3956210da7f2.png">
2023-04-13 19:33:05 +02:00
WindSoilder
017151dff1
optimize hash md5 for binary input (#8860)
# Description

Fixes: #8260

# User-Facing Changes

`open bigfile | hash md5` no longer consumes too much memory

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-04-13 19:29:06 +02:00
WindSoilder
ad90b6e5f3
rm: enable trash flag on android and ios platrofm (#8871)
# Description

As title, enable trash flag on all platforms make `rm` more portable
across different platforms, but `-t` will do nothing.

Fixes: #8104

# User-Facing Changes
Na

# Tests + Formatting
It's hard to add tests because we don't run tests for android and ios
platforms.

# 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: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-04-13 07:34:52 -05:00
Antoine Stevan
36036d9308
FEATURE: do not use theme-independant colors in the default configs (#8855)
# Description
i was playing with my theme a bit and i was thinking about the following
- the default themes should not use precise colors
- the default themes should let the terminal set the exact colors

for instance, the `filesize` field of the `$env.config.color_config`
looks good but not with terminal themes like dracula or tokyonight
😮

in this PR, i just use "built-in" colors, like `red` or `yellow_bold` or
`{fg: green attr: n}` to let the terminal theme set the colors 😋

# User-Facing Changes
i tried to stay as close as the previous default themes, so there should
be the least amount of differences 😌

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

# After Submitting
```
$nothing
```
2023-04-12 17:09:44 -05:00
JT
487789b45b
Adds multi-file support to IDE support (#8857)
# Description

This adds multi-file support to the in-progress IDE support. The main
new features are a `-I` flag that allows you to add a new source search
path when starting up the nu binary, and fixes for the current IDE
support to support spans in other files.

This needs accompanying fixes to the vscode/lsp implementation to pass
along the project directory via `-I`.

UPDATE: Marking this draft until we have a means to test this.

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-04-13 05:36:29 +12:00
JT
8ee52b6ee1
Relax the closure syntax, highlight differently (#8846)
# Description

This relaxes the closure syntax so that `||` is no longer required. This
allows for `ls | each { $in.name }` for example.

I've gone ahead and changed the syntax highlighting so that blocks and
closures are distinct for now.

# User-Facing Changes

Removes `||` requirement for closures.

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-04-12 05:21:52 +12:00
JT
46dba8853a
Revert numberlike parsing restriction (#8845)
# Description

This effectively reverts #8635. We shipped this change with 0.78 and
received many comments/issues related to this restriction feeling like a
step backward.

fixes: #8844 
(and probably other issues)

# User-Facing Changes

Returns numbers and number-like values to being allowed to be bare
words. Examples: `3*`, `1fb43`, `4,5`, and related.

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-04-12 05:21:31 +12:00
federico viscomi
eb4d19fb9c
Parser panic for signature with multibyte char for short flag #8821 (#8849)
Hey I'm a developer and I'm still new to nushell and rust but I would
like to learn more about both. This is my first PR for this project.

The intent of my change is to allow to use multibyte utf-8 characters in
commands short flags.
2023-04-11 09:52:51 +12:00
Máté FARKAS
c3678764b4
stdlib test runner: implement setup and teardown commands to unit tests (#8776)
# Description

As in other testing frameworks, the `setup` runs before every test case,
and the `teardown` after that. A context can be created in `setup`,
which will be in the `$in` variable in the test cases, and in the
`teardown`. The `teardown` is called regardless of the test is passed,
skipped, or failed.

For example:

```nushell
use std.nu *

export def setup [] {
    log debug "Setup is running"
    {msg: "This is the context"}
}

export def teardown [] {
    log debug $"Teardown is running. Context: ($in)"
}

export def test_assert_pass [] {
    log debug $"Assert is running. Context: ($in)"
}

export def test_assert_skip [] {
    log debug $"Assert is running. Context: ($in)"
    assert skip
}

export def test_assert_fail_skipped_by_default [] {
    log debug $"Assert is running. Context: ($in)"
    assert false
}
```


![image](https://user-images.githubusercontent.com/282320/230466359-9908cc72-edbd-4150-9aff-d15fe42c0cc7.png)

# After Submitting

I'll update the documentation.

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-04-10 22:42:11 +02:00
nibon7
74dcac3b0d
Fix process_range on 32-bit platforms (#8842)
# Description

This PR fixes
`commands::str_::substrings_the_input_and_treats_end_index_as_length_if_blank_end_index_given`
testcase on 32-bit platform.

```
failures:
---- commands::str_::substrings_the_input_and_treats_end_index_as_length_if_blank_end_index_given stdout ----
=== stderr
thread 'commands::str_::substrings_the_input_and_treats_end_index_as_length_if_blank_end_index_given' panicked at 'assertion failed: `(left == right)`
  left: `"arepa"`,
 right: `"arepas"`', crates/nu-command/tests/commands/str_/mod.rs:363:9
failures:
    commands::str_::substrings_the_input_and_treats_end_index_as_length_if_blank_end_index_given
test result: FAILED. 1072 passed; 1 failed; 23 ignored; 0 measured; 0 filtered out; finished in 2.98s
error: test failed, to rerun pass `-p nu-command --test main`
```

https://gitlab.alpinelinux.org/nibon7/aports/-/jobs/1005935#L3864
https://gitlab.alpinelinux.org/nibon7/aports/-/jobs/1005931#L3867

# User-Facing Changes

N/A

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-04-11 06:52:42 +12:00
Antoine Stevan
6d51e34d0a
stdlib: make helper modules available in std (#8841)
> **Note**
> waiting for the following to land
> - https://github.com/nushell/nushell/pull/8824 to avoid conflicts,
i'll add this to `CONTRIBUTING.md` once it's ready 👍

should close #8839 

# Description
this PR moves the `log` submodule of `std` to the top of the call stack,
making it available in the rest of the library as `log`.
i've added some comments around the `submodules` list in
`load_standard_library` to make it clear how it should work.
 
# User-Facing Changes
`log` and `assert` are now available in the rest of `std`.

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

# After Submitting
```
$nothing
```
2023-04-10 13:32:33 -05:00
WindSoilder
de76c7a57d
Remove autoprinting of for loop (#8843)
# Description

It's an addition to https://github.com/nushell/nushell/pull/8618
And I think it's good to keep the same behavior when we use for loop for
list.

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-04-11 05:23:22 +12:00
Stefan Holderbach
0e23400510
Follow up #8758 with a style fix (#8822)
# Description

The old comment around the question mark operator doesn't make sense
 to me based on the closure signature.
The `match` expressions were thus superfluous.


# User-Facing Changes

None

# Tests + Formatting

No change
2023-04-09 18:42:43 -07:00
Antoine Stevan
d0a83fec69
stdlib: add completion to help commands (#8799)
> **Note**
> waiting for
> - https://github.com/nushell/nushell/pull/8770
> - #8815

# Description
this PR adds a very basic completion support to the `help`
implementations of the `std`.

# User-Facing Changes
completion on all the `std help ...` commands, based on the names in
`$nu.scope.`

# Tests + Formatting
-  `toolkit fmt`
-  `toolkit clippy`
-  `toolkit test`
-  `toolkit test stdlib`

# After Submitting
```
$nothing
```
2023-04-10 10:59:57 +12:00
Stefan Holderbach
57510f2fd2
Move CLI related commands to nu-cli (#8832)
# Description

Part of the larger cratification effort.

Moves all `reedline` or shell line editor specific commands to `nu-cli`.

## From `nu-cmd-lang`:
- `commandline`
- This shouldn't have moved there. Doesn't directly depend on reedline
but assumes parts in the engine state that are specific to the use of
reedline or a REPL

## From `nu-command`:
- `keybindings` and subcommands
  - `keybindings default`
  - `keybindings list`
  - `keybindings listen`
    - very `reedline` specific
- `history`
  - needs `reedline`
- `history session`

## internal use
Instead of having a separate `create_default_context()` that calls
`nu-command`'s `create_default_context()`, I added a `add_cli_context()`
that updates an `EngineState`


# User-Facing Changes

None

## Build time comparison

`cargo build --timings` from a `cargo clean --profile dev`

### total
main: 64 secs
this: 59 secs

### `nu-command` build time

branch | total| codegen | fraction  
---|---|---|---
main | 14.0s | 6.2s | (44%)
this | 12.5s | 5.5s | (44%)

`nu-cli` depends on `nu-command` at the moment.
Thus it is built during the code-gen phase of `nu-command` (on 16
virtual cores)

# Tests + Formatting

I removed the `test_example()` facilities for now as we had not run any
of the commands in an `Example` test and importing the right context for
those tests seemed more of a hassle than the duplicated
`test_examples()` implementations in `nu-cmd-lang` and `nu-command`
2023-04-10 10:56:47 +12:00
JT
58b96fdede
Add option to not load std-lib. Default tests to not use std-lib (#8833)
this adds a `--no-std-lib` flag. Moves `nu!` to use the `--no-std-lib`.
Adds a new `nu_with_std!` macro for future tests that need the std-lib.

# 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
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-04-10 10:55:29 +12:00
JT
9e3d6c3bfd
Only add the std lib files once (#8830)
# Description

We were seeing duplicate entries for the std lib files, and this PR
addresses that. Each file should now only be added once.

Note: they are still parsed twice because it's hard to recover the
module from the output of `parse` but a bit of clever hacking in a
future PR might be able to do that.

# 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-std/tests/run.nu` to run the tests for the
standard library

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-04-10 08:55:47 +12:00
Antoine Stevan
4a955d7e76
stdlib: refactor into a multi-module library (#8815) 2023-04-09 20:00:20 +03:00
mike
637283ffad
allow register to accept a const argument (#8758)
# Description

this pr allows `register` to be used with const variables
```nu
const math_plugin = "~/.config/nushell/plugins/nu_plugin_math"
register $math_plugin
```

should close #8208, previous work #8435
2023-04-08 15:04:57 -05:00
Antoine Stevan
d128c0e02b
stdlib: use the loaded library in tests and update README (#8811)
Should close #8809.

# Description
this PR uses the automatically loaded library from the tests by
replacing `use std.nu ...` with `use std ...`.

the `README` has been updated by
- removing the very deprencated "concrete examples"
- fixing the `use std` and the "run the tests" sections

the `README` can be previewed
[here](https://github.com/amtoine/nushell/blob/refactor/stdlib/use-std-in-tests-and-update-readme/crates/nu-std/README.md)
👍

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

# Tests + Formatting
- 🟢 `toolkit test stdlib`

# After Submitting
```
$nothing
```
2023-04-08 07:35:16 -05:00
Michael Angerman
60e6ea5abd
remove nu_cli crate dependency from nu_std (#8807)
now nu_std only depends on nu_parser, nu_protocol and miette
and removes the nu_cli dependency

this enables developers moving forward to come along and implement their
own CLI's without having to pull in a redundant nu-cli which will not be
needed for them.

I did this by moving report_error into nu_protocol
which nu_std already has a dependency on anyway....



- `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-std/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
> ```
2023-04-08 13:53:43 +02:00
Antoine Stevan
415607706f
remove the "MODULE NOT FOUND" print from the parser (#8816)
related to #8765.
should close #8812.

# Description
this PR simply removes the `prinln("MODULE NOT FOUND")` from the parser.

# User-Facing Changes
no more `MODULE NOT FOUND` while typing a `use` command
2023-04-08 13:19:09 +02:00
JT
f2b977b9c5
improve operation mismatch errors (#8800)
# Description

This improves the operation mismatch error in a few ways:

* We now detect if the left-hand side of the operation is at fault, and
show a simpler error/error message if it is
* Removed the unhelpful hint
* Updated the error text to make it clear what types are causing the
issue


![image](https://user-images.githubusercontent.com/547158/230666329-537a8cae-6350-4ee7-878e-777e05c4f265.png)


![image](https://user-images.githubusercontent.com/547158/230666353-93529dc2-039a-4774-a84c-a6faac94d8e2.png)


# User-Facing Changes

Error texts and spans will change

# 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-08 09:32:44 +12:00
Harshal Chaudhari
35e8420780
fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793)
# Description

This PR further fixes tests as part of #8670 

# 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-07 14:09:55 -07:00
Michael Angerman
5ec6edb9c5
add LICENSE to nu-std (#8803)
# 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
- `cargo run -- crates/nu-std/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-07 13:39:21 -07:00
Antoine Stevan
5d8bedfbe4
stdlib: make the library a standalone crate (#8770)
# Description
as we now have a prelude thanks to #8627, i'd like to work on the
structure of the library 😋

and i think the first step is to make it a true standalone crate 😏

this PR
- moves all the library from `crates/nu-utils/standard_library/` to
`crates/nu-std/`
- moves the `rust` loading code from `src/run.rs` to
`crates/nu-std/src/lib.rs`
2023-04-07 22:12:27 +02:00
JT
0477493734
Fix parser recovery after error (#8798)
# Description

This fixes the parser recovery after the first error (at least the main
culprit), where `parse_value` was not able to properly parse `any`
values after the first error.

fixes #8796 

# 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
- `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-08 07:01:12 +12:00
Jelle Besseling
e6b196c141
Add $nu.current-exe variable (#8789)
# Description

Part solving #8752

Adds an extra variable to the `nu` table `current-exe` which is the path
to the running shell executable.

# User-Facing Changes

Adds a variable to the `nu` table.

# Tests + Formatting

Tests and formatting have been run. No new test added

# After Submitting

I could add documentation for this if wanted

Co-authored-by: Jelle Besseling <jelle@bigbridge.nl>
2023-04-07 13:51:09 -05:00
Antoine Stevan
49960beb35
FEATURE: make the link in the ansi extra usage an ANSI link (#8795)
# Description
this addresses the comments of @fdncred from
https://github.com/nushell/nushell/issues/8713#issuecomment-1498206087

the exact ANSI link has been generated with
```bash
"https://en.wikipedia.org/wiki/ANSI_escape_code" | ansi link --text "ANSI escape code" | debug -r
```

# User-Facing Changes
there is now an ANSI link in the `ansi` help page instead of a markdown
link.

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

# After Submitting
```
$nothing
```
2023-04-07 13:39:51 -05:00
Jakub Žádník
1b677f167e
Remove old alias implementation (#8797) 2023-04-07 21:09:38 +03:00
goldfish
a3ea0c304a
Fix config {nu,env} to open $nu.{config,env}-file (#8792)
# Description

fixed #8755
Now, command `config {nu,env}` opens default file
`.config/nushell/{config,env}.nu`.
This behavior is inappropriate when `nu` is launched with option
`--config` or `--env-config`.
This PR changes the file that the command opens to
`$nu.{config,env}-file`.

# User-Facing Changes

`config {nu,env}` opens `$nu.{config,env}-file`.
2023-04-07 18:37:54 +02:00
WMR
4fda6d7eaa
Add regex separators for split row/list/column (#8707)
# Description

Verified on discord with maintainer

Change adds regex separators in split rows/column/list. The primary
motivating reason was to make it easier to split on separators with
unbounded whitespace without requiring a lot of trim jiggery. But,
secondary motivation is the same as the set of all motivations for
adding split regex features to most languages.

# User-Facing Changes

Adds -r option to split rows/column/list.

# Tests + Formatting

Ran tests, however tests.nu fails with unrelated errors:

```
~/src/nushell> cargo run -- crates/nu-utils/standard_library/tests.nu                                                                                                                                                          04/02/2023 02:07:25 AM
    Finished dev [unoptimized + debuginfo] target(s) in 0.24s
     Running `target/debug/nu crates/nu-utils/standard_library/tests.nu`
INF|2023-04-02T02:07:27.060|Running tests in test_asserts
INF|2023-04-02T02:07:27.141|Running tests in test_dirs
Error:
  × list is just pwd after initialization

INF|2023-04-02T02:07:27.167|Running tests in test_logger
INF|2023-04-02T02:07:27.286|Running tests in test_std
Error:
  × some tests did not pass (see complete errors above):
  │
  │       test_asserts test_assert
  │       test_asserts test_assert_equal
  │       test_asserts test_assert_error
  │       test_asserts test_assert_greater
  │       test_asserts test_assert_greater_or_equal
  │       test_asserts test_assert_length
  │       test_asserts test_assert_less
  │       test_asserts test_assert_less_or_equal
  │       test_asserts test_assert_not_equal
  │     ⨯ test_dirs test_dirs_command
  │       test_logger test_critical
  │       test_logger test_debug
  │       test_logger test_error
  │       test_logger test_info
  │       test_logger test_warning
  │       test_std test_path_add
  │
```

Upon investigating seeing this difference:

```
╭───┬─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 0 │ /var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5         │
│ 1 │ /private/var/folders/1f/ltbr1m8s5s1811k6n1rhpc0r0000gn/T/test_dirs_c1ed89d6-19f7-47c7-9e1f-74c39f3623b5 │
╰───┴─────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```

This seems unrelated to my changes, but can investigate further if
desired.

# 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: Robert Waugh <robert@waugh.io>
2023-04-07 06:46:11 -05:00
Bob Hyman
771e24913d
range operator accepts bot..=top as well as bot..top (#8382)
# Description

A compromise fix for #8162. Nushell range operator now accepts `..=` to
mean the range includes the top value, so you can use your Rust habits.
But the unadorned `..` range operator also includes the value, so you
can also use your Nushell habits.

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

```nushell
〉1..5
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 4 │
│ 4 │ 5 │
╰───┴───╯
-------------------------------------------- /home/bobhy/src/rust/nushell --------------------------------------------
〉1..=5
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 4 │
│ 4 │ 5 │
╰───┴───╯
-------------------------------------------- /home/bobhy/src/rust/nushell --------------------------------------------
〉1..<5
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 4 │
╰───┴───╯
```
# User-Facing Changes

Existing scripts with range operator will continue to operate as
heretofore.

_(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:

- [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

Will update the book to include new syntax.
2023-04-07 06:40:05 -05:00
JT
aded2c1937
Refactor to support multiple parse errors (#8765)
# Description

This is a pretty heavy refactor of the parser to support multiple parser
errors. It has a few issues we should address before landing:

- [x] In some cases, error quality has gotten worse `1 / "bob"` for
example
- [x] if/else isn't currently parsing correctly
- probably others

# User-Facing Changes

This may have error quality degradation as we adjust to the new error
reporting mechanism.

# 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-07 12:35:45 +12:00
Jakub Žádník
e54b867e8e
Remove parser keywords label from commands that do not need it (#8780) 2023-04-07 01:12:21 +03:00
Jakub Žádník
c12b4b4af7
Aliasing math expression shows error earlier (#8779) 2023-04-07 00:40:53 +03:00
Jakub Žádník
87ddba0193
Allow multi-word aliases (#8777) 2023-04-07 00:05:09 +03:00
dependabot[bot]
a29b61bd4f
Bump miette from 5.6.0 to 5.7.0 (#8720) 2023-04-06 20:39:54 +00:00
Antoine Stevan
d06ebb1686
standard library: implement help commands with $nu (#8505) 2023-04-06 22:13:22 +03:00
Máté FARKAS
74283c3ebc
stdlib: add assert skip command to skip test case (#8748) 2023-04-06 13:03:10 -05:00
Jelle Besseling
8a030f3bfc
Add ppid example for ps (#8768)
# Description

Add an extra example for the `ps` command

# User-Facing Changes

Only adds this example:


![image](https://user-images.githubusercontent.com/1576660/230374829-dc957b89-0a76-451d-baba-5e4463b150c3.png)

# Tests + Formatting

N/A

# After Submitting

This is related to https://github.com/nushell/nushell.github.io/pull/864

Co-authored-by: Jelle Besseling <jelle@bigbridge.nl>
2023-04-06 07:32:12 -05:00
Máté FARKAS
5518ffd248
Stdlib: use default color for info log level (#8766)
To make it work with a light theme, as well. The dark theme is not
affected, since the default color is white there.

## Before


![image](https://user-images.githubusercontent.com/282320/230329663-6fae7b7d-7062-459c-ad80-8da3a243d606.png)

## After


![image](https://user-images.githubusercontent.com/282320/230329784-c40bf93e-0740-4b87-ae19-84fd7983898a.png)

Also, I added back the example command to the test script which is very
useful in these cases...

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-04-06 06:45:45 -05:00
Jan9103
bcdb9bf5b4
Update some help examples (#8759)
# 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.)_
-->

Recently a few things changed, which now create issues:
- `1.0.0`, `+500`, and `0x000000` used to get parsed as string, but now
just errors
- `each { print $in }` -> `each {|| print $in }`

I looked through all the help pages and fixed every highlighted (red
background) error: `help commands | each {|i| help $i.name} | table |
less`

# User-Facing Changes

<!--
_(List of all changes that impact the user experience here. This helps
us keep track of breaking changes.)_
-->

The examples work again and no longer contain error syntax-highlighting

# 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-05 18:36:00 -05:00
dependabot[bot]
3509bde1a9
Bump windows from 0.46.0 to 0.48.0 (#8721)
Bumps [windows](https://github.com/microsoft/windows-rs) from 0.46.0 to
0.48.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/microsoft/windows-rs/releases">windows's
releases</a>.</em></p>
<blockquote>
<h2>0.48.0</h2>
<p>This release includes an update to all crates to address a target
version reliability issue. This issue is detailed here: <a
href="https://redirect.github.com/microsoft/windows-rs/issues/2410#issuecomment-1490802715">microsoft/windows-rs#2410</a></p>
<h2>What's Changed</h2>
<ul>
<li>Improve target version reliability by <a
href="https://github.com/kennykerr"><code>@​kennykerr</code></a> in <a
href="https://redirect.github.com/microsoft/windows-rs/pull/2412">microsoft/windows-rs#2412</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/microsoft/windows-rs/compare/0.47.0...0.48.0">https://github.com/microsoft/windows-rs/compare/0.47.0...0.48.0</a></p>
<h2>0.47.0</h2>
<p>As a reminder, updates are only published by request (<a
href="https://redirect.github.com/microsoft/windows-rs/issues/2397">#2397</a>;
<a
href="https://redirect.github.com/microsoft/win32metadata/issues/1507">microsoft/win32metadata#1507</a>).
This release provides an update to the <code>windows</code> crate. It
does not include an update to the <code>windows-sys</code> crate.</p>
<p>This update adds support for standalone code generation (<a
href="https://redirect.github.com/microsoft/windows-rs/issues/2396">#2396</a>)
as well as requested fixes to the Win32 metadata that prevented some
APIs from being used.</p>
<h2>What's Changed</h2>
<ul>
<li>Workaround for <code>rustdoc</code> regression by <a
href="https://github.com/kennykerr"><code>@​kennykerr</code></a> in <a
href="https://redirect.github.com/microsoft/windows-rs/pull/2381">microsoft/windows-rs#2381</a></li>
<li>Token privilege samples by <a
href="https://github.com/kennykerr"><code>@​kennykerr</code></a> in <a
href="https://redirect.github.com/microsoft/windows-rs/pull/2382">microsoft/windows-rs#2382</a></li>
<li>Apply <code>const</code> parameter metadata by <a
href="https://github.com/kennykerr"><code>@​kennykerr</code></a> in <a
href="https://redirect.github.com/microsoft/windows-rs/pull/2384">microsoft/windows-rs#2384</a></li>
<li>Advanced metadata filtering by <a
href="https://github.com/kennykerr"><code>@​kennykerr</code></a> in <a
href="https://redirect.github.com/microsoft/windows-rs/pull/2385">microsoft/windows-rs#2385</a></li>
<li>Update Win32 metadata v46 by <a
href="https://github.com/kennykerr"><code>@​kennykerr</code></a> in <a
href="https://redirect.github.com/microsoft/windows-rs/pull/2387">microsoft/windows-rs#2387</a></li>
<li>Support standalone code generation by <a
href="https://github.com/kennykerr"><code>@​kennykerr</code></a> in <a
href="https://redirect.github.com/microsoft/windows-rs/pull/2396">microsoft/windows-rs#2396</a></li>
<li>Update readme to include <code>windows-targets</code> and
<code>windows-bindgen</code> by <a
href="https://github.com/kennykerr"><code>@​kennykerr</code></a> in <a
href="https://redirect.github.com/microsoft/windows-rs/pull/2399">microsoft/windows-rs#2399</a></li>
<li>Update Win32 metadata v47 by <a
href="https://github.com/kennykerr"><code>@​kennykerr</code></a> in <a
href="https://redirect.github.com/microsoft/windows-rs/pull/2400">microsoft/windows-rs#2400</a></li>
<li>Version 0.47.0 by <a
href="https://github.com/kennykerr"><code>@​kennykerr</code></a> in <a
href="https://redirect.github.com/microsoft/windows-rs/pull/2401">microsoft/windows-rs#2401</a></li>
<li>Add CLR test for lib validation by <a
href="https://github.com/kennykerr"><code>@​kennykerr</code></a> in <a
href="https://redirect.github.com/microsoft/windows-rs/pull/2403">microsoft/windows-rs#2403</a></li>
<li>Restore reproducible libs by <a
href="https://github.com/riverar"><code>@​riverar</code></a> in <a
href="https://redirect.github.com/microsoft/windows-rs/pull/2402">microsoft/windows-rs#2402</a></li>
<li>Check diff for all targets by <a
href="https://github.com/kennykerr"><code>@​kennykerr</code></a> in <a
href="https://redirect.github.com/microsoft/windows-rs/pull/2404">microsoft/windows-rs#2404</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/microsoft/windows-rs/compare/0.46.0...0.47.0">https://github.com/microsoft/windows-rs/compare/0.46.0...0.47.0</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="406944152e"><code>4069441</code></a>
Improve target version reliability (<a
href="https://redirect.github.com/microsoft/windows-rs/issues/2412">#2412</a>)</li>
<li><a
href="ec95c1e6ac"><code>ec95c1e</code></a>
Check diff for all targets (<a
href="https://redirect.github.com/microsoft/windows-rs/issues/2404">#2404</a>)</li>
<li><a
href="91e0a5c079"><code>91e0a5c</code></a>
Restore reproducible libs (<a
href="https://redirect.github.com/microsoft/windows-rs/issues/2402">#2402</a>)</li>
<li><a
href="36ea325a8d"><code>36ea325</code></a>
Add CLR test for lib validation (<a
href="https://redirect.github.com/microsoft/windows-rs/issues/2403">#2403</a>)</li>
<li><a
href="e03d14e2d0"><code>e03d14e</code></a>
Version 0.47.0 (<a
href="https://redirect.github.com/microsoft/windows-rs/issues/2401">#2401</a>)</li>
<li><a
href="f86349d691"><code>f86349d</code></a>
Update Win32 metadata v47 (<a
href="https://redirect.github.com/microsoft/windows-rs/issues/2400">#2400</a>)</li>
<li><a
href="3e3c87b5ed"><code>3e3c87b</code></a>
Update readme to include <code>windows-targets</code> and
<code>windows-bindgen</code> (<a
href="https://redirect.github.com/microsoft/windows-rs/issues/2399">#2399</a>)</li>
<li><a
href="6672c6d28a"><code>6672c6d</code></a>
Support standalone code generation (<a
href="https://redirect.github.com/microsoft/windows-rs/issues/2396">#2396</a>)</li>
<li><a
href="f3ef2cdfa7"><code>f3ef2cd</code></a>
Update Win32 metadata v46 (<a
href="https://redirect.github.com/microsoft/windows-rs/issues/2387">#2387</a>)</li>
<li><a
href="3507dcd3b1"><code>3507dcd</code></a>
Advanced metadata filtering (<a
href="https://redirect.github.com/microsoft/windows-rs/issues/2385">#2385</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/microsoft/windows-rs/compare/0.46.0...0.48.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=windows&package-manager=cargo&previous-version=0.46.0&new-version=0.48.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-04-05 16:54:26 -05:00
mike
add20873d0
make str index-of -r use ranges (#8724)
# Description

final follow up to #8660 

# User-Facing Changes

**BREAKING CHANGE**
any scripts using the previous string or list syntax will **BREAK**
2023-04-05 23:22:40 +02:00
Antoine Stevan
427db0d101
FEATURE: better ansi -e error (#8709)
Should close #8704.

# Description
this PR
- makes the error thrown by things like `ansi -e {invalid: "invalid"}`
more explicit
- makes the `ansi -e` example more explicit about valid / invalid keys

# User-Facing Changes
the error
```bash
> ansi -e {invalid: "invalid"}
Error: nu:🐚:incompatible_parameters

  × Incompatible parameters.
   ╭─[entry #1:1:1]
 1 │ ansi -e {invalid: "invalid"}
   ·         ──────────┬─────────
   ·                   ╰── unknown ANSI format key: expected one of ['fg', 'bg', 'attr'], found 'invalid'
   ╰────
```

the new `ansi -e` example
```bash
  Use structured escape codes
  > let bold_blue_on_red = {  # `fg`, `bg`, `attr` are the acceptable keys, all other keys are considered invalid and will throw errors.
        fg: '#0000ff'
        bg: '#ff0000'
        attr: b
    }
    $"(ansi -e $bold_blue_on_red)Hello Nu World(ansi reset)"
  Hello Nu World
```

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

# After Submitting
```
$nothing
```
2023-04-05 23:14:39 +02:00
JT
56efbd7de9
Add IDE support (#8745)
# Description

This adds a set of new flags on the `nu` binary intended for use in
IDEs. Here is the set of supported functionality so far:

* goto-def - go to the definition of a variable or custom command
* type hints - see the inferred type of variables
* check - see the errors in the document (currently only one error is
supported)
* hover - get information about the variable or custom command
* complete - get a completion list at the current position

# User-Facing Changes

No changes to the REPL experience. This only impacts the IDE scenario.

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

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-04-06 07:34:47 +12:00
dependabot[bot]
91282d4404
Bump git2 from 0.16.1 to 0.17.0 (#8722) 2023-04-05 19:20:58 +00:00
Artemiy
f723bc6989
Std xml utils (#8437)
# Description

Add `xaccess`,`xupdate` and `xinsert` scripts to standard library. They
allow accessing and manipulating data in new xml format
https://github.com/nushell/nushell/pull/7947 with relative ease.

Access some data in nushell xml structure:

![image](https://user-images.githubusercontent.com/17511668/224785447-317359e2-1430-4dfc-9307-73f1d5e50098.png)

Update attributes of xml tags matching a path:

![image](https://user-images.githubusercontent.com/17511668/224785506-85e9aa30-b36b-43db-af1d-2f4460563124.png)


# User-Facing Changes

New commands `std xaccess`, `std xupdate` and `std xinsert`

# 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-04-05 13:54:08 -05:00
Antoine Stevan
22142bd4ae
add a cross platform clip command to the standard library (#8695)
Should close the associated poin in #8311

# Description
this PR adds a `clip` command to `std` which
- has error support in case the clipboard system command is not
installed
- removes any ANSI escape sequences from the input to have a clean
copied text
- can throw desktop notifications on linux in case of a long pipeline
which needs to be copied (can be disabled with `--no-notify`)
- echoes the copied data to the output of the terminal (can be disabled
with --silent)
- has examples and dependencies listed
- has "charpage" 65001 (a.k.a. utf-8) support for windows

## new additions from 9cd3c951f to
ad3e8de25b
- better OS context error support
- use of the `match` statement for scalability
- `match` the value of the `$nu.os-info.name`
- add `macOS` with `pbcopy` to the list of supported systems
- throw an error when the OS is not supported
- ~~add simple tests to make sure `clip` works on all main OSes with the
CI~~ had to be removed in 6028b98483 (see
[the failing
test](https://github.com/nushell/nushell/actions/runs/4610091544/jobs/8148126550?pr=8695#step:6:35))

# User-Facing Changes
users can now access a `clip` to copy the output of any pipeline to the
system clipboard, on any system

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

# After Submitting
```
$nothing
```
2023-04-05 13:19:42 -05:00
Antoine Stevan
caf1432dc7
refactor the ansi help page (#8713)
# Description
i've always found the `ansi --help` extra usage hard to read and
understand...
i decided to give it a shot today, so here is what i came up 😋 

- make the extra usage structured with `nushell` tables
- make the examples clearer with variables and comments

one change that might appear strange is the following last two commits
```diff
diff --git a/crates/nu-command/src/platform/ansi/ansi_.rs b/crates/nu-command/src/platform/ansi/ansi_.rs
index 4746d27fa..ba3e597c4 100644
--- a/crates/nu-command/src/platform/ansi/ansi_.rs
+++ b/crates/nu-command/src/platform/ansi/ansi_.rs
@@ -507,10 +507,7 @@ impl Command for AnsiCommand {
 
     fn signature(&self) -> Signature {
         Signature::build("ansi")
-            .input_output_types(vec![
-                (Type::Nothing, Type::String),
-                (Type::List(Box::new(Type::String)), Type::String),
-            ])
+            .input_output_types(vec![(Type::Nothing, Type::String)])
             .optional(
                 "code",
                 SyntaxShape::Any,
```
`ansi` is never used on `list` inputs, as can be seen in the `Ansi.run`
function: `_input: PipelineData` is never used.
this broke the tests (see [this
action](https://github.com/nushell/nushell/actions/runs/4589552235/jobs/8104520078#step:4:1392))
for no real reason...

# User-Facing Changes
hopefully an easier to read `help ansi` page.

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

# 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-05 13:16:36 -05:00
Jelle Besseling
65c90d5b45
Add ppid to ps command (#8750)
# Description

Adds the `ppid` field that's available on all supported platforms to the
`ps` command. This would be useful in my scripts.

# User-Facing Changes

- ps output now contains an extra column

# Tests + Formatting

Not sure if I need to add a test for this

# After Submitting

Update https://www.nushell.sh/book/quick_tour.html#quick-tour to show
the new table
2023-04-05 13:12:01 -05:00
goldfish
71b4949843
Change default config to display failed LAST_EXIT_CODE (#8735)
# Description

fixed #8655 
Change default nushell configuration file `default_env.nu` to display
LAST_EXIT_CODE in the prompt. For this change, users can quickly know
that a previous command failed.

# User-Facing Changes

This change affects only users who use the default configuration.
When a command fails, the exit code is displayed in the prompt like
these figures.
* before

![image](https://user-images.githubusercontent.com/37319612/229782830-45bc6b0d-75e4-459f-ae1d-46877f740239.png)
* after

![image](https://user-images.githubusercontent.com/37319612/229784089-e68b5d14-499b-4448-b764-e6b30ca64714.png)


# Tests + Formatting

When I ran tests, `test.nu` failed with the following error.
The error also occurs in the master branch, so it's probably unrelated
to these changes.
Do I need to address it?

* `cargo fmt --all -- --check`: passed
* `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect`: passed
* `cargo test --workspace`: passed
* `cargo run -- crates/nu-utils/standard_library/tests.nu`: ~failed~
passed
```
~/oss_dev/nushell> cargo run -- crates/nu-utils/standard_library/tests.nu
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/nu crates/nu-utils/standard_library/tests.nu`
Error: nu:🐚:external_command

  × External command failed
    ╭─[/home/hiroki/oss_dev/nushell/crates/nu-utils/standard_library/tests.nu:73:1]
 73 │         | upsert test {|module|
 74 │             nu -c $'use ($module.file) *; $nu.scope.commands | select name module_name | to nuon'
    ·             ─┬
    ·              ╰── did you mean 'du'?
 75 │             | from nuon
    ╰────
  help: No such file or directory (os error 2)
  ```

# After Submitting

nothing
2023-04-05 13:06:24 -05:00
WindSoilder
54a18991ab
Loops return external stream when external command failed. (#8646) 2023-04-05 20:38:04 +03:00
K3rnelP4n1k
1fcb98289a
Add section on removing ANSI sequences with find command (#8519)
Co-authored-by: Phreno <phreno@pop-os.localdomain>
2023-04-05 20:26:20 +03:00
Thomas Coratger
01e5ba01f6
Correction bug multiple dots mkdir and touch (#8486) 2023-04-05 20:22:56 +03:00
StevenDoesStuffs
1134c2f16c
Allow NU_LIBS_DIR and friends to be const (#8538) 2023-04-05 19:56:48 +03:00
Stefan Holderbach
d18cf19a3f
Bump to 0.78.1 development version (#8741)
# Description

either just development or hotfix
2023-04-05 13:36:10 +12:00
Stefan Holderbach
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
Stefan Holderbach
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
Stefan Holderbach
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
Stefan Holderbach
68d98fcf24
Remove unused atty dep in nu-table (#8716)
# Description

nfm
2023-04-02 20:30:36 +02:00
mike
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
Harshal Chaudhari
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
Stefan Holderbach
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
Antoine Stevan
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
Lukáš Veškrna
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
Reilly Wood
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
Kelvin Samuel
eaea00366b
Fix a bug with us not outputting as µs with the into duration command (#8691)
# Description

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

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

After this change, it now outputs the correct symbol:

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

# User-Facing Changes

User will now see correct unit when converting into microseconds.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-utils/standard_library/tests.nu` to run the
tests for the standard library

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-31 16:01:48 -05:00
Darren Schroeder
0788fe5e72
fully deprecate str collect (#8680)
# Description

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

# User-Facing Changes

No more `str collect`

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-utils/standard_library/tests.nu` to run the
tests for the standard library

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-31 13:23:22 -05:00
Stefan Holderbach
3bf5999ef4
Remove proptests for nuon writing/parsing (#8688)
# Description

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


# User-Facing Changes

none

# Tests + Formatting

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

I accidentally noticed that your fix tricks wrapping a bit.


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


It must address it.

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

---------

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

Adds two more patterns when working with lists:

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

# User-Facing Changes

Adds more capability to list pattern matching.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-utils/standard_library/tests.nu` to run the
tests for the standard library

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-31 11:08:53 +13:00
Darren Schroeder
09276db2a5
add a threads parameter to par_each (#8679)
# Description

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


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

closes #4407

# User-Facing Changes

New parameter

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-utils/standard_library/tests.nu` to run the
tests for the standard library

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-30 16:39:40 -05:00
Kelvin Samuel
bc6948dc89
Allow parsing of mu (µ) character for durations (issue #8614) (#8647)
# Description
This is to resolve the issue
[8614](https://github.com/nushell/nushell/issues/8614).
It allows the parsing of the mu (µ) character for durations, so you can
type `10µs`, and it correctly outputs, whilst maintaining the current
`us` parsing as well.

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


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

# User-Facing Changes

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

# Tests + Formatting

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

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.

---------

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

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

Closes #8671
Closes #8674

# User-Facing Changes

No more panic

# Tests + Formatting

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

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-30 09:54:57 -05:00
Benjamin Lee
53beba7acc
Support passing an empty list to sort, uniq, sort-by, and uniq-by (issue #5957) (#8669)
# Description

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

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

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

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

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

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

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

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

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

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

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

# User-Facing Changes

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

# After Submitting

> If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.

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

---------

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

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

This was an easy bug to miss, because `ureq::send_json()` accepts any
`impl serde::Serialize`. I've added a test to prevent regression.
2023-03-29 11:55:51 -07:00
Darren Schroeder
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
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