Commit Graph

2141 Commits

Author SHA1 Message Date
Jakub Žádník
4b16406050
Add proptest regression (#8396)
# Description

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

# User-Facing Changes

None?

# Tests + Formatting

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

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

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

# After Submitting

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


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

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

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

---

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

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

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


</details>

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

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

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

# User-Facing Changes

Internal changes only

# Tests + Formatting

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

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-15 18:54:55 +13:00
Reilly Wood
57ce6a7c66
Fix ls behaviour when directory is empty (#8439)
Prior to this PR, `ls` would return `nothing` in an empty directory.
After this PR, it returns an empty `List`. This makes the behaviour of
`ls` more consistent and easier to reason about (IMO).

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

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

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

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

```

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

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

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

Either to be used in an emergency point release or to indicate
development builds in the `version` command
2023-03-14 23:26:08 +01:00
Stefan Holderbach
fd09609b44
Bump version to 0.77.0 (#8410) 2023-03-14 20:46:42 +02:00
Stefan Holderbach
c7583ecdb7
Pin to reedline 0.17 (#8441)
# Description

See release notes:

https://github.com/nushell/reedline/releases/tag/v0.17.0
2023-03-14 00:04:36 +01:00
Stefan Holderbach
4eec4a27c7
Pin to nu-ansi-term 0.47 (#8440)
# Description

Update reedline to a commit that uses the same version as we share types

# User-Facing Changes

(-)

# Tests + Formatting

Build check
2023-03-13 23:38:18 +01:00
BlacAmDK
86faf753bd
Fix SQLite table creation sql (#8430)
# Description

The "CREATE TABLE" statement in `into sqlite` does not add quotes to the
column names, reproduction steps are below:

```
/home/xxx〉[[name,y/n];[a,y]] | into sqlite test.db
Error: 
  × Failed to prepare SQLite statement
   ╭─[entry #1:1:1]
 1 │ [[name,y/n];[a,y]] | into sqlite test.db
   ·                                                       ───┬───
   ·                                                             ╰── near "/": syntax error in CREATE TABLE IF NOT EXISTS main (name TEXT,y/n TEXT) at offset 44
   ╰────
```

# User-Facing Changes

None

---------

Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-03-13 10:11:28 -07:00
Jakub Žádník
808e523adc
Disable alias recursion (#8397)
# Description

Prevents alias from aliasing itself. It allows a commonly requested
pattern similar to `alias ls = ls -l`.

One small issue is that the syntax highlighting is a bit off:

![alias_itself_no_color](https://user-images.githubusercontent.com/25571562/224545129-8a3ff535-347b-4a4e-b686-11493bb2a33b.png)

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

# User-Facing Changes

Shouldn't be 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` 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-13 06:16:26 +13:00
Stefan Holderbach
a52386e837
Box ShellError in Value::Error (#8375)
# Description

Our `ShellError` at the moment has a `std::mem::size_of<ShellError>` of
136 bytes (on AMD64). As a result `Value` directly storing the struct
also required 136 bytes (thanks to alignment requirements).

This change stores the `Value::Error` `ShellError` on the heap.

Pro:
- Value now needs just 80 bytes
- Should be 1 cacheline less (still at least 2 cachelines)

Con:
- More small heap allocations when dealing with `Value::Error`
  - More heap fragmentation
  - Potential for additional required memcopies

# Further code changes

Includes a small refactor of `try` due to a type mismatch in its large
match.

# User-Facing Changes

None for regular users.

Plugin authors may have to update their matches on `Value` if they use
`nu-protocol`

Needs benchmarking to see if there is a benefit in real world workloads.
**Update** small improvements in runtime for workloads with high volume
of values. Significant reduction in maximum resident set size, when many
values are held in memory.

# Tests + Formatting
2023-03-12 09:57:27 +01:00
Artemiy
a13946e3ef
New xml format (#7947)
# Description

Changes old `from xml` `to xml` data formats. See #7682 for reasoning
behind this change.
Output is now a series of records with `tag`, `attributes` and `content`
fields.

Old:

![image](https://user-images.githubusercontent.com/17511668/224508728-92d37c1f-ebac-4d5c-924d-bebd60f5cf85.png)
New:

![image](https://user-images.githubusercontent.com/17511668/224508753-a2de338a-ff2a-41e0-bbc1-ccc07a1d00ce.png)


# User-Facing Changes

New output/input format, better error handling for `from xml` and `to
xml` 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-03-12 12:35:42 +13:00
Jakub Žádník
af1ab39851
Allow aliasing parser keywords (#8250) 2023-03-10 23:20:31 +02:00
David Matos
ccd72fa64a
Error out when config.nu has no editor configured (#8282)
# Description
Fixes #8245. Instead of trying to use `nano` or `notepad` as defaults,
it errors out if finds that `buffer_editor` , $EDITOR, $VISUAL do not
exist.

If the PR is landed, Ill update the website as it means what its in
there is no longer correct.
```
❯ config nu
Error: 
  × No editor configured
   ╭─[entry #3:1:1]
 1 │ config nu
   · ────┬────
   ·     ╰── Please specify one via environment variables $EDITOR or $VISUAL
   ╰────
  help: Nushell's config file can be found with the command: $nu.config-path. For more help: (https://nushell.sh/book/configuration.html#configurations-with-built-in-commands)
  
  ``` 
# User-Facing Changes

# Tests + Formatting


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-03-09 08:07:20 -06:00
Reilly Wood
03e688ea7b
Revert to notify v4 (#8367)
This reverts https://github.com/nushell/nushell/pull/8114 which upgraded
to `notify` (a file watching crate used by the `watch` command) v5.

`notify` v5 has several breaking changes and it's much harder to use. It
no longer includes debouncing of file system events, which I think is
essential functionality for `watch`. @WindSoilder was going to try
writing our own debouncing functionality but I don't think he had time
to finish it.

@WindSoilder Is it OK if we revert this for the 0.77 release (March 14)?
We can try again for 0.78
2023-03-08 21:45:58 -08:00
Darren Schroeder
0df847da15
fixed an error message that popped up after landing (#8356)
# Description

This PR fixes an error message that popped up after landing a PR #8337.
I guess there were too many changes since the PR was submitted?

# User-Facing Changes

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

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-07 19:02:48 -06:00
Bob Hyman
2ad0fcb377
Fix 8244 -- store timestamps with nanosecond resolution (consistently) (#8337)
# Description

Fix for data ambiguity noted in #8244.

Basic change is to use nanosecond resolution for unix timestamps (stored
in type Int). Previously, a timestamp might have seconds, milliseconds
or nanoseconds, but it turned out there were overlaps in data ranges
between different resolutions, so there wasn't always a unique mapping
back to date/time.

Due to higher precision, the *range* of dates that timestamps can map to
is restricted. Unix timestamps with seconds resolution and 64 bit
storage can cover all dates from the Big Bang to eternity. Timestamps
with seconds resolution and 32 bit storage can only represent dates from
1901-12-13 through 2038-01-19. The nanoseconds resolution and 64 bit
storage used with this fix can represent dates from 1677-09-21T00:12:44
to 2262-04-11T23:47:16, something of a compromise.

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

## `<datetime> | into int`
Converts to nanosecond resolution
```rust
〉date now | into int
1678084730502126846
```
This is the number of non-leap nanoseconds after the unix epoch date:
1970-01-01T00:00:00+00:00.

Conversion fails for dates outside the supported range:
```rust
〉1492-10-12 | into int
Error: nu:🐚:incorrect_value

  × Incorrect value.
   ╭─[entry #51:1:1]
 1 │ 1492-10-12 | into int
   ·              ────┬───
   ·                  ╰── DateTime out of timestamp range 1677-09-21T00:12:43 and 2262-04-11T23:47:16
   ╰────


```

## `<int> | into datetime`
Can no longer fail or produce incorrect results for any 64-bit input:
```rust
〉0 | into datetime 
Thu, 01 Jan 1970 00:00:00 +0000 (53 years ago)
〉"7fffffffffffffff" | into int -r 16 | into datetime
Fri, 11 Apr 2262 23:47:16 +0000 (in 239 years)
〉("7fffffffffffffff" | into int -r 16) * -1 | into datetime
Tue, 21 Sep 1677 00:12:43 +0000 (345 years ago)
```

## `<date> | date to-record` and `<date> | date to-table`
Now both have a `nanosecond` field.  
```rust
〉"7fffffffffffffff" | into int -r 16 | into datetime | date to-record
╭────────────┬───────────╮
│ year       │ 2262      │
│ month      │ 4         │
│ day        │ 11        │
│ hour       │ 23        │
│ minute     │ 47        │
│ second     │ 16        │
│ nanosecond │ 854775807 │
│ timezone   │ +00:00    │
╰────────────┴───────────╯
〉"7fffffffffffffff" | into int -r 16 | into datetime | date to-table
╭───┬──────┬───────┬─────┬──────┬────────┬────────┬────────────┬──────────╮
│ # │ year │ month │ day │ hour │ minute │ second │ nanosecond │ timezone │
├───┼──────┼───────┼─────┼──────┼────────┼────────┼────────────┼──────────┤
│ 0 │ 2262 │     4 │  11 │   23 │     47 │     16 │  854775807 │ +00:00   │
╰───┴──────┴───────┴─────┴──────┴────────┴────────┴────────────┴──────────╯
```

This change was not mandated by the OP problem, but it is nice to be
able to see the nanosecond bits that were present in Nushell `date` type
all along.
# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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-07 17:02:15 -06:00
Antoine Stevan
f34034ae58
FIX: redirect to encode base64 as hash bash64 is deprecated (#8351)
# Description
i tried yesterday to `encode` with an invalid character set and this is
what i got
```bash
>_ {alg: "HS256", type: "JWT"} | to json -r | encode base64 --character-set invalid-character-set
Error:
  × value is not an accepted character set
   ╭─[entry #11:1:1]
 1 │ {alg: "HS256", type: "JWT"} | to json -r | encode base64 --character-set invalid-character-set
   ·                                                                          ──────────┬──────────
   ·                                                                                    ╰── invalid-character-set is not a valid character-set.
Please use `help hash base64` to see a list of valid character sets.
   ╰────
```

but `hash base64` is now a deprecated command, see `help hash base64`.

=> **this PR changes the error message to mention `help encode base64`,
where the list of valid character sets is, instead**

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

# Tests + Formatting
- 🟢 `cargo fmt --all`
- 🟢 `cargo clippy --workspace -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect`
- 🟢 `cargo test --workspace`

# After Submitting
```
$nothing
```
2023-03-07 20:04:54 +01:00
Reilly Wood
0e2167884d
Add SSL tests for http get (#8327)
This PR adds tests to confirm that:
1. `http get` does the right thing (bail) when it encounters common SSL
errors
2. the `--insecure` flag works to ignore SSL errors

It's prompted by #8098, where `--insecure` stopped working and we didn't
notice until it was reported by a user.

## Deets + considerations

This PR uses [badssl.com](https://badssl.com/), a very handy website
affiliated with the Google Chrome team. The badssl authors mention that
stability is not guaranteed:

> Most subdomains are likely to have stable functionality, but anything
could change without notice.

I suspect that the badssl.com subdomains I've chosen will be stable
enough in practice. Can revisit this if the tests end up being flaky.

This PR does mean our tests are now making an external network call...
which I _think_ is OK. Our CI isn't exactly designed for offline
machines; test runners already have to download a bunch of crates etc. I
think the new tests are quick enough:


![image](https://user-images.githubusercontent.com/26268125/222992751-a9f0d8ff-b776-4ea5-908a-7d11607487fe.png)
2023-03-07 07:56:39 -08:00
Reilly Wood
e445c41454
Fix to json for SQLite databases (#8343)
Fixes #8341. 

The `CustomValue::to_json()` function is an odd duck; it defaults to
returning `null`, and no `CustomValue` implementations override it to do
anything useful. I forgot to implement `to_json()` for `SQLiteDatabase`,
so `open foo.db | to json` was returning `null`.

To fix this, I've removed `CustomValue::to_json()` and now `to json`
will collect a `CustomValue` into a regular `Value` before doing a JSON
conversion.
2023-03-06 14:36:26 -08:00
Stefan Holderbach
62575c9a4f
Document and critically review ShellError variants - Ep. 3 (#8340)
Continuation of #8229 and #8326

# Description

The `ShellError` enum at the moment is kind of messy. 

Many variants are basic tuple structs where you always have to reference
the implementation with its macro invocation to know which field serves
which purpose.
Furthermore we have both variants that are kind of redundant or either
overly broad to be useful for the user to match on or overly specific
with few uses.

So I set out to start fixing the lacking documentation and naming to
make it feasible to critically review the individual usages and fix
those.
Furthermore we can decide to join or split up variants that don't seem
to be fit for purpose.

# Call to action

**Everyone:** Feel free to add review comments if you spot inconsistent
use of `ShellError` variants.

# User-Facing Changes

(None now, end goal more explicit and consistent error messages)

# Tests + Formatting

(No additional tests needed so far)

# Commits (so far)

- Remove `ShellError::FeatureNotEnabled`
- Name fields on `SE::ExternalNotSupported`
- Name field on `SE::InvalidProbability`
- Name fields on `SE::NushellFailed` variants
- Remove unused `SE::NushellFailedSpannedHelp`
- Name field on `SE::VariableNotFoundAtRuntime`
- Name fields on `SE::EnvVarNotFoundAtRuntime`
- Name fields on `SE::ModuleNotFoundAtRuntime`
- Remove usused `ModuleOrOverlayNotFoundAtRuntime`
- Name fields on `SE::OverlayNotFoundAtRuntime`
- Name field on `SE::NotFound`
2023-03-06 18:33:09 +01:00
Reilly Wood
4898750fc1
Remove body parameters from http get (#8336)
`http get` has 2 parameters which are used for setting the body of the
HTTP request. They don't make sense because [GET requests should have no
body](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET):


![image](https://user-images.githubusercontent.com/26268125/223032130-764d0313-df00-48a6-80a5-0d8ff296b8ae.png)
2023-03-06 08:49:28 -08:00
Stefan Holderbach
f7b8f97873
Document and critically review ShellError variants - Ep. 2 (#8326)
Continuation of #8229 

# Description

The `ShellError` enum at the moment is kind of messy. 

Many variants are basic tuple structs where you always have to reference
the implementation with its macro invocation to know which field serves
which purpose.
Furthermore we have both variants that are kind of redundant or either
overly broad to be useful for the user to match on or overly specific
with few uses.

So I set out to start fixing the lacking documentation and naming to
make it feasible to critically review the individual usages and fix
those.
Furthermore we can decide to join or split up variants that don't seem
to be fit for purpose.

**Everyone:** Feel free to add review comments if you spot inconsistent
use of `ShellError` variants.

- Name fields of `SE::IncorrectValue`
- Merge and name fields on `SE::TypeMismatch`
- Name fields on `SE::UnsupportedOperator`
- Name fields on `AssignmentRequires*` and fix doc
- Name fields on `SE::UnknownOperator`
- Name fields on `SE::MissingParameter`
- Name fields on `SE::DelimiterError`
- Name fields on `SE::IncompatibleParametersSingle`

# User-Facing Changes

(None now, end goal more explicit and consistent error messages)

# Tests + Formatting

(No additional tests needed so far)
2023-03-06 11:31:07 +01:00
dependabot[bot]
b7a34498e3
Bump rust-embed from 6.4.1 to 6.6.0 (#8330)
Bumps [rust-embed](https://github.com/pyros2097/rust-embed) from 6.4.1
to 6.6.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/pyrossh/rust-embed/blob/master/changelog.md">rust-embed's
changelog</a>.</em></p>
<blockquote>
<h2>[6.6.0] - 2023-03-05</h2>
<ul>
<li>sort_by_file_name() requires walkdir v2.3.2 <a
href="https://github-redirect.dependabot.com/pyrossh/rust-embed/issues/206">#206</a></li>
<li>Add <code>mime-guess</code> feature to statically store mimetype <a
href="https://github-redirect.dependabot.com/pyrossh/rust-embed/issues/192">#192</a></li>
</ul>
<h2>[6.4.2] - 2022-10-20</h2>
<ul>
<li>Fail the proc macro if include/exclude are used without the feature
<a
href="https://github-redirect.dependabot.com/pyrossh/rust-embed/issues/187">#187</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li>See full diff in <a
href="https://github.com/pyros2097/rust-embed/commits">compare
view</a></li>
</ul>
</details>
<br />


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

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

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

---

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

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


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-05 19:36:14 -08:00
dependabot[bot]
10fd3115c2
Bump rayon from 1.6.1 to 1.7.0 (#8328)
Bumps [rayon](https://github.com/rayon-rs/rayon) from 1.6.1 to 1.7.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/rayon-rs/rayon/blob/master/RELEASES.md">rayon's
changelog</a>.</em></p>
<blockquote>
<h1>Release rayon 1.7.0 / rayon-core 1.11.0 (2023-03-03)</h1>
<ul>
<li>The minimum supported <code>rustc</code> is now 1.59.</li>
<li>Added a fallback when threading is unsupported.</li>
<li>The new <code>ParallelIterator::take_any</code> and
<code>skip_any</code> methods work like
unordered <code>IndexedParallelIterator::take</code> and
<code>skip</code>, counting items in
whatever order they are visited in parallel.</li>
<li>The new <code>ParallelIterator::take_any_while</code> and
<code>skip_any_while</code> methods work
like unordered <code>Iterator::take_while</code> and
<code>skip_while</code>, which previously had
no parallel equivalent. The &quot;while&quot; condition may be satisfied
from anywhere
in the parallel iterator, affecting all future items regardless of
position.</li>
<li>The new <code>yield_now</code> and <code>yield_local</code>
functions will cooperatively yield
execution to Rayon, either trying to execute pending work from the
entire
pool or from just the local deques of the current thread,
respectively.</li>
</ul>
<h1>Release rayon-core 1.10.2 (2023-01-22)</h1>
<ul>
<li>Fixed miri-reported UB for SharedReadOnly tags protected by a
call.</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="7ffaf3463b"><code>7ffaf34</code></a>
Merge <a
href="https://github-redirect.dependabot.com/rayon-rs/rayon/issues/716">#716</a></li>
<li><a
href="163003e0e3"><code>163003e</code></a>
bump the release date</li>
<li><a
href="f7d75532fc"><code>f7d7553</code></a>
Release rayon 1.3.0 / rayon-core 1.7.0</li>
<li><a
href="b98bb23f05"><code>b98bb23</code></a>
Remove unneeded extern crate statements</li>
<li><a
href="9b92c7deb9"><code>9b92c7d</code></a>
cargo fmt</li>
<li><a
href="e02f439bbf"><code>e02f439</code></a>
Remove useless 'use crate;' in favor of the crate prelude</li>
<li><a
href="a1db0fe390"><code>a1db0fe</code></a>
Fix clippy::flat_map_identity</li>
<li><a
href="4e4025693f"><code>4e40256</code></a>
Update ci/compat-Cargo.lock</li>
<li><a
href="1f9d117d51"><code>1f9d117</code></a>
Remove cfg(rayon_unstable)</li>
<li><a
href="198ca7f6aa"><code>198ca7f</code></a>
Remove rayon-futures</li>
<li>Additional commits viewable in <a
href="https://github.com/rayon-rs/rayon/compare/rayon-core-v1.6.1...rayon-core-v1.7.0">compare
view</a></li>
</ul>
</details>
<br />


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

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

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

---

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

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


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-05 19:32:16 -08:00
Filip Andersson
f6ca62384e
changes Reqwest to Ureq. (#8320)
# Description

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

This pull request removes `Reqwest` and replaces it with `Ureq` to
remove some of our dependencies, giving us faster compile times as well
as smaller binaries. `Ureq` does not have an async runtime included so
we do not need build heavy dependencies such as `Tokio`. From older
tests I had the number of build units be reduced from `430 -> 392`.
The default of `Ureq` uses `Rustls` but it has been configured to
instead use `native_tls` which should work exactly the same as the `tls`
works now.
I removed `content-length` from the http commands as after refactoring i
did not see a reason to have it available, correct me if this is
something we should preserve.

In the medium, to long term, we should maybe consider changing to
`rustls` to have the same `tls` on all platforms.

# User-Facing Changes

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

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-05 14:48:13 -08:00
Reilly Wood
f93033c20b
Fix CPU usage info in sys (#8321)
Closes #8264. This PR does a few things to fix the `usage` column in
`sys.cpu`:

1. Sleep a while (~400ms) between calls to `sys.refresh_cpu()`, [as
required by
`sysinfo`](https://docs.rs/sysinfo/latest/sysinfo/trait.SystemExt.html#method.refresh_cpu)
2. Change `sys` to return a `LazyRecord` (so you can do things like `sys
| get host` instantly without waiting for CPU info)
3. Update our `sysinfo` dependency to [fix CPU usage calculations on
Linux](https://github.com/GuillaumeGomez/sysinfo/pull/946)

CPU usage is no longer always reported as zero:


![image](https://user-images.githubusercontent.com/26268125/222929775-5e9cbe18-95d9-4ecb-baf8-1e843f5c7086.png)
2023-03-04 14:48:34 -08:00
Jérémy Audiger
b9c78a05aa
Resolve Clippy warnings inside tests. (#8315)
# Description

Command: `cargo clippy --workspace --all-targets`

Resolve those warnings:

```
warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> crates/nu-parser/tests/test_parser.rs:86:59
   |
86 |             compare_rhs_binaryOp(test_tag, &expected_val, &observed_val);
   |                                                           ^^^^^^^^^^^^^ help: change this to: `observed_val`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
   = note: `#[warn(clippy::needless_borrow)]` on by default

warning: `assert!(false, ..)` should probably be replaced
   --> crates/nu-cli/src/completions/command_completions.rs:319:17
    |
319 |                 assert!(false, "Merge delta has failed: {}", err);
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: use `panic!(..)` or `unreachable!(..)`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants
    = note: `#[warn(clippy::assertions_on_constants)]` on by default

warning: 1 warning emitted

warning: `assert!(false, ..)` should probably be replaced
   --> crates/nu-cli/src/completions/completer.rs:600:13
    |
600 |             assert!(false, "Error merging delta: {:?}", err);
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: use `panic!(..)` or `unreachable!(..)`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants

warning: length comparison to zero
   --> crates/nu-cli/src/completions/completer.rs:620:24
    |
620 |             assert_eq!(result.len() > 0, has_result, "line: {}", line);
    |                        ^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!result.is_empty()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
    = note: `#[warn(clippy::len_zero)]` on by default

warning: equality checks against true are unnecessary
   --> crates/nu-cli/src/completions/completer.rs:632:33
    |
632 |                     .filter(|x| *x == true)
    |                                 ^^^^^^^^^^ help: try simplifying it as shown: `*x`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
    = note: `#[warn(clippy::bool_comparison)]` on by default

    Checking nu v0.76.1 (/home/jaudiger/Development/git-repositories/jaudiger/nushell)
warning: 4 warnings emitted

warning: the borrowed expression implements the required traits
  --> crates/nu-command/tests/commands/cp.rs:26:40
   |
26 |         let first_hash = get_file_hash(&test_file.display());
   |                                        ^^^^^^^^^^^^^^^^^^^^ help: change this to: `test_file.display()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
   = note: `#[warn(clippy::needless_borrow)]` on by default

warning: the borrowed expression implements the required traits
   --> crates/nu-command/tests/commands/cp.rs:178:13
    |
178 |             &jonathans_expected_copied_dir
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `jonathans_expected_copied_dir`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: the borrowed expression implements the required traits
   --> crates/nu-command/tests/commands/cp.rs:182:13
    |
182 |             &andres_expected_copied_dir
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `andres_expected_copied_dir`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: the borrowed expression implements the required traits
   --> crates/nu-command/tests/commands/cp.rs:186:13
    |
186 |             &yehudas_expected_copied_dir
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `yehudas_expected_copied_dir`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: 4 warnings emitted
```

# User-Facing Changes

None.

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-04 14:58:20 +01:00
Jérémy Audiger
a7b5bd18ba
Shadow rs dep (#8298)
# Description

While looking at the recent MR merged, I noticed that a dependency was
no more used with https://github.com/nushell/nushell/pull/8280.

# User-Facing Changes

None.

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-03 09:41:13 -08:00
Jérémy Audiger
c1d76bfac7
Add unit tests for HTTP commands. (#8267)
# Description

Following the comment from @fdncred:
https://github.com/nushell/nushell/pull/8144#issuecomment-1442514338. I
added some unit tests for HTTP commands. The tests are not exhaustive,
but at least, this is a first good step IMO.

# User-Facing Changes

None.

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-02 11:05:18 -08:00
Stefan Holderbach
438062d7fc
Document and critically review ShellError variants - Ep. 1 (#8229)
# Description

The `ShellError` enum at the moment is kind of messy. 

Many variants are basic tuple structs where you always have to reference
the implementation with its macro invocation to know which field serves
which purpose.
Furthermore we have both variants that are kind of redundant or either
overly broad to be useful for the user to match on or overly specific
with few uses.

So I set out to start fixing the lacking documentation and naming to
make it feasible to critically review the individual usages and fix
those.
Furthermore we can decide to join or split up variants that don't seem
to be fit for purpose.

Feel free to add review comments if you spot inconsistent use of
`ShellError` variants.

- Name fields on `ShellError::OperatorOverflow`
- Name fields on `ShellError::PipelineMismatch`
- Add doc to `ShellError::OnlySupportsThisInputType`
- Name `ShellError::OnlySupportsThisInputType`
- Name field on `ShellError::PipelineEmpty`
- Comment about issues with `TypeMismatch*`
- Fix a few `exp_input_type`s
- Name fields on `ShellError::InvalidRange`

# User-Facing Changes

(None now, end goal more explicit and consistent error messages)

# Tests + Formatting

(No additional tests needed so far)
2023-03-01 20:34:48 +01:00
Michael Angerman
5bf077d64f
remove left over build.rs from nu-command (#8280)
@fdncred pointed out to me that post creation of the nu-cmd-lang crate
we probably don't need an extra build.rs
file in nu-command any longer now that the version command (and
build.rs) is located in nu-cmd-lang...

I am removing the redundancy...
2023-03-01 09:30:58 -08:00
WindSoilder
dec0a2517f
Throw out error if external command in subexpression is failed to run (#8204) 2023-03-01 13:50:38 +02:00
Reilly Wood
324d625324
Fix CPU frequency in sys output (#8275)
The `sys | get cpu.freq` column (supposed to contain the frequency for
each CPU core in megahertz) was incorrect for 2 reasons:
1. We weren't telling the `sysinfo` crate to refresh CPU frequency info
2. We were overwriting the values in the column with the systemwide
physical core count. Whoops!

### Before


![image](https://user-images.githubusercontent.com/26268125/222045977-2c021c92-794f-4498-b12c-e3a1bbaa7483.png)

### After


![image](https://user-images.githubusercontent.com/26268125/222046066-ff8ccd21-3c47-4d7d-8f14-e0744822cd2d.png)


## Future work

This PR does not fix https://github.com/nushell/nushell/issues/8264 ;
the `cpu_usage` column is still incorrect.
2023-03-01 21:31:05 +13:00
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
dependabot[bot]
a09aaf3495
Bump csv from 1.1.6 to 1.2.0 (#8235)
Bumps [csv](https://github.com/BurntSushi/rust-csv) from 1.1.6 to 1.2.0.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="fa01b78533"><code>fa01b78</code></a>
1.2.0</li>
<li><a
href="2ba20b55d9"><code>2ba20b5</code></a>
readme: various updates</li>
<li><a
href="521294f87b"><code>521294f</code></a>
msrv: set rust-version = 1.60</li>
<li><a
href="31c8ebc49d"><code>31c8ebc</code></a>
readme: updates and set rust-version</li>
<li><a
href="a0e83883e2"><code>a0e8388</code></a>
deps: drop 'bstr'</li>
<li><a
href="9e1126a3f4"><code>9e1126a</code></a>
cargo: update some fields</li>
<li><a
href="d7a4f7dcc6"><code>d7a4f7d</code></a>
rust: move to 2021 edition</li>
<li><a
href="022ac05205"><code>022ac05</code></a>
error: drop 'source' impl</li>
<li><a
href="9ab83111a7"><code>9ab8311</code></a>
*: better import grouping and short hand struct init</li>
<li><a
href="ea0273c531"><code>ea0273c</code></a>
*: fix all warnings and update code</li>
<li>Additional commits viewable in <a
href="https://github.com/BurntSushi/rust-csv/compare/1.1.6...1.2.0">compare
view</a></li>
</ul>
</details>
<br />


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

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

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

---

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

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


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-27 19:48:51 +13:00
dependabot[bot]
ffc8e752a5
Bump bytesize from 1.1.0 to 1.2.0 (#8236)
Bumps [bytesize](https://github.com/hyunsik/bytesize) from 1.1.0 to
1.2.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/hyunsik/bytesize/releases">bytesize's
releases</a>.</em></p>
<blockquote>
<h2>Release 1.2.0</h2>
<h2>Changes</h2>
<ul>
<li>serde improvements <a
href="https://github-redirect.dependabot.com/hyunsik/bytesize/issues/29">#29</a>
(<a
href="https://github.com/joeroback"><code>@​joeroback</code></a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="476dc867b2"><code>476dc86</code></a>
Remove -dev suffix for release</li>
<li><a
href="eaaf3bc097"><code>eaaf3bc</code></a>
Merge pull request <a
href="https://github-redirect.dependabot.com/hyunsik/bytesize/issues/29">#29</a>
from joeroback/serde_improvements</li>
<li><a
href="c7a785bd2c"><code>c7a785b</code></a>
resolves <a
href="https://github-redirect.dependabot.com/hyunsik/bytesize/issues/27">#27</a>,
fixes several clippy warnings with u16/u8 and is_digit/is_ascii...</li>
<li><a
href="db44636f05"><code>db44636</code></a>
Merge pull request <a
href="https://github-redirect.dependabot.com/hyunsik/bytesize/issues/28">#28</a>
from ileixe/master</li>
<li><a
href="58cf4a5024"><code>58cf4a5</code></a>
Change as_u64() to const</li>
<li><a
href="065c00b54f"><code>065c00b</code></a>
Change the crate version to 1.2.0-dev</li>
<li>See full diff in <a
href="https://github.com/hyunsik/bytesize/compare/v1.1.0...v1.2.0">compare
view</a></li>
</ul>
</details>
<br />


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

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

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

---

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

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


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-27 19:48:14 +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