Commit Graph

1829 Commits

Author SHA1 Message Date
JT
e22b70acff
Remove the 'env' command, as we have the variable (#8185)
# Description

Removes the `env` command, as the `$env` is generally a much better
experience.

# User-Facing Changes

Breaking change: Removes `env`.

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-01 21:20:00 +13:00
Jérémy Audiger
a5c604c283
Uniformize usage() and extra_usage() message ending for commands helper. (#8268)
# Description

Working on uniformizing the ending messages regarding methods usage()
and extra_usage(). This is related to the issue
https://github.com/nushell/nushell/issues/5066 after discussing it with
@jntrnr

# User-Facing Changes

None.

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-28 21:33:02 -08:00
Ryan Devenney
644164fab3
math floor and ceil round to int rather than float #8258 (#8269)
# Description

#8258 

Math floor and ceil return int types rather than floats.

# User-Facing Changes

Before:
```
/home/rdevenney/projects/open_source/nushell〉[(3.14 | math ceil | describe), 
(3.14 | math floor | describe), 
(3 | math ceil | describe), 
(3 | math floor | describe)]
╭───┬───────╮
│ 0 │ float │
│ 1 │ float │
│ 2 │ int   │
│ 3 │ int   │
╰───┴───────╯

```

After:
```
/home/rdevenney/projects/open_source/nushell〉[(3.14 | math ceil | describe), 
(3.14 | math floor | describe), 
(3 | math ceil | describe), 
(3 | math floor | describe)]
╭───┬─────╮
│ 0 │ int │
│ 1 │ int │
│ 2 │ int │
│ 3 │ int │
╰───┴─────╯

```

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-28 21:28:16 -08:00
Jérémy Audiger
50f1e33965
Fix insecure + max-time arguments for HTTP commands. (#8266)
# Description

Follow up of https://github.com/nushell/nushell/pull/8255

Sorry about the max-time argument, I didn't pay attention to the
copy-paste. Regarding the insecure argument, the problem was before I
began to work on the refacto. My mistake was to not have tested this
argument.

# User-Facing Changes

None.

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-28 14:33:28 -06:00
alesito85
ffc3727a1e
Fixes insecure and timeout flags (#8255)
# Description

Fixes #8098 by properly parsing `insecure` flag and also fixes the
`timeout` flag, which is described as `max-time` (from curl?).

# User-Facing Changes

The only change is that the flags now work.

# Tests + Formatting

Everything passes.

# Screenshots

Before

![image](https://user-images.githubusercontent.com/4399118/221845043-6dfba69d-daea-49a7-b55c-7ee628551b1c.png)

After


![image](https://user-images.githubusercontent.com/4399118/221845382-0111cbe9-4ba6-4de1-9e2a-655efbc65a26.png)
2023-02-28 06:48:15 -06:00
Michael Angerman
f8d2bff283
cratification: Example support (#8231)
# Description

When the crate nu_cmd_lang crate was created last week example_test.rs
was copied over from nu_command
to nu_cmd_lang. By doing this there was a set of methods in
example_test.rs that existed in both crates...

This PR removes the redundancy by moving all of those duplicated methods
into the crate nu_test_support in a newly created file called
example_support.rs


_(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

# 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-02-27 13:58:56 -08:00
baehyunsol
ba5258d716
remove unnecessary rows in into datetime --list (#8243)
Below is the result of `into datetime --list | uniq -d`.

```
╭───┬───────────────┬─────────┬───────────────────────────────────────╮
│ # │ Specification │ Example │              Description              │
├───┼───────────────┼─────────┼───────────────────────────────────────┤
│ 0 │ %Y            │ 2023    │ The full proleptic Gregorian year,    │
│   │               │         │ zero-padded to 4 digits.              │
│ 1 │ %C            │ 20      │ The proleptic Gregorian year divided  │
│   │               │         │ by 100, zero-padded to 2 digits.      │
╰───┴───────────────┴─────────┴───────────────────────────────────────╯
```

It's supposed to be an empty table, but it has two rows. I removed the
duplicates.

# User-Facing Changes

`into datetime --list` will print out a correct table.
2023-02-27 11:21:52 +01:00
Jakub Žádník
a3f817d71b
Re-implement aliases (#8123)
# Description

This PR adds an alternative alias implementation. Old aliases still work
but you need to use `old-alias` instead of `alias`.

Instead of replacing spans in the original code and re-parsing, which
proved to be extremely error-prone and a constant source of panics, the
new implementation creates a new command that references the old
command. Consider the new alias defined as `alias ll = ls -l`. The
parser creates a new command called `ll` and remembers that it is
actually a `ls` command called with the `-l` flag. Then, when the parser
sees the `ll` command, it will translate it to `ls -l` and passes to it
any parameters that were passed to the call to `ll`. It works quite
similar to how known externals defined with `extern` are implemented.

The new alias implementation should work the same way as the old
aliases, including exporting from modules, referencing both known and
unknown externals. It seems to preserve custom completions and pipeline
metadata. It is quite robust in most cases but there are some rough
edges (see later).

Fixes https://github.com/nushell/nushell/issues/7648,
https://github.com/nushell/nushell/issues/8026,
https://github.com/nushell/nushell/issues/7512,
https://github.com/nushell/nushell/issues/5780,
https://github.com/nushell/nushell/issues/7754

No effect: https://github.com/nushell/nushell/issues/8122 (we might
revisit the completions code after this PR)

Should use custom command instead:
https://github.com/nushell/nushell/issues/6048

# User-Facing Changes

Since aliases are now basically commands, it has some new implications:

1. `alias spam = "spam"` (requires command call)
	* **workaround**: use `alias spam = echo "spam"`
2. `def foo [] { 'foo' }; alias foo = ls -l` (foo defined more than
once)
* **workaround**: use different name (commands also have this
limitation)
4. `alias ls = (ls | sort-by type name -i)`
* **workaround**: Use custom command. _The common issue with this is
that it is currently not easy to pass flags through custom commands and
command referencing itself will lead to stack overflow. Both of these
issues are meant to be addressed._
5. TODO: Help messages, `which` command, `$nu.scope.aliases`, etc.
* Should we treat the aliases as commands or should they be separated
from regular commands?
6. Needs better error message and syntax highlight for recursed alias
(`alias f = f`)
7. Can't create alias with the same name as existing command (`alias ls
= ls -a`)
	* Might be possible to add support for it (not 100% sure)
8. Standalone `alias` doesn't list aliases anymore
9. Can't alias parser keywords (e.g., stuff like `alias ou = overlay
use` won't work)
	* TODO: Needs a better error message when attempting to do so

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-27 20:44:05 +13:00
David Matos
96e3a3de68
Error out when Select gets same row (#8200)
# Description
Fixes #8145, by disallowing any rows that are duplicated.

```
❯ ls | select 0 0
Error: 
  × Select only allows unique rows
   ╭─[entry #1:1:1]
 1 │ ls | select 0 0
   ·               ┬
   ·               ╰── duplicated row
   ╰────

```

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

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

# After Submitting

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

---------

Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-26 18:14:15 -08:00
Reilly Wood
2aa5c2c41f
Simplify str trim command (#8205)
### What?

This change removes 3 flags (`--all`, `--both`, and `--format`) from
`str trim`. This is a net reduction of ~450 LoC and `str trim` no longer
depends on `fancy_regex`.

### Why?

I found these flags to be quite confusing when reviewing `str trim`
earlier today:

1. `--all` removes characters even if they're in the centre of the the
string.
- This is arguably not "trimming"! In all programming languages I'm
familiar with, trimming only affects the start and end of a string.
    - If someone needs to do this, `str replace` is more natural IMO
2. `--both` trims from the left and right
- Confusing and unnecessary given that this is also the default
behaviour
3. `--format` replaces multiple spaces with a single space, even in the
centre of the string
- Again, I don't think this falls under the scope of "trimming". IMO
`str replace` is a more natural fit

I believe that `str trim` is simpler and easier to understand after this
change.

### Before

```
〉help str trim
Trim whitespace or specific character

Search terms: whitespace, strip, lstrip, rstrip

Usage:
  > str trim {flags} ...(rest)

Flags:
  -h, --help - Display the help message for this command
  -c, --char <String> - character to trim (default: whitespace)
  -l, --left - trims characters only from the beginning of the string
  -r, --right - trims characters only from the end of the string
  -a, --all - trims all characters from both sides of the string *and* in the middle
  -b, --both - trims all characters from left and right side of the string
  -f, --format - trims spaces replacing multiple characters with singles in the middle
```

### After

```
〉help str trim
Trim whitespace or specific character

Search terms: whitespace, strip, lstrip, rstrip

Usage:
  > str trim {flags} ...(rest)

Flags:
  -h, --help - Display the help message for this command
  -c, --char <String> - character to trim (default: whitespace)
  -l, --left - trims characters only from the beginning of the string
  -r, --right - trims characters only from the end of the string
```
2023-02-26 12:23:30 -08:00
Xoffio
4b3e3a37a3
Ctrl+c interruption - cp command (#8219)
# Description
if you try to copy a big file with `cp` you will noticed that you can't
interrupt the process. This pull request fix that.
This was discuss here
https://github.com/nushell/nushell/pull/8012#issuecomment-1427313054

# User-Facing Changes
None

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

---------

Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-26 12:18:20 -08:00
Doru
c602b5a1e8
special-case ExternalStream in bytes starts-with (#8203)
# Description
`bytes starts-with` converts the input into a `Value` before running
.starts_with to find if the binary matches. This has two side effects:
it makes the code simpler, only dealing in whole values, and simplifying
a lot of input pipeline handling and value transforming it would
otherwise have to do. _Especially_ in the presence of a cell path to
drill into. It also makes buffers the entire input into memory, which
can take up a lot of memory when dealing with large files, especially if
you only want to check the first few bytes (like for a magic number).

This PR adds a special branch on PipelineData::ExternalStream with a
streaming version of starts_with.

# User-Facing Changes
Opening large files and running bytes starts-with on them will not take
a long time.

# 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

# Drawbacks
Streaming checking is more complicated, and there may be bugs. I tested
it with multiple chunks with string data and binary data and it seems to
work alright up to 8k and over bytes, though.

The existing `operate` method still exists because the way it handles
cell paths and values is complicated. This causes some "code
duplication", or at least some intent duplication, between the value
code and the streaming code. This might be worthwhile considering the
performance gains (approaching infinity on larger inputs).

Another thing to consider is that my ExternalStream branch considers
string data as valid input. The operate branch only parses Binary
values, so it would fail. `open` is kind of unpredictable on whether it
returns string data or binary data, even when passing `--raw`. I think
this can be a problem but not really one I'm trying to tackle in this
PR, so, it's worth considering.
2023-02-26 15:17:44 +01:00
pwygab
9bbb9711e4
allow for arguments in EDITOR and VISUAL env vars (#8105)
# Description

Fixes #8051.

# User-Facing Changes

You can now put command arguments into the EDITOR and VISUAL config /
env variables.

# Tests + Formatting

I don't know how to write tests for this. However, I set $env.EDITOR to
"nvim -R" and it seemed to work.

# 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-02-26 06:56:38 -06:00
Antoine Stevan
680405e527
REFACTOR: format some example commands (#8223)
hellord 👋 😋 

# Description
this PR fixes the format of a few single-line examples and the
indentation of some multi-line examples
- single-line example formatting
  - `compact`
- multi-line example indentation
  - `update cells`
  - `error make
  - `split-by`

# User-Facing Changes
- `compact`

from
```bash
Examples:
  Filter out all records where 'Hello' is null (returns nothing)
  > [["Hello" "World"]; [null 3]]| compact Hello

  Filter out all records where 'World' is null (Returns the table)
  > [["Hello" "World"]; [null 3]]| compact World
```
to
```bash
Examples:
  Filter out all records where 'Hello' is null (returns nothing)
  > [["Hello" "World"]; [null 3]] | compact Hello

  Filter out all records where 'World' is null (Returns the table)
  > [["Hello" "World"]; [null 3]] | compact World
```
- `update cells`

from
```bash
Examples:
  Update the zero value cells to empty strings.
  > [
    ["2021-04-16", "2021-06-10", "2021-09-18", "2021-10-15", "2021-11-16", "2021-11-17", "2021-11-18"];
    [          37,            0,            0,            0,           37,            0,            0]
] | update cells { |value|
      if $value == 0 {
        ""
      } else {
        $value
      }
}

  Update the zero value cells to empty strings in 2 last columns.
  > [
    ["2021-04-16", "2021-06-10", "2021-09-18", "2021-10-15", "2021-11-16", "2021-11-17", "2021-11-18"];
    [          37,            0,            0,            0,           37,            0,            0]
] | update cells -c ["2021-11-18", "2021-11-17"] { |value|
        if $value == 0 {
          ""
        } else {
          $value
        }
}
```
to
```bash
Examples:
  Update the zero value cells to empty strings.
  > [
        ["2021-04-16", "2021-06-10", "2021-09-18", "2021-10-15", "2021-11-16", "2021-11-17", "2021-11-18"];
        [          37,            0,            0,            0,           37,            0,            0]
    ] | update cells { |value|
          if $value == 0 {
            ""
          } else {
            $value
          }
    }

  Update the zero value cells to empty strings in 2 last columns.
  > [
        ["2021-04-16", "2021-06-10", "2021-09-18", "2021-10-15", "2021-11-16", "2021-11-17", "2021-11-18"];
        [          37,            0,            0,            0,           37,            0,            0]
    ] | update cells -c ["2021-11-18", "2021-11-17"] { |value|
            if $value == 0 {
              ""
            } else {
              $value
            }
    }
```
- `split-by`

from
```bash
Examples:
  split items by column named "lang"
  >
                {
                    '2019': [
                      { name: 'andres', lang: 'rb', year: '2019' },
                      { name: 'jt', lang: 'rs', year: '2019' }
                    ],
                    '2021': [
                      { name: 'storm', lang: 'rs', 'year': '2021' }
                    ]
                } | split-by lang
```
to
```bash
Examples:
  split items by column named "lang"
  > {
        '2019': [
          { name: 'andres', lang: 'rb', year: '2019' },
          { name: 'jt', lang: 'rs', year: '2019' }
        ],
        '2021': [
          { name: 'storm', lang: 'rs', 'year': '2021' }
        ]
    } | split-by lang
```
- `error make`

from
```bash
Examples:
  Create a custom error for a custom command
  > def foo [x] {
      let span = (metadata $x).span;
      error make {msg: "this is fishy", label: {text: "fish right here", start: $span.start, end: $span.end } }
    }

  Create a simple custom error for a custom command
  > def foo [x] {
      error make {msg: "this is fishy"}
    }
```
to
```bash
Examples:
  Create a custom error for a custom command
  > def foo [x] {
        let span = (metadata $x).span;
        error make {msg: "this is fishy", label: {text: "fish right here", start: $span.start, end: $span.end } }
    }

  Create a simple custom error for a custom command
  > def foo [x] {
        error make {msg: "this is fishy"}
    }
```

# Tests + Formatting
no tests have been changed => this is a pure formatting PR

- ✔️ `cargo fmt --all`
- ✔️ `cargo clippy --workspace -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect`
- ✔️ `cargo test --workspace`

# After Submitting
need to change the book? 🤔
2023-02-26 06:50:05 -06:00
pwygab
44595b44c5
add case insensitive switch to starts-with and ends-with (#8221)
# Description

Fixes #8202

# User-Facing Changes
`str starts-with` and `str ends-with` now has a `-i` switch.

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-26 06:48:09 -06:00
Stefan Holderbach
836a56b347
Revert range expansion for to nuon (#8210)
# Description

The code to generate the nuon format supports writing range literals,
which obviates the need to expand the range as added in #8047

# User-Facing Changes

`to nuon` will still output ranges as literals

# Tests + Formatting

- Add test for `to nuon` range output
- Add `from nuon` test for range
2023-02-25 18:29:30 +01:00
baehyunsol
b1e7bb899a
Update trim_.rs (#8201)
fix typo in help messages


# 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

# After Submitting

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

---------

Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-24 22:18:20 -08:00
David Matos
42f0b55de0
allow Range to expand to array-like when converting to json (#8047)
# Description
Fixes #8002, which expands ranges `1..3` to expand to array-like when
saving and converting to json. Now,

```
> 1..3 | save foo.json
# foo.json
[
    1,
    2,
    3
]


> 1..3 | to json
[
    1,
    2,
    3
]
```
# 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:

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 15:31:33 -06:00
Henry Jetmundsen
253b223e65
pipe binary data to external commands (#8058)
Fixes #7615 

# Description

When calling external commands, we create a table from the pipeline data
to handle external commands expecting paginated input. When a binary
value is made into a table, we convert the vector of bytes representing
the binary bytes into a pretty formatted string. This results in the
pretty formatted string being sent to external commands instead of the
actual binary bytes. By checking whether the stdout of the call is being
redirected, we can decide whether to send the raw binary bytes or the
pretty formatted output when creating a table command.

# User-Facing Changes

When passing binary values to external commands, the external command
will receive the actual bytes instead of the pretty printed string. Use
cases that don't involve piping a binary value into an external command
are unchanged.


![new_behavior](https://user-images.githubusercontent.com/32406734/218349172-24cd12f2-d563-4957-bdf1-6aa804b174b2.png)

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 21:39:52 +01:00
Alex Tremblay
4dd9d0d46b
move hash md5 and hash sha256 commands to the hash category (#8196)
# Description

For auto-generated documentation, move the `hash _` commands into the
Hash category

# User-Facing Changes

Apart from documentation, none.

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 11:53:25 -06:00
Darren Schroeder
fd1ac5106d
fix ansi example so it is tested (#8192)
# Description

This PR just fixes one `ansi` test so that the test runner will accept
it and test the scenario. No other changes.

# User-Facing Changes

_(List of all changes that impact the user experience here. This helps
us keep track of breaking changes.)_

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 11:52:51 -06:00
Michael Angerman
585e104608
Cratification: Break out nu_cmd_lang into a separate crate (#8181)
# Description

This breaks out the core_commands into a separate crate called
nu_cmd_lang

_(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

# 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-02-24 09:54:42 -06:00
Jérémy Audiger
83087e0f9d
HTTP HEAD / PATCH / PUT / DELETE commands (#8144)
# Description

Based on https://github.com/nushell/nushell/pull/8135.

Add the remaining HTTP commands:

- Head
- Patch
- Put
- Delete

It should finally resolve the issue
https://github.com/nushell/nushell/issues/2741

# User-Facing Changes

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-23 17:52:12 -06:00
WindSoilder
0e86ba4b63
Dependency update: update notify version to v5 (#8114)
# Description

Relative: #8060

While investigating, I found we need to update notify, which is a good
step to remove some duplicate dependencies.

As title, here are some goods and bads after updating:

## Good
keep dependency up to date, and remove duplidate dependency(cfg-if,
winapi) in Cargo.lock.

## Bad
Introduce some breaking changes:
After updating to notify v5, I found that we have to remove `Rename`
events.

But I've testing under notify v4, and it doesn't work good if we running
the following command on MacOS:
```
touch a
mv a b
```
It fires file create event, but no file rename event. So `rename` event
is not really reliable, so I think it's ok for us to remove `Rename`
events.

The reason to remove `--debounce-ms` flag:
It's not provided by defualt file watcher, we can use
[PollWatcher](https://docs.rs/notify/latest/notify/poll/struct.PollWatcher.html),
but it scans filesystem, which is really expensive. So I just remove the
flag.

# User-Facing Changes

1. `--debounce-ms` flag is removed
2. no longer watch `Rename` event.

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 13:35:09 -08:00
Xoffio
fc23c6721a
cp progress bar implementation (#8012)
# NOTE
Clean duplicate of #7825
Sorry about all the mess guys... I got confuse with GitHub and and ended
up mankind that mess.
This the same code I just cleaned the commits.

# Description
Progress bar implementation for the `cp` command. Now if the flag `-p`
or `--progress` is set, then the user will be able to see the progress
of the file or files being copy


![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg)

![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg)

# User-Facing Changes
A new flag (`--progress` `-p`) was added to the `cp` command 
Examples:
```nu
cp -p test_file.txt test_folder_1\
cp -r -p test_folder\* test_folder_1\
cp -r -p -i test_folder\* test_folder_1\
```

## Notes 
- The progress bar uses `std::io::{Read, Write}` instead of
`std::fs::copy` to get the progress. that means that when the progress
bar is used the copy process might be a bit slower.
- Progress bar for symbolic links TBD: Since symbolic links are usually
very light I think is not worth it to duplicate the function
`copy_symlink` just to add a progress bar that will be so fast to the
point is not needed, but.. for consistency purposes we might need to
added it, In that case I would have to pass the variable `progress` by
parameter (to not duplicate code unnecessary). If I do that i would have
to pass the `progress` var to every function to respect `copy_impl: impl
Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p

---------

Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 11:57:38 -08:00
Maxim Zhiburt
8deecc0137
table --collapse dont do truncation return message instead (#8172)
Reverts #8042

I've just noticed that #8042 was merged, but I didn't addressed your
@fdncred last comment.
This PR reverts #8042 and returns a message in cases where we need
truncation/wrapping.


157b7e0b60/crates/nu-command/tests/commands/table.rs (L234-L240)

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-02-22 18:35:45 +00:00
WindSoilder
c7966e81c2
check external failed in let assignment (#8164)
# Description

Fixes: #8136

# User-Facing Changes

The following command

```
let VAR = ^cat non-existing-file; echo "failed"
```
will no longer output `failed` 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` 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: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 17:35:09 +00:00
Ryan Devenney
2659c359e9
interrupt input command with Ctrl + C (#8159)
# Description

GH Issue: [#8074](https://github.com/nushell/nushell/issues/8074)

Adding SIGINT Ctrl + C functionality to *most* of the `input` command.
`input` with the flags `--suppress-output` and `--bytes-until` are
executed in raw mode which allows a ^C signal to be caught as it's
input, but an "optionless" call of `input` is using a standard
`read_line()` method that takes a ^C input and clears the buffer of any
data collected before the ^C. I'm more than happy to alter the
"optionless" call but putting it in raw mode hides the user input, so at
the moment that's unchanged.

# User-Facing Changes

Now ^C anywhere in the stdin stream will cause the command to SIGINT (as
long as the command isn't optionless), rather than being read in as part
of the input.
```
/home/rdevenney/projects/open_source/nushell〉input --suppress-output
Error: nu:🐚:io_error (link)

  × I/O error
  help: SIGINT
```

```
/home/rdevenney/projects/open_source/nushell〉input --bytes-until "a"
Error: nu:🐚:io_error (link)

  × I/O error
  help: SIGINT

```

As mentioned above, the default input behavior is the same.

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 17:19:19 +00:00
Artemiy
e389e51b2b
Display empty records and lists (#7925)
# Description

Fix some issues related to #7444 
1. Empty lists and records are now displayed as a small notice in a box:

![image](https://user-images.githubusercontent.com/17511668/215832023-3f8d743a-2899-416f-9109-7876ad2bbedf.png)

![image](https://user-images.githubusercontent.com/17511668/215832273-c737b8a4-af33-4c16-8dd3-bd4f0fd19b5a.png)
2. Empty records are now correctly displayed if inside of another record
list or table:

![image](https://user-images.githubusercontent.com/17511668/215832597-00f0cebc-a3b6-4ce8-8373-a9340d4c7020.png)

![image](https://user-images.githubusercontent.com/17511668/215832540-ab0e2a14-b8f6-4f47-976c-42003b622ef6.png)
3. Fixed inconsistent coloring of empty list placeholder inside of
lists/tables:

![image](https://user-images.githubusercontent.com/17511668/215832924-813ffe17-e04e-4301-97c3-1bdbccf1825c.png)

![image](https://user-images.githubusercontent.com/17511668/215832963-4765c4cf-3036-4bcc-81e1-ced941fa47cb.png)


# User-Facing Changes

`table` command now displays empty records and lists like a table with
text and correctly displays empty records inside tables and lists.

New behavior of displaying empty lists and records can be disabled using
`table.show_empty` config option.

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 16:18:33 +00:00
Leon
150b0b6b86
Add select extra_usage explaining relationship to get (#8146)
# Description

See title.

Also changed some misleading wording in `reject`'s help.

# User-Facing Changes

See above.

# Tests + Formatting

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

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

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

# 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-02-22 13:00:16 +00:00
Jérémy Audiger
c4d1aa452d
Final rework for the HTTP commands (#8135)
# Description

Final rework for https://github.com/nushell/nushell/issues/2741, after
this one, we'll add for free HTTP PUT, PATCH, DELETE and HEAD.

# User-Facing Changes

We can now post data using HTTP GET. I add some examples in the output
of `http get --help` to demonstrate this new behavior.

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 12:56:11 +00:00
Leon
4482862a40
Fix one error message in into string (#8163)
# Description

Fixes the following message:
```
〉(ls).0 | into string
Error: nu:🐚:cant_convert (link)

  × Can't convert to record.
   ╭─[entry #4:1:1]
 1 │ (ls).0 | into string
   ·          ─────┬─────
   ·               ╰── can't convert string to record
   ╰────
  help: try using the `to nuon` command
```

# User-Facing Changes

See above.

# Tests + Formatting

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

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

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

# 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-02-22 09:05:19 +00:00
Hofer-Julian
101ed629a4
Update polars to 0.27.2 (#8154)
Mostly to get rid of https://github.com/pola-rs/polars/pull/6098/files

This currently breaks nushell's table formatting:

```
nu ❯  open-df forcing.arrow | first
could not mmap compressed IPC file, defaulting to normal read╭───┬──────────┬────┬────────┬──────────┬───────┬──────────┬──────┬──────────┬─────╮
│ # │   time   │ id │ demand │ drainage │ E_pot │ infiltra │  P   │ priority │ ... │
│   │          │    │        │          │       │ tion     │      │          │     │
├───┼──────────┼────┼────────┼──────────┼───────┼──────────┼──────┼──────────┼─────┤
│ 0 │ 4 years  │  1 │   0.00 │     0.02 │  0.00 │     0.00 │ 0.00 │     4.00 │ ... │
│   │ ago      │    │        │          │       │          │      │          │     │
╰───┴──────────┴────┴────────┴──────────┴───────┴──────────┴──────┴──────────┴─────╯
```

@visr
2023-02-21 23:32:28 +00:00
Antoine Stevan
e89866bedb
TEST: add the output to the new with-env example (#8148)
Related to #8119.
Should address the review comment by @sholderbach from #8119.


# Description

this PR adds the output to the new example for the `with-env` command
introduced by #8119.

```bash
with-env {X: "Y", W: "Z"} { [$env.X $env.W] }
```
should output
```bash
["Y", "Z"]
```
hence the proposition from @sholderbach, i.e.
```rust
Some(Value::list(
    vec![Value::test_string("Y"), Value::test_string("Z")],
    Span::test_data(),
))
```

# User-Facing Changes
_none_

# Tests + Formatting

not really a test, only the output value for the last `with-env` example

- ✔️ `cargo fmt --all`
- ✔️ `cargo clippy --workspace -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect`
- ✔️ `cargo test --workspace`

# After Submitting
_none_
2023-02-21 10:15:35 +00:00
Darren Schroeder
6ca62ef131
show more informaiton when there are toml errors (#8140)
# Description

While debugging #8139 I noticed that there was some error information
coming from the toml crate that we were not displaying. This would've
helped me to understand what was going on. So, this PR shows more
verbose errors when toml fails to parse.

### Before

```
cargo llvm-cov show-env | from toml 
Error: nu:🐚:cant_convert (link)

  × Can't convert to structured toml data.
   ╭─[entry #1:1:1]
 1 │ cargo llvm-cov show-env | from toml
   · ──┬──
   ·   ╰── can't convert string to structured toml data
   ╰────
```

### After

```
cargo llvm-cov show-env | from toml
Error: nu:🐚:cant_convert (link)

  × Can't convert to structured toml data.
   ╭─[entry #1:1:1]
 1 │ cargo llvm-cov show-env | from toml
   · ──┬──
   ·   ╰── can't convert string to structured toml data
   ╰────
  help: TOML parse error at line 2, column 24
          |
        2 | LLVM_PROFILE_FILE="C:\CarTar\nushell-%p-%m.profraw"
          |                        ^
        invalid escape sequence
        expected `b`, `f`, `n`, `r`, `t`, `u`, `U`, `\`, `"`
```

# User-Facing Changes

_(List of all changes that impact the user experience here. This helps
us keep track of breaking changes.)_

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-20 18:50:31 +00:00
Maxim Zhiburt
b9be416937
Add colors in table --collapse (#8120)
close #8110 

cc: @amtoine

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-02-20 12:59:33 +00:00
Bob Hyman
0a8c9b22b0
string | fill counts clusters, not graphemes; and doesn't count ANSI escape codes (#8134)
Enhancement of new `fill` command (#7846) to handle content including
ANSI escape codes for formatting or multi-code-point Unicode grapheme
clusters.
In both of these cases, the content is (many) bytes longer than its
visible length, and `fill` was counting the extra bytes so not adding
enough fill characters.

# Description

This script:
```rust
# the teacher emoji `\u{1F9D1}\u{200D}\u{1F3EB}` is 3 code points, but only 1 print position wide.
echo "This output should be 3 print positions wide, with leading and trailing `+`"
$"\u{1F9D1}\u{200D}\u{1F3EB}" | fill -c "+" -w 3 -a "c"

echo "This output should be 3 print positions wide, with leading and trailing `+`"
$"(ansi green)a(ansi reset)" | fill -c "+" -w 3 -a c
echo ""
```

Was producing this output:
```rust
This output should be 3 print positions wide, with leading and trailing `+`
🧑‍🏫

This output should be 3 print positions wide, with leading and trailing `+`
a
```

After this PR, it produces this output:
```rust
This output should be 3 print positions wide, with leading and trailing `+`
+🧑‍🏫+

This output should be 3 print positions wide, with leading and trailing `+`
+a+
```
# User-Facing Changes

Users may have to undo fixes they may have introduced to work around the
former behavior. I have one such in my prompt string that I can now
revert.

# Tests + Formatting

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

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

`fill` command not documented in the book, and it still talks about `str
lpad/rpad`. I'll fix.

Note added dependency on a new library `print-positions`, which is an
iterator that yields a complete print position (cluster + Ansi sequence)
per call. Should this be vendored?
2023-02-20 06:32:20 -06:00
Antoine Stevan
88e07b5ea4
DOCUMENTATION: add a new "key-value" example to with-env (#8119)
hello there 👋 😋 

when messing around with `with-env`, looking at the examples, i did not
understand that we could directly run `with-env` with a record as the
argument and not from the input of a pipe 😮

even though the last example, i.e. 
```bash
  Set by row(e.g. `open x.json` or `from json`)
  > '{"X":"Y","W":"Z"}'|from json|with-env $in { [$env.X $env.W] }
```
, is equivalent, just the record comes from the pipe, i thought adding
that explicite new example could be helpful 😌
 
# Description
looking at the single real change of this PR, i.e. 86ef34e90, you can
see i've simply added
```bash
  Set by key-value record
  > with-env {X: "Y", W: "Z"} { [$env.X $env.W] }
```
just before the example above

> **Note**
> i've also added spaces around the '|' in the last examples, from
> ```bash
>   > '{"X":"Y","W":"Z"}'|from json|with-env $in { [$env.X $env.W] }
> ```
> to
> ```bash
>   > '{"X":"Y","W":"Z"}' | from json | with-env $in { [$env.X $env.W] }
> ```
> hopefully making the pipeline a bit easier to read 👍

### hope you like that 😏 

# User-Facing Changes
a new example has been added to `with-env`

# Tests + Formatting
no tests have been added

# After Submitting
the change should not affect the website, i think

=> if i need to generate the associated `HTML` file on
https://github.com/nushell/nushell.github.io, please tell me 😋
2023-02-19 18:28:49 +00:00
Jérémy Audiger
66398fbf77
Factorize HTTP commands code (#8088)
# Description

In order to work on https://github.com/nushell/nushell/issues/2741, I'm
preparing the code.

# User-Facing Changes

Both commands do support the timeout option.

**But the timeout argument `-t, --timeout` has been migrated to `-m,
--max-time`**. I had to make a choice since there is another option
using the short command `t` which is "content-type".

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-17 23:10:29 +00:00
David Matos
1fd1a3a456
Support URLs in start command (#7799)
# Description
Fixes issue #7792 Fix basically by @kubouch , "stolen" by me :). Edit:
Added "proper" fix rather than the one liner
```
start Cargo.toml
// Opens in default editor 
```

```
start https://www.google.com [alternative_browser]
// Opens page in default browser or another browser if specified
```

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-16 13:33:25 +00:00
Darren Schroeder
cba3e100a0
fix rename when it is passed an empty column list to rename (#8086)
# Description

This PR fixes a bug that occurs if you pass `rename --column` and empty
list like `ls | rename -c []`.

## Before

```
> ls | rename -c []
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', crates\nu-command\src\filters\rename.rs:110:15
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

## After

```
> ls | rename -c []
Error: nu:🐚:type_mismatch (link)

  × Type mismatch.
   ╭─[entry #1:1:1]
 1 │ ls | rename -c []
   ·                ─┬
   ·                 ╰── The list cannot be empty and must contain only two values: the column's name and its replacement value
   ╰────
```

# User-Facing Changes

_(List of all changes that impact the user experience here. This helps
us keep track of breaking changes.)_

# Tests + Formatting

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

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

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

# 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-02-15 21:47:27 +00:00
Darren Schroeder
d5ce509e3a
move ast command to the debug group (#8077)
# Description

This PR tweaks how `ast` works a tiny bit by outputting values in stead
of eprintln!'s. It also moves the `ast` command into the folder with the
rest of the debug commands and changes the category to debug.

I started adding some tests but couldn't figure out a good way to do it
since every `ast` command contains spans that will be different on each
invocation.

# User-Facing Changes



# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-14 18:47:34 +00:00
Michael Angerman
2f10d19c98
remove spurious use from default_context.rs (#8073)
For some reason this "Use" in default_context.rs was in the code,
but it is not being "used" --- pun intended...
2023-02-13 20:14:20 +00:00
Darren Schroeder
4c787af26d
relocate debug commands (#8071)
# Description

Now that we've landed the debug commands we were working on, let's
relocate them to an easier place to find all of them. That's what this
PR does.

The only actual code change was changing the `timeit` command to a
`Category::Debug` command. The rest is just moving things around and
hooking them up.

# User-Facing Changes



# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-13 16:39:07 +00:00
WindSoilder
208ffdc1da
Move some from xxx commands to plugin (#7942)
# Description

From nushell 0.8 philosophy:
https://github.com/nushell/nushell.github.io/blob/main/contributor-book/philosophy_0_80.md#core-categories

> The following categories should be moved to plugins:
Uncommon format support

So this pr is trying to move following commands to plugin:
- [X] from eml
- [x] from ics
- [x] from ini
- [x] from vcf

And we can have a new plugin handles for these formatting, currently
it's implemented here:

https://github.com/WindSoilder/nu_plugin_format

The command usage should be the same to original command.

If it's ok, the plugin can support more formats like
[parquet](https://github.com/fdncred/nu_plugin_from_parquet), or [EDN
format](https://github.com/nushell/nushell/issues/6415), or something
else.

Just create a draft pr to show what's the blueprint looks like, and is
it a good direction to move forward?

# User-Facing Changes

_(List of all changes that impact the user experience here. This helps
us keep track of breaking changes.)_

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-13 12:42:08 +00:00
Ryan Devenney
072d2a919d
#8027 Hide implementation details in invalid cd call (#8049)
# Description

[GH issue](https://github.com/nushell/nushell/issues/8027)

The current error message for a cd command includes a Debug output of
the `io::Error` being returned from `canonicalize_with`, so it's been
replaced with a more user friendly and readable depiction of the error.

# User-Facing Changes

As described in the issue, I've changed the error message for a cd into
a directory that does not exist from:
```
/home/rdevenney/projects/open_source/nushell〉cd asdfasdf                                                                               02/11/2023 08:59:59 PM
Error: nu:🐚:directory_not_found (link)

 × Directory not found
   ╭─[entry #2:1:1]
 1 │ cd asdfasdf
   ·    ────┬───
   ·        ╰── directory not found
   ╰────
  help: IO Error: Os { code: 2, kind: NotFound, message: "No such file or directory" }
```
To:
```
/home/rdevenney/projects/open_source/nushell〉cd asdfasdf                                                                               02/11/2023 08:58:38 PM
Error: nu:🐚:directory_not_found (link)

  × Directory not found
   ╭─[entry #1:1:1]
 1 │ cd asdfasdf
   ·    ────┬───
   ·        ╰── directory not found
   ╰────
  help: IO Error: DirectoryNotFound
```
# 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: Reilly Wood <reilly.wood@icloud.com>
2023-02-13 02:24:48 +00:00
Maxim Zhiburt
ccbdc9f6d8
nu-table/ Fix table --expand issue when table with no header involved (#8045)
close #8029

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-02-12 23:28:42 +00:00
Jakub Žádník
b0775b3f1e
Fix hidden env vars not being hidden in closures (#8055)
# Description

This one fixes env not being hidden inside closure, reported in the
conversation under https://github.com/nushell/nushell/issues/6593

https://github.com/nushell/nushell/issues/6593
https://github.com/nushell/nushell/issues/7937 still persist. These
seems a bit more involved and might need hidden env tracking also in the
engine state... I'm not yet sure what's causing it.

Also re-enables some env-related tests and removes unused Value clone.

# User-Facing Changes

Just a bugfix

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-12 17:48:51 +00:00
Bob Hyman
2894668b3e
Improve error when regex rejects pattern. Resolution of #8037 (#8050)
# Description

Improve error when `str replace <pattern>` detects a problem with
<pattern>.

# User-Facing Changes

New "Incorrect value" error:
```
〉 'C:\Users\kubouch' | str replace 'C:\Users' 'foo'
Error: nu:🐚:incorrect_value (link)

  × Incorrect value.
   ╭─[entry #1:1:1]
 1 │  'C:\Users\kubouch' | str replace 'C:\Users' 'foo'
   ·                                   ─────┬────
   ·                                        ╰── Regex error: Parsing error at position 4: Invalid hex escape
   ╰────
```

We could fruitfully replace some of the current uses of
`ShellError::UnsupportedInput` with this error. 'Incorrect value' is
different from 'wrong type'

# Tests + Formatting

Don't forget to add tests that cover your changes.
* none added / changed.

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

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-02-12 13:25:40 +00:00
Darren Schroeder
9777d755d5
add benchmark to deprecated commands (#8046)
# Description

This PR adds a deprecated message to the `benchmark` command.
```
> benchmark
Error: nu:🐚:deprecated_command (link)

  × Deprecated command benchmark
   ╭─[entry #1:1:1]
 1 │ benchmark
   · ────┬────
   ·     ╰── 'benchmark' is deprecated. Please use 'timeit' instead.
   ╰────
```

# User-Facing Changes

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-11 21:39:55 +00:00