Commit Graph

601 Commits

Author SHA1 Message Date
Stefan Holderbach
7d6b23ee2f
Simplify rawstrings in tests (#10180)
Inspired by
https://rust-lang.github.io/rust-clippy/master/index.html#/needless_raw_string_hashes

Ran `cargo +stable clippy --workspace --all-targets`

Fixed manually as I ran into a false positive along the lines of:
https://github.com/rust-lang/rust-clippy/issues/11068

Also collapse one set of single line tests.

Work for #8670
2023-09-01 00:08:27 +02:00
Stefan Holderbach
faad6ca355
Remove dead tests depending on inc (#10179)
They relied on the `nu_plugin_inc` but where behind a feature flag that
isn't actually defined anywhere. These tests of `update` or `upsert`
shouldn't really depend on `inc` so I decided to remove them outright as
they haven't been used to exercise the commands under test.
2023-08-31 23:11:04 +02:00
J-Kappes
c77c1bd297
Tests: clean up unnecessary use of pipeline() (#10170)
As described in Issue #8670, removed `pipeline()` wherever its argument
contained no line breaks.

---------

Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
2023-08-31 23:10:29 +02:00
Matthias Q
93f20b406e
feat: allow from csv to accept 4 byte unicode separator chars (#10138)
- this PR should close #10132

# Description
* added a flag to `from csv --ascii` that replaces the given `separator
with the unicode separator x1f https://www.codetable.net/hex/1f (aka
Information Separator One)

# User-Facing Changes
New flags are available for `from csv` ( `--ascii` or short `-a`)

# Tests + Formatting
There are no tests at the moment. Code has been formatted.
- `cargo test --workspace` (breaks with a non related test on my
machine)
2023-08-31 18:55:39 +02:00
Michael Angerman
7d3312e96e
remove warnings in nu_command tests (#10145)
several warnings were appearing in nu_command tests when running just
the tests
in nu_command so I went ahead and removed the warnings...
2023-08-29 13:18:52 -07:00
Jakub Žádník
5ac5b90aed
Allow parse-time evaluation of calls, pipelines and subexpressions (#9499)
Co-authored-by: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
2023-08-26 16:41:29 +03:00
JT
1e3e034021
Spanned Value step 1: span all value cases (#10042)
# Description

This doesn't really do much that the user could see, but it helps get us
ready to do the steps of the refactor to split the span off of Value, so
that values can be spanless. This allows us to have top-level values
that can hold both a Value and a Span, without requiring that all values
have them.

We expect to see significant memory reduction by removing so many
unnecessary spans from values. For example, a table of 100,000 rows and
5 columns would have a savings of ~8megs in just spans that are almost
always duplicated.

# User-Facing Changes

Nothing yet

# 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-08-25 08:48:05 +12:00
Herobs
a785e64bc9
Fix 9156 endian consistency (#9873)
- fixed #9156

# Description
I'm trying to fix the problems mentioned in the issue. It's my first
attempt in Rust. Please let me know if there are any problems.

# User-Facing Changes
- The `--little-endian` option dropped, replaced with `--endian`.
- Add the `--compact` option to the `into binary` command.
- `into int` accepts binary input
2023-08-24 07:08:58 -05:00
Darren Schroeder
af82eeca72
remove --column from length command and remove record processing (#10091)
# Description

This PR removes `record` processing from the `length` command. It just
doesn't make sense to try and get the length of a record. This PR also
removes the `--column` parameter. If you want to list or count columns,
you could use `$table | columns` or `$table | columns | length`.

close #10074 

### Before

![image](https://github.com/nushell/nushell/assets/343840/83488316-3ec4-4c32-9583-00341a71f46f)

### After
Catches records two different ways now.
with the `input_output_types` checker

![image](https://github.com/nushell/nushell/assets/343840/ca67f8b6-359e-4933-ab4d-1b702f8d79cf)

and with additional logic in the command for cases like `echo`

![image](https://github.com/nushell/nushell/assets/343840/99064351-b208-4bd3-bab9-535f97cd7ad4)


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

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `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-08-23 16:03:26 -05:00
Jakub Žádník
fe2c498a81
Fix wrong path expansion in save (#10046) 2023-08-18 20:45:10 +03:00
Darren Schroeder
fe7122280d
allow int as a cellpath for select (#10048)
Description

This PR allows ints to be used as cell paths.

### Before
```nushell
❯ let index = 0
❯ locations | select $index
Error: nu:🐚:cant_convert

  × Can't convert to cell path.
   ╭─[entry #26:1:1]
 1 │ locations | select $index
   ·                    ───┬──
   ·                       ╰── can't convert int to cell path
   ╰────
```

### After
```nushell
❯ let index = 0
❯ locations | select $index
╭#┬───────location────────┬city_column┬state_column┬country_column┬lat_column┬lon_column╮
│0│http://ip-api.com/json/│city       │region      │countryCode   │lat       │lon       │
╰─┴───────────────────────┴───────────┴────────────┴──────────────┴──────────┴──────────╯
```
# 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-08-18 10:16:18 -05:00
Jakub Žádník
2e0fb7c1a6
Change str replace to match substring by default (#10038) 2023-08-18 00:18:16 +03:00
Eugene Diachkin
ec5b9b9f37
Make http -f display the request headers. Closes #9912 (#10022)
# Description
As described in https://github.com/nushell/nushell/issues/9912, the
`http` command could display the request headers with the `--full` flag,
which could help in debugging the requests. This PR adds such
functionality.

# User-Facing Changes
If `http get` or other `http` command which supports the `--full` flag
is invoked with the flag, it used to display the `headers` key which
contained an table of response headers. Now this key contains two nested
keys: `response` and `request`, each of them being a table of the
response and request headers accordingly.


![image](https://github.com/nushell/nushell/assets/24980/d3cfc4c3-6c27-4634-8552-2cdfbdfc7076)
2023-08-17 09:19:10 -05:00
Jakub Žádník
e88a51e930
Refactor scope commands (#10023) 2023-08-17 11:58:38 +03:00
Darren Schroeder
3ed45c7ba8
allow select to take a $variable with a list of columns (#9987)
# Description

This PR enables `select` to take a constructed list of columns as a
variable.

```nushell
> let cols = [name type];[[name type size]; [Cargo.toml toml 1kb] [Cargo.lock toml 2kb]] | select $cols
  ╭#┬───name───┬type╮
  │0│Cargo.toml│toml│
  │1│Cargo.lock│toml│
  ╰─┴──────────┴────╯
```
and rows
```nushell
> let rows = [0 2];[[name type size]; [Cargo.toml toml 1kb] [Cargo.lock toml 2kb] [file.json json 3kb]] | select $rows
  ╭#┬───name───┬type┬size╮
  │0│Cargo.toml│toml│1kb │
  │1│file.json │json│3kb │
  ╰─┴──────────┴────┴────╯
```

# 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-08-15 07:01:45 -05:00
Maxim Zhiburt
696b2cda4a
nu-table: Fix padding 0 width issues (#10011)
close #10001

cc: @fdncred @amtoine 

note: make sure you rebase/squash

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-08-14 19:07:34 -05:00
Stefan Holderbach
435348aa61
Rename misused "deprecation" to removal (#10000)
# Description
In the past we named the process of completely removing a command and
providing a basic error message pointing to the new alternative
"deprecation".

But this doesn't match the expectation of most users that have seen
deprecation _warnings_ that alert to either impending removal or
discouraged use after a stability promise.

# User-Facing Changes
Command category changed from `deprecated` to `removed`
2023-08-15 07:17:31 +12:00
Maxim Zhiburt
aa37572ddc
nu-table/ Add table.indent configuration (#9983)
Hi there.

Am I got it right?

ref: https://github.com/zhiburt/tabled/issues/358
cc: @fdncred

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-08-11 08:37:16 -05:00
Antoine Stevan
202dfdaee2
fix panic with lines on an error (#9967)
should close https://github.com/nushell/nushell/issues/9965

# Description
this PR implements the `todo!()` left in `lines`.

# User-Facing Changes
### before
```nushell
> open . | lines
thread 'main' panicked at 'not yet implemented', crates/nu-command/src/filters/lines.rs:248:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

### after
```nushell
> open . | lines
Error: nu:🐚:io_error

  × I/O error
  help: Is a directory (os error 21)
```

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

this PR adds the `lines_on_error` test to make sure this does not happen
again 😌

# After Submitting
2023-08-09 14:12:58 +02:00
Antoine Stevan
b964347895
add a test to make sure "nothing" shows up as "nothing" in help (#9941)
related to 
- https://github.com/nushell/nushell/pull/9935

# Description
this PR just adds a test to make sure type annotations in `def`s show as
`nothing` in the help pages of commands.

# User-Facing Changes

# Tests + Formatting
adds a new test `nothing_type_annotation`.

# After Submitting
2023-08-09 05:10:34 +12:00
panicbit
56ed1eb807
parse: collect external stream chunks before matching (#9950)
<!--
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
-->

# Description
This PR implements the workaround discussed in #9795, i.e. having
`parse` collect an external stream before operating on it with a regex.

- Should close #9795 

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
- `parse` will give the correct output for external streams
- increased memory and time overhead due to collecting the entire stream
(no short-circuiting)

# 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
> ```
-->
- formatting is checked
- clippy is happy
- no tests that weren't already broken fail
- added test case

# 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-08-08 06:48:13 -05:00
Michael Angerman
58f98a4260
Cratification: move some str case commands to nu-cmd-extra (#9926)
I am moving the following str case commands to nu-cmd-extra (as
discussed in the core team meeting the other day)

* camel-case
* kebab-case
* pascal-case
* screaming-snake-case
* snake-case
* title-case
2023-08-06 06:40:44 -07:00
panicbit
6b4d06d8a7
do not emit None mid-stream during parse (#9925)
<!--
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 #issue 

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.
-->
Currently `parse` acts like a `.filter` over an iterator, except that it
emits `None` for elements that can't be parsed. This causes consumers of
the adapted iterator to stop iterating too early. The correct behaviour
is to keep pulling the inner iterator until either the end of it is
reached or an element can be parsed.

- this PR should close #9906 

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
List streams won't be truncated anymore after the first parse failure.

# 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 -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
> ```
-->
- [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
  - 11 tests fail, but the same 11 tests fail on main as well
- [x] `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

# 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-08-06 06:17:03 -05:00
Maxim Zhiburt
7e096e61d7
Add an option to set header on border (style) (#9920)
fix #9796

Sorry that you've had the issues.
I've actually encountered them yesterday too (seems like they have
appeared after some refactoring in the middle) but was not able to fix
that rapid.

Created a bunch of tests.

cc: @fdncred 

Note:

This option will be certainly slower then a default ones. (could be
fixed but ... maybe later).
Maybe it shall be cited somewhere.

PS: Haven't tested on a wrapped/expanded tables.

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-08-04 13:50:47 -05:00
WindSoilder
14bf25da14
rename from date format to format date (#9902)
# Description
Closes: #9891
I also think it's good to keep command name consistency.

And moving `date format` to deprecated.

# User-Facing Changes
Running `date format` will lead to deprecate message:
```nushell
❯ "2021-10-22 20:00:12 +01:00" | date format
Error: nu:🐚:deprecated_command

  × Deprecated command date format
   ╭─[entry #28:1:1]
 1 │ "2021-10-22 20:00:12 +01:00" | date format
   ·                                ─────┬─────
   ·                                     ╰── 'date format' is deprecated. Please use 'format date' instead.
   ╰────
```
2023-08-04 06:06:00 +12:00
Darren Schroeder
ec4941c8ac
update format signature to allow record to be passed in (#9898)
# Description

This PR updates the signature of `format` to allow records to be passed
in.

Closes #9897 

### Before
```nushell
{name: Downloads} | format "{name}"

  × Command does not support record<name: string> input.
   ╭─[entry #12:1:1]
 1 │ {name: Downloads} | format "{name}"
   ·                       ───┬──
   ·                          ╰── command doesn't support record<name: string> input
   ╰────
```

### After
```nushell
{name: Downloads} | format "{name}"
Downloads
```

# 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-08-02 10:57:58 -05:00
mengsuenyan
28ed21864d
fixed the bug ~ | path type return empty string (#9853)
- this PR should close #9849 
- fixes #9849
2023-07-31 07:47:18 -05:00
jflics6460
154856066f
Accept records for http subcommand headers (-H) (#9771)
# Description

See also: #9743 
Before: 
`http <subcommand> -H` took a list in the form:

```nushell
[my-header-key-A my-header-value-A my-header-key-B my-header-value-B]
```

Now:
In addition to the old format, Records can be passed, For example,
```nushell
> let reqHeaders = {
    Cookie:  "acc=barfoo",
    User-Agent: "Mozilla/7.0 (Windows NT 33.0; Win64; x64) AppleWebKit/1038.90 (KHTML, like Gecko)"
}
> http get -H $reqHeaders https://example.com
```

is now equivalent to
```nushell
http get -H [Cookie "acc=barfoo" User-Agent "Mozilla/7.0 (Windows NT 33.0; Win64; x64) AppleWebKit/1038.90 (KHTML, like Gecko)"] https://example.com
```

# User-Facing Changes
No breaking changes, but Records can now also be passed to `http
<subcommand> -H`.

# Tests + Formatting
# After Submitting
2023-07-30 22:28:48 +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
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
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
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
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
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
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
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
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
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
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
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
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
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
mengsuenyan
026335fff0
Fix cp -u/mv -u when the dst doesn't exist (#9662)
Fixes #9655
2023-07-12 18:12:59 +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
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
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