Commit Graph

1016 Commits

Author SHA1 Message Date
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
mike
e01eb42e74
fix NotAConstant error help message (#8293)
```
Error: nu::parser::not_a_constant (link)

  × Not a constant.
   ╭─[entry #23:1:1]
 1 │ let file = "/home/user/file"; source $file
   ·                                      ──┬──
   ·                                        ╰── Value is not a parse-time constant
   ╰────
  help: Only a subset of expressions are allowed
        constants during parsing. Try using the 'let'
        command or typing the value literally.
```
this pr changes the help message to 'Try using the `const` command ...'
2023-03-02 19:07:25 -06: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
mike
0a2e711351
fix: allow subtraction of durations from dates (#8247)
`date` - `duration` is
[implemented](ba5258d716/crates/nu-protocol/src/value/mod.rs (L2145))
but the type checker rejects it

this pr fixes that
2023-02-27 21:17:58 +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]
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
Ryan Devenney
b572b4ecbd
remove links to ShellError and ParseError docs - #8167 (#8193)
# Description

issue #8167

Remove the `(link)` to the docs for `ShellError` and `ParseError`. As
per discussion on the issue, the nu-parser version didn't update on the
docs causing deadlinks for those errors, which brought the usefullness
of these links into question and it was decided to remove all of them
that `derive(diagnostic)`.

# User-Facing Changes
Before:
```
/home/rdevenney/projects/open_source/nushell〉ls | get name}
Error: nu::parser::unbalanced_delimiter (link)

  × Unbalanced delimiter.
   ╭─[entry #1:1:1]
 1 │ ls | get name}
   ·              ▲
   ·              ╰── unbalanced { and }
   ╰────
```

After:
```
/home/rdevenney/projects/open_source/nushell〉ls | get name}
Error: nu::parser::unbalanced_delimiter

  × Unbalanced delimiter.
   ╭─[entry #1:1:1]
 1 │ ls | get name}
   ·              ▲
   ·              ╰── unbalanced { and }
   ╰────
```

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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:26:31 -08:00
Mango The Fourth
d0e0701a88
fix: fix lexing of comments, such that a#b becomes a coherent Item (#8151)
# Description

Previously `nix run nixpkgs#hello` was lexed as `Item, Item, Item,
Comment`, however, `#hello` is *not* supposed to be a comment here and
should be parsed as part of the third `Item`.

This change introduces this behavior by not interrupting the parse of
the current token upon seeing a `#`.

Thank you so much for considering this, I think many `nix` users will be
grateful for this change and I think this will lead to more adaptation
in the ecosystem.

- closes #8137 and #6335 

# User-Facing Changes

- code like `somecode# bla` and `somecode#bla` will not be parsed as
`somecode, comment` but as `somecode#bla`, hence this is a breaking
change for all users who didn't put a space before a comment introducing
token (`#`)

# Tests + Formatting

I've added tests that cover this behavior in `test_lex.rs`

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

I think this is expected behavior in most other shells, so the
documentation was lacking for not documenting the unexpected behavior
before and hence now is automatically more complete >D
2023-02-22 12:59:47 +00:00
Darren Schroeder
e761954cf0
allow different types of lists to be appended (#8157)
# Description

closes #8153

This PR allows different types of lists, like `list<string>` and
`list<any>` to be appended with the `++=` operator.

## Before

```
mut args = [ hello ("hello" | path join world)]
$args ++= [ foo bar ]
Error: nu::parser::type_mismatch (link)

  × Type mismatch during operation.
   ╭─[entry #2:1:1]
 1 │ $args ++= [ foo bar ]
   ·           ─────┬─────
   ·                ╰── expected list<any>, found list<string>
   ╰────
```

## After

```
mut args = [ hello ("hello" | path join world)]
$args ++= [ foo bar ]
$args
╭───┬─────────────╮
│ 0 │ hello       │
│ 1 │ hello\world │
│ 2 │ foo         │
│ 3 │ bar         │
╰───┴─────────────╯
```

# 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-22 12:53:36 +00:00
Darren Schroeder
58829e3560
fixes a def parsing bug with a default list (#8096)
# Description

This PR fixes a bug where a default list in a custom command parameter
wasn't being accepted. The reason was because it was comparing specific
types of list like `list<any>` != `list<string>`. So, this PR attempts
to fix that.

### Before

```
> def f [param: list = [one]] { echo $param }
Error: nu::parser::assignment_mismatch (link)

  × Default value wrong type
   ╭─[entry #1:1:1]
 1 │ def f [param: list = [one]] { echo $param }
   ·                      ──┬──
   ·                        ╰── default value not list<any>
   ╰────
```

### After

```
> def f [param: list = [one]] {echo $param}
> f
╭───┬─────╮
│ 0 │ one │
╰───┴─────╯
```

closes #8092 

# 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-22 12:53:11 +00:00
WindSoilder
62652cf8c1
simplify parse_expression function code. (#8149)
# Description

When reading parser code to see how it works, I found that
`parse_expression` function contains some duplicate code about function
call, we can match several values at once to simplify code

# 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-22 12:14:20 +00:00
Stefan Holderbach
95ec2fcce7
Update to 0.76.1 version for development (#8161)
# Description

For tracking in `version` for bug reports during development. Might be
used for an urgent hotfix if necessary.
2023-02-21 23:21:39 +00:00
Stefan Holderbach
bc38a6a795
Bump version for 0.76.0 release (#8121)
Before landing:

- [x] `reedline 0.16.0` is out and pinned.
- [x] all fixes and features necessary are landed.

In the meantime:

- [ ] feed the release notes with relevant features and breaking changes
2023-02-21 20:46:29 +00:00
JT
ade7bde813
Bare word improvements (#8066)
# Description

This does two fixes for bare words:

* It changes completions for paths to wrap a path with backticks if it
starts with a number. This helps bare words that start with numbers be
separate from unit values
* It allows bare words wrapped with backticks to be the name of a
command. Backtick values in command positions are no longer treated as
strings

# 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-16 02:30:56 +00:00
WindSoilder
8136170431
support multiplication operation on string and list values (#8061)
# Description

As title, I found this feature is useful to me too :)

Closes: #8039

# User-Facing Changes

```
❯ 3 * "ab"
ababab

❯ 3 * [1 2 3]
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 1 │
│ 4 │ 2 │
│ 5 │ 3 │
│ 6 │ 1 │
│ 7 │ 2 │
│ 8 │ 3 │
╰───┴───╯
```

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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:35:53 +00:00
Bob Hyman
007916c2c1
Syntax errors for string and int (#7952)
# Description

Added a few syntax errors in ints and strings, changed parser to stop
and show that error rather than continue trying to parse those tokens as
some other shape. However, I don't see how to push this direction much
further, and most of the classic confusing errors can't be changed.

Flagged as WIP for the moment, but passes all checks and works better
than current release:
1. I have yet to figure out how to make these errors refer back to the
book, as I see some other errors do.
2. How to give syntax error when malformed int is first token in line?
Currently parsed as external command, user gets confusing error message.
3. Would like to be more strict with *decimal* int literals (lacking,
e.g, `0x' prefix). Need to tinker more with the order of parse shape
calls, currently, float is tried after int, so '1.4' has to be passed.

_(Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.)_

```bash

〉"\z"
Error: 
   ╭─[entry #3:1:1]
 1 │ "\z"
   ·  ─┬─
   ·   ╰── Syntax error in string, unrecognized character after escape '\'.
   ╰────
```
Canonic presentation of a syntax error.
```bash
〉"  \u{01ffbogus}"
Error: 
  × Invalid syntax
   ╭─[entry #2:1:1]
 1 │ "  \u{01ffbogus}"
   ·    ───────┬──────
   ·           ╰── Syntax error in string, expecting 1 to 6 hex digits in unicode escape '\u{X...}', max value 10FFFF.
   ╰────
```
Malformed unicode escape in string, flagged as error.  
String parse can be opinionated, it's the last shape tried.
```bash
〉0x22bogus
Error: nu:🐚:external_command (link)
  × External command failed
   ╭─[entry #4:1:1]
1 │ 0x22bogus
   · ────┬────
   ·     ╰── executable was not found
   ╰────
  help: No such file or directory (os error 2)
```
A *correct* number in first token would be evaluated, but an *incorrect*
one is treated as external command? Confusing to users.
```bash
〉0 + 0x22bogus
Error: 
  × Invalid syntax
   ╭─[entry #5:1:1]
1 │ 0 + 0x22bogus
   ·     ────┬────
   ·         ╰── Syntax error in int, invalid digits in radix 16 int.
   ╰────
```
Can give syntax error if token is unambiguously int literal. e.g has 0b
or 0x prefix, could not be a float.
```bash
〉0 + 098bogus
Error: nu::parser::unsupported_operation (link)

  × Types mismatched for operation.
   ╭─[entry #6:1:1]
 1 │ 0 + 098bogus
   · ┬ ┬ ────┬───
   · │ │     ╰── string
   · │ ╰── doesn't support these values.
   · ╰── int
   ╰────
  help: Change int or string to be the right types and try again.
```
But *decimal* literal (no prefix) can't be too strict. Parser is going
to try float later. So '1.4' must be passed.

# User-Facing Changes

First and foremost, more specific error messages for typos in string and
int literals. Probably improves interactive user experience.

But a script that was causing and then checking for specific error might
notice a different error message.

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

# Tests + Formatting

Added (positive and negative unit tests in `cargo test -p nu-parser`.
Didn't add integration tests.

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: Stefan Holderbach <sholderbach@users.noreply.github.com>
2023-02-13 16:09:50 +00:00
Stefan Holderbach
1cd70d7505
Disable auto-benchmark harness for crates (#8057)
# Description

This disables automatic detection of `#[bench]` and other benchmarks
within the crates. Our benchmarks should all live in `benches`

This fixes a problem with criterion flags and should also reduce the
build requirements for `cargo bench` a bit

Taken from https://github.com/nushell/nushell/pull/7952

See:
https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options


# User-Facing Changes

None
2023-02-12 22:22:00 +00:00
Reilly Wood
16b99ed0ba
Make ++ operator work with strings and binary values (#8017)
This PR makes `++` (the append operator) work with strings and binary
values. Can now do things like:

```bash
〉"a" ++ "b"
ab
〉0x[01 02] ++ 0x[03]
Length: 3 (0x3) bytes | printable whitespace ascii_other non_ascii
00000000:   01 02 03                                             •••
```

Closes #8015.
2023-02-10 07:52:10 +13:00
WindSoilder
055edd886d
Make plugin commands support examples. (#7984)
# Description

As title, we can't provide examples for plugin commands, this pr would
make it possible


# User-Facing Changes

Take plugin `nu-example-1` as example:
```
❯ nu-example-1 -h
PluginSignature test 1 for plugin. Returns Value::Nothing

Usage:
  > nu-example-1 {flags} <a> <b> (opt) ...(rest)

Flags:
  -h, --help - Display the help message for this command
  -f, --flag - a flag for the signature
  -n, --named <String> - named string

Parameters:
  a <int>: required integer value
  b <string>: required string value
  (optional) opt <int>: Optional number
  ...rest <string>: rest value string

Examples:
  running example with an int value and string value
  > nu-example-1 3 bb
```

The examples session is newly added.

## Basic idea behind these changes
when nushell query plugin signatures, plugin just returns it's signature
without any examples, so nushell have no idea about the examples of
plugin commands.
To adding the feature, we just making plugin returns it's signature with
examples.

Before:
```
        1. get signature
         ----------------> 
Nushell ------------------  Plugin
        <-----------------
        2. returns Vec<Signature>
```

After:
```
        1. get signature
        ----------------> 
Nushell ------------------  Plugin
        <-----------------
        2. returns Vec<PluginSignature>
```
        
When writing plugin signature to $nu.plugin-path:
Serialize `<PluginSignature>` rather than `<Signature>`, which would
enable us to serialize examples to `$nu.plugin-path`

## Shortcoming
It's a breaking changes because `Plugin::signature` is changed, and it
requires plugin authors to change their code for new signatures.

Fortunally it should be easy to change, for rust based plugin, we just
need to make a global replace from word `Signature` to word
`PluginSignature` in their plugin project.

Our content of plugin-path is really large, if one plugin have many
examples, it'd results to larger body of $nu.plugin-path, which is not
really scale. A solution would be save register information in other
binary formats rather than `json`. But I think it'd be another story.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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-08 16:14:18 -06:00
Jérémy Audiger
99076af18b
Use imported names in Command::run signatures (#7967)
# Description

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

I opened this PR to unify the run command method. It's mainly to improve
consistency across the tree.

# 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-05 22:17:46 +01:00
Stefan Holderbach
5e957ecda6
Bump to 0.75.1 development version (#7930)
To demark development work or to be used with a point release in an
emergency
2023-01-31 23:55:29 +01:00
Stefan Holderbach
17a265b197
Version bump for 0.75 release (#7902)
- [x] Are we ready for the release
- [x] Upgrade to upcoming `reedline 0.15`
2023-01-31 21:00:59 +01:00
Darren Schroeder
3fabc8e1e6
update type check so that ++ with lists works better (#7926)
closes https://github.com/nushell/nushell/issues/7913
2023-01-31 21:11:05 +02:00
Stefan Holderbach
ab480856a5
Use variable names directly in the format strings (#7906)
# Description

Lint: `clippy::uninlined_format_args`

More readable in most situations.
(May be slightly confusing for modifier format strings
https://doc.rust-lang.org/std/fmt/index.html#formatting-parameters)

Alternative to #7865

# User-Facing Changes

None intended

# Tests + Formatting

(Ran `cargo +stable clippy --fix --workspace -- -A clippy::all -D
clippy::uninlined_format_args` to achieve this. Depends on Rust `1.67`)
2023-01-29 19:37:54 -06:00
Bob Hyman
e616b2e247
Support extended unicode escapes in strings: "\u{10fff}" (#7883)
# Description

Support extended unicode escapes in strings with same syntax as Rust:
`"\u{6e}"`.

# User-Facing Changes

New syntax in string literals, `\u{NNNNNN}`, to go along with the
existing `\uNNNN`.
New syntax accepts 1-6 hex digits and rejects values greater than
0x10FFFF (max Unicode char)..

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

Won't break existing scripts, since this is new syntax.  

We might consider deprecating `char -u`, since users can now embed
unicode chars > 0xFFFF with the new escape.

# Tests + Formatting

Several unit tests and one integration test added.

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

# After Submitting

- [ ] If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-01-29 09:25:53 +13:00
Jakub Žádník
3c6b10c6b2
Fix wrong VarId of $in variable (#7893)
Fixes https://github.com/nushell/nushell/issues/7872
2023-01-28 19:55:29 +02:00
JT
36ddbfdc85
Add 'number' command for enumeration (#7871)
# Description

This adds a `number` command that will enumerate the input, and add an
`index` and `item` record for each item. The `index` is the number of
the item in the input stream, and `item` is the original value of the
item.

```
> ls | number | get 14
╭───────┬────────────────────────────╮
│ index │ 14                         │
│       │ ╭──────────┬─────────────╮ │
│ item  │ │ name     │ crates      │ │
│       │ │ type     │ dir         │ │
│       │ │ size     │ 832 B       │ │
│       │ │ modified │ 2 weeks ago │ │
│       │ ╰──────────┴─────────────╯ │
╰───────┴────────────────────────────╯
```

# User-Facing Changes

This adds a `number` command.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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-01-28 06:45:57 +13:00
Darren Schroeder
e03c354e89
add decimal to SyntaxShape (#7852)
# Description

This adds the `SyntaxShape::Decimal` so you can create custom commands
with `decimal` types such as:
```shell
def cmd [x:decimal] { echo $x }
```

/cc @kurokirasama

Internally this is a little messy since we have `Type::Float` and
`SyntaxShape::Decimal`. I originally named it `float` and
`SyntaxShape::Float` but since we have `into decimal` and `1.1 |
describe` reports `decimal`, I decided to change the SyntaxShape.

# 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-01-25 06:43:22 -06:00
Kangaxx-0
0bb2e47c98
Incorrect parsing of unbalanced braces based on issue 6914 (#7621) 2023-01-24 10:05:46 +02:00
dependabot[bot]
bef397228f
Bump miette from 5.3.0 to 5.5.0 (#7838) 2023-01-23 01:56:28 +00:00
Jakub Žádník
ba12b0de0d
Fix command name lookup for known externals (#7830)
Fixes https://github.com/nushell/nushell/issues/7822
2023-01-22 21:40:18 +02:00
Jakub Žádník
3552d03f6c
Allow main command to define top-level module command (#7764) 2023-01-22 21:34:15 +02:00
WindSoilder
4f57c5d56e
Fix multi-line redirection inside a block (#7808)
# Description

Fixes: #7786

The issue is because the lite block is wrong while converting from lex
tokens

# What happened internally?
Take the following as example:
```
❯ def foobar [] { 
    'hello' out> /tmp/output.1
    'world' out> /tmp/output.2
}
```

## Before:
```
LiteBlock { block: [
    LitePipeline { commands: [
        Command(None, LiteCommand { comments: [], parts: [Span { start: 40900, end:40907 }] }),
        Redirection(Span { start: 40908, end: 40912 }, Stdout, LiteCommand { comments: [], parts: [Span { start: 40913, end: 40926 }] })]
    },
    LitePipeline { commands: [
        Redirection(Span { start: 40908, end: 40912 }, Stdout, LiteCommand { comments: [], parts: [Span { start: 40929, end: 40936 }] }),   // this is wrong, should be command.
        Redirection(Span { start: 40937, end: 40941 }, Stdout, LiteCommand { comments: [], parts: [Span { start: 40942, end: 40955 }] })]
    }] }
```

## After:
```
LiteBlock { block: [
    LitePipeline { commands: [
        Command(None, LiteCommand { comments: [], parts: [Span { start: 40824, end: 40831 }] }),
        Redirection(Span { start: 40832, end: 40836 }, Stdout, LiteCommand { comments: [], parts: [Span { start: 40837, end: 40850 }] })] 
    },
    LitePipeline { commands: [
        Command(None, LiteCommand { comments: [], parts: [Span { start: 40854, end: 40861 }] }), 
        Redirection(Span { start: 40862, end: 40866 }, Stdout, LiteCommand { comments: [], parts: [Span { start: 40867, end: 40880 }] })] 
    }
] }
```

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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-01-23 06:32:56 +13:00
Günter Zöchbauer
2c5c81815a
Fix typos (#7811)
Some minor text fixes
2023-01-22 15:22:10 +01:00
mike
0fe2884397
add dedicated const in pipeline, const builtin var errors (#7784)
# Description

Currently `let` and `const` share error handling, and this might lead to
confusing error messages


![sJan17-51](https://user-images.githubusercontent.com/98623181/212981108-c80b3e55-cece-4ee5-ba8f-cb5dcfdf63e0.png)

This PR adds dedicated errors to `const`
2023-01-20 00:11:48 +01:00
Justin Ma
f823c7cb5d
fix some typos (#7773)
# Description

Nothing changed, just fix some typos

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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: Stefan Holderbach <sholderbach@users.noreply.github.com>
2023-01-16 12:43:46 +01:00
mike
56a9eab7eb
Allow underscores in integers and floats (#7759)
# Description

This PR makes changes that allow underscores in numbers.

Example:
```nu
# allows underscores to be placed arbitrarily to enhance readability.
let pi = 3.1415_9265_3589_793

# works with integers
let num = 1_000_000_000_000
let fav_color = 0x68_9d_6a
```
2023-01-15 09:03:57 -06:00
Anton
7221eb7f39
Fix typos and use more idiomatic assertions (#7755)
I have changed `assert!(a == b)` calls to `assert_eq!(a, b)`, which give
better error messages. Similarly for `assert!(a != b)` and
`assert_ne!(a, b)`. Basically all instances were comparing primitives
(string slices or integers), so there is no loss of generality from
special-case macros,

I have also fixed a number of typos in comments, variable names, and a
few user-facing messages.
2023-01-15 15:03:32 +13:00
WindSoilder
8aa2632661
Support redirect err and out to different streams (#7685)
# Description

Closes: #7364 

# User-Facing Changes

Given the following shell script:
```bash
x=$(printf '=%.0s' {1..100})
echo $x
echo $x 1>&2
```

It supports the following command:
```
bash test.sh out> out.txt err> err.txt
```

Then both `out.txt` and `err.txt` will contain `=`(100 times)

## About the change

The core idea is that when doing lite-parsing, introduce a new variant
`LiteElement::SeparateRedirection` if we meet two Redirection
token(which is generated by `lex` function),
During converting from lite block to block,
`LiteElement::SeparateRedirection` will be converted to
`PipelineElement::SeparateRedirection`.

Then in the block eval process, if we get
`PipelineElement::SeparateRedirection`, we invoke `save` command with
`--stderr` arguments to acthive our behavior.



## What happened internally?
Take the following command as example:
```
^ls out> out.txt err> err.txt
```

lex parsing result(`Tokens`) are not changed, but `LiteBlock` and
`Block` is changed after this pr.

### LiteBlock before
```rust
LiteBlock {
    block: [
        LitePipeline { commands: [
            Command(None, LiteCommand { comments: [], parts: [Span { start: 39041, end: 39044 }] }),
            // actually the span of first Redirection is wrong too..
            Redirection(Span { start: 39058, end: 39062 }, Stdout, LiteCommand { comments: [], parts: [Span { start: 39050, end: 39057 }] }),
            Redirection(Span { start: 39058, end: 39062 }, Stderr, LiteCommand { comments: [], parts: [Span { start: 39063, end: 39070 }] })
        ]
    }]
}
```
### LiteBlock after
```rust
LiteBlock {
    block: [
        LitePipeline { commands: [
            Command(
                None, 
                LiteCommand { comments: [], parts: [Span { start: 38525, end: 38528 }] }),
                // new one! two Redirection merged into one SeparateRedirection.
                SeparateRedirection { 
                    out: (Span { start: 38529, end: 38533 }, LiteCommand { comments: [], parts: [Span { start: 38534, end: 38541 }] }),
                    err: (Span { start: 38542, end: 38546 }, LiteCommand { comments: [], parts: [Span { start: 38547, end: 38554 }] })
                }
        ]
    }]
}
```

### Block before
```rust
Pipeline {
    elements: [
        Expression(None, Expression {
            expr: ExternalCall(Expression { expr: String("ls"), span: Span { start: 39042, end: 39044 }, ty: String, custom_completion: None }, [], false),
            span: Span { start: 39041, end: 39044 },
            ty: Any, custom_completion: None 
        }),
        Redirection(Span { start: 39058, end: 39062 }, Stdout, Expression { expr: String("out.txt"), span: Span { start: 39050, end: 39057 }, ty: String, custom_completion: None }),
        Redirection(Span { start: 39058, end: 39062 }, Stderr, Expression { expr: String("err.txt"), span: Span { start: 39063, end: 39070 }, ty: String, custom_completion: None })] }
```

### Block after
```rust
Pipeline {
    elements: [
        Expression(None, Expression {
            expr: ExternalCall(Expression { expr: String("ls"), span: Span { start: 38526, end: 38528 }, ty: String, custom_completion: None }, [], false),
            span: Span { start: 38525, end: 38528 },
            ty: Any,
            custom_completion: None 
        }),
        // new one! SeparateRedirection
        SeparateRedirection {
            out: (Span { start: 38529, end: 38533 }, Expression { expr: String("out.txt"), span: Span { start: 38534, end: 38541 }, ty: String, custom_completion: None }),
            err: (Span { start: 38542, end: 38546 }, Expression { expr: String("err.txt"), span: Span { start: 38547, end: 38554 }, ty: String, custom_completion: None }) 
        }
    ]
}
```
# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](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-01-12 10:22:30 +01:00
Jakub Žádník
57cf805e12
Add const support for all overlay commands (#7720) 2023-01-12 00:18:06 +02:00
Stefan Holderbach
1ae9157985
Bump to 0.74.1 development version (#7721)
# Description

May be used for hotfix if needed
2023-01-11 22:30:41 +01:00
Stefan Holderbach
8044fb2db0
Bump version to 0.74.0 (#7718)
Preparing the release
2023-01-10 20:58:13 +01:00
Amirhossein Akhlaghpour
00469de93e
Limit recursion to avoid stack overflow (#7657)
Add recursion limit to `def` and `block`.
Summary of this PR , it will detect if `def` call itself or not .
Then execute by using `stack` which I think best choice to use with this
design and core as it is available in all crates and mutable and
calculate the recursion limit on calling `def`.
Set 50 as recursion limit on `Config`.
Add some tests too .

Fixes #5899

Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-01-04 18:38:50 -08:00
Leon
65d0b5b9d9
Make get hole errors and cell path hole errors identical (improvement on #7002) (#7647)
# Description

This closes #7498, as well as fixes an issue reported in
https://github.com/nushell/nushell/pull/7002#issuecomment-1368340773

BEFORE:
```
〉[{foo: 'bar'} {}] | get foo
Error: nu:🐚:column_not_found (link)

  × Cannot find column
   ╭─[entry #5:1:1]
 1 │ [{foo: 'bar'} {}] | get foo
   · ────────┬────────   ─┬─
   ·         │            ╰── value originates here
   ·         ╰── cannot find column 'Empty cell'
   ╰────

〉[{foo: 'bar'} {}].foo
╭───┬─────╮
│ 0 │ bar │
│ 1 │     │
╰───┴─────╯
```
AFTER:
```
〉[{foo: 'bar'} {}] | get foo
Error: nu:🐚:column_not_found (link)

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

〉[{foo: 'bar'} {}].foo
Error: nu:🐚:column_not_found (link)

  × Cannot find column
   ╭─[entry #3:1:1]
 1 │ [{foo: 'bar'} {}].foo
   ·               ─┬  ─┬─
   ·                │   ╰── cannot find column 'foo'
   ·                ╰── value originates here       
   ╰────
```

EDIT: This also changes the semantics of `get`/`select` `-i` somewhat.
I've decided to leave it like this because it works more intuitively
with `default` and `compact`.
BEFORE:
```
〉[{a:1} {b:2} {a:3}] | select -i foo | to nuon
null
```
AFTER:
```
〉[{a:1} {b:2} {a:3}] | select -i foo | to nuon
[[foo]; [null], [null], [null]]
```

# User-Facing Changes

See above. EDIT: the issue with holes in cases like ` [{foo: 'bar'}
{}].foo.0` versus ` [{foo: 'bar'} {}].0.foo` has been resolved.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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-01-02 14:45:43 -08:00
Kangaxx-0
614bc2a943
early return for parsing closure and block with interchanged shape (#7618) 2023-01-01 12:26:51 +02:00
Leon
7aa2a57434
def: make various punctuation misuses into errors (#7624)
Closes https://github.com/nushell/nushell/issues/7604
2022-12-31 13:18:53 +02:00
Jakub Žádník
8bfcea8054
Expand Nushell's help system (#7611) 2022-12-30 17:44:37 +02:00
Jérémy Audiger
f3d2be7a56
doc: correct some really tiny typos. (#7635) 2022-12-30 13:18:28 +01:00
Leon
f5d6672ccf
Disallow ^ in def command names (#7606)
# Description

Closes #7273.

Also slightly edits/tidies up parser.rs.

# User-Facing Changes

`^` is now forbidden in `def` and `def-env` command names. EDIT: also
`alias`.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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.
2022-12-27 15:00:44 -08:00
Kian-Meng Ang
79000aa5e0
Fix typos by codespell (#7600)
# Description

Found via `codespell -S target -L
crate,ser,numer,falsy,ro,te,nd,bu,ndoes,statics,ons,fo,rouge,pard`

# User-Facing Changes

None.

# Tests + Formatting

None and done.

# After Submitting

None.
2022-12-26 02:31:26 -05:00
pwygab
6fc5244439
tighter restrictions on alias and def names (#7392)
# Description

Prevent a situation where a `def` can't be run due to a poor choice of
name. Related: #6335. Hashtags, numbers and filesizes are no longer
allowed. `alias` check has been moved because previously `alias 123`
would be caught but `alias "123"` would be permitted.

# User-Facing Changes

Some definitions can no longer be made, but because they couldn't be run
previously anyway, it doesn't really matter.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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.
2022-12-22 12:31:34 -08:00
Leon
8e1112c1dd
Change other instances of $nothing to null (#7569)
# Description

Purely for consistency, various remaining instances of `$nothing`
(almost all of which were in test code) have been changed to `null`.
Now, the only place that refers to `$nothing` is the parser code which
implements it.

# User-Facing Changes

The default config.nu now uses `null` in certain places where it used
`$nothing`.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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.
2022-12-22 12:30:10 -08:00
Jakub Žádník
23a5c5dc09
Remove shape-directed import pattern parsing (#7570) 2022-12-22 16:36:13 +02:00
Jakub Žádník
d8a2e0e9a3
Small parser refactors (#7568) 2022-12-22 13:41:44 +02:00
Jakub Žádník
757d7479af
Add "fall-through" signatures (#7527)
Fixes https://github.com/nushell/nushell/issues/4659
Fixes https://github.com/nushell/nushell/issues/5294
Fixes https://github.com/nushell/nushell/issues/6124
fix https://github.com/nushell/nushell/issues/5103
2022-12-22 00:33:26 +02:00
Jakub Žádník
3a2c7900d6
Initial support for parse-time constants (#7436) 2022-12-22 00:21:03 +02:00
Stefan Holderbach
d27263af97
Bump to new development version 0.73.1 (#7544) 2022-12-21 12:35:50 -06:00
JT
1291b647ae
bump to 0.73 (#7542)
# 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.
2022-12-20 21:58:48 +13:00
Gavin Foley
98b9839e3d
Fix for escaping backslashes in interpolated strings (fixes #6737) (#7119)
Co-authored-by: Gavin Foley <gavinmfoley@gmail.com>
2022-12-14 07:54:13 -06:00
Darren Schroeder
0db4d89838
add missing shapes to default_config (#7472)
# Description

We've added some shapes recently. This PR adds them to the
default_config and sorts them in order to make finding missing ones
easier.

# 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.
2022-12-14 07:11:17 -06:00
Darren Schroeder
e529746294
sort enums add missing items to parse_shape_name (#7450)
# Description

This PR adds missing items in `parse_shape_name`, sorts the
`SyntaxShape` enum and the `Type` enum. It's a pain to hunt around for
particular items in an enum when they're unsorted.

# 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.
2022-12-13 10:46:22 -06:00
pwygab
0c4d4632ef
let UnknownFlag error list out available flags (#7443)
# Description
Fixes #6773.

```
/home/gabriel/CodingProjects/nushell〉ls -r                                                                                                                             12/12/2022 02:57:35 PM
Error: nu::parser::unknown_flag (link)

  × The `ls` command doesn't have flag `-r`.
   ╭─[entry #1:1:1]
 1 │ ls -r
   ·     ┬
   ·     ╰── unknown flag
   ╰────
  help: Available flags: --help(-h), --all(-a), --long(-l), --short-names(-s), --full-paths(-f), --du(-d), --directory(-D). Use `--help` for more information.
```

# User-Facing Changes

Different error for unknown flag.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` 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.
2022-12-13 06:45:33 -06:00
JT
0c656fd276
Revert "Pipeline operators: && and ||" (#7452)
Reverts nushell/nushell#7448

Some surprising behavior in how we do this. For example:

```
〉if (true || false) { print "yes!" } else { print "no!" }
no!
〉if (true or false) { print "yes!" } else { print "no!" }
yes!
```

This means for folks who are using the old `||`, they possibly get the
wrong answer once they upgrade. I don't think we can ship with that as
it will catch too many people by surprise and just make it easier to
write buggy code.
2022-12-13 16:36:13 +13:00
JT
35bea5e044
Pipeline operators: && and || (#7448)
# Description

We got some feedback from folks used to other shells that `try/catch`
isn't quite as convenient as things like `||`. This PR adds `&&` as a
synonym for `;` and `||` as equivalent to what `try/catch` would do.

# User-Facing Changes

Adds `&&` and `||` pipeline operators.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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.
2022-12-13 09:53:46 +13:00
Jakub Žádník
6b4282eadf
Move 'where' to parser keywords; Add 'filter' command (#7365)
# Description

This PR moves the `where` command to a parser keyword. While it still
uses the shape-directed parsing dictated by the signature, we're free to
change the parsing code now to a custom one once we remove the syntax
shapes.

As a side effect, the `where -b` flag was removed and its functionality
has moved to the new `filter` command.

Just FYI, other commands that take row conditions:
- `take until`
- `take while`
- `skip until`
- `skip while`
- `any`
- `all`

We can either move these to the parser as well or make them accept a
closure instead of row condition.

# User-Facing Changes

New `filter` command which replaces `where -b` functionality.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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.
2022-12-10 19:23:24 +02:00
raccmonteiro
b56ad92e25
++= appendAssign operator (#7346) (#7354)
# Description

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



# Tests + Formatting
```
> mut a = [1 2 3]
> $a ++= [4 5 6]
> $a
[1 2 3 4 5 6]
```
2022-12-09 11:20:58 -05:00
pwygab
fc5fe4b445
ensure error in else is forwarded appropriately (#7411)
# Description

Fixes #7407. 

```
/home/gabriel/CodingProjects/nushell〉if false { 'a' } else { $foo }    12/09/2022 08:14:48 PM
Error: nu::parser::variable_not_found (link)

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

# 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.
2022-12-09 15:48:12 +02:00
JT
379e3d70ca
Better errors when bash-like operators are used (#7241)
# Description

Adds improved errors for when a user uses a bashism that nu doesn't
support.

fixes #7237 

Examples:

```
Error: nu::parser::shell_andand (link)

  × The '&&' operator is not supported in Nushell
   ╭─[entry #1:1:1]
 1 │ ls && ls
   ·    ─┬
   ·     ╰── instead of '&&', use ';' or 'and'
   ╰────
  help: use ';' instead of the shell '&&', or 'and' instead of the boolean '&&'
```

```
Error: nu::parser::shell_oror (link)

  × The '||' operator is not supported in Nushell
   ╭─[entry #8:1:1]
 1 │ ls || ls
   ·    ─┬
   ·     ╰── instead of '||', use 'try' or 'or'
   ╰────
  help: use 'try' instead of the shell '||', or 'or' instead of the boolean '||'
```

```
Error: nu::parser::shell_err (link)

  × The '2>' shell operation is 'err>' in Nushell.
   ╭─[entry #9:1:1]
 1 │ foo 2> bar.txt
   ·     ─┬
   ·      ╰── use 'err>' instead of '2>' in Nushell
   ╰────
```

```
Error: nu::parser::shell_outerr (link)

  × The '2>&1' shell operation is 'out+err>' in Nushell.
   ╭─[entry #10:1:1]
 1 │ foo 2>&1 bar.txt
   ·     ──┬─
   ·       ╰── use 'out+err>' instead of '2>&1' in Nushell
   ╰────
  help: Nushell redirection will write all of stdout before stderr.
```


# User-Facing Changes

**BREAKING CHANGES**

This removes the `&&` and `||` operators. We previously supported by
`&&`/`and` and `||`/`or`. With this change, only `and` and `or` are
valid boolean operators.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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.
2022-12-08 12:02:11 +13:00
JT
fa15a2856a
Add OneOf shape to fix else (#7385)
# Description

fixes #7384 

This is a stop-gap fix until we remove type-directed parsing. With this,
you can create a `OneOf` shape that can be one of a list of syntax
shapes. This gives you a little more control than you get with `Any`,
allowing you to add `Block` without breaking other parsing rules.

# User-Facing Changes

`else` block will no longer capture variables as it will now use a block
instead of a closure.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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.
2022-12-08 08:58:54 +13:00
Leon
9b41f9ecb8
Allow $env and mutable records to be mutated by = (closes #7110) (#7318)
# Description

Closes #7110. ~~Note that unlike "real" `mut` vars, $env can be deeply
mutated via stuff like `$env.PYTHON_IO_ENCODING = utf8` or
`$env.config.history.max_size = 2000`. So, it's a slightly awkward
special case, arguably justifiable because of what $env represents (the
environment variables of your system, which is essentially "outside"
normal Nushell regulations).~~
EDIT: Now allows all `mut` vars to be deeply mutated using `=`, on
request.

# 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.
2022-12-06 19:51:55 +02:00
Darren Schroeder
017a13fa3f
bump to dev build v0.72.2 (#7360)
# Description

After the 0.72.1 hotfix, let's bump our dev builds to 0.72.2.

# 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.
2022-12-05 14:18:06 -06:00
Daniel Buch Hansen
850ecf648a
Protocol: debug_assert!() Span to reflect a valid slice (#6806)
Also enforce this by #[non_exhaustive] span such that going forward we
cannot, in debug builds (1), construct invalid spans.

The motivation for this stems from #6431 where I've seen crashes due to
invalid slice indexing.

My hope is this will mitigate such senarios

1. https://github.com/nushell/nushell/pull/6431#issuecomment-1278147241

# Description

(description of your pull request here)

# Tests

Make sure you've done the following:

- [ ] Add tests that cover your changes, either in the command examples,
the crate/tests folder, or in the /tests folder.
- [ ] Try to think about corner cases and various ways how your changes
could break. Cover them with tests.
- [ ] If adding tests is not possible, please document in the PR body a
minimal example with steps on how to reproduce so one can verify your
change works.

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)
- [ ] `cargo clippy --workspace --features=extra -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect` to check that you're
using the standard code style
- [ ] `cargo test --workspace --features=extra` to check that all the
tests pass

# Documentation

- [ ] If your PR touches a user-facing nushell feature then make sure
that there is an entry in the documentation
(https://github.com/nushell/nushell.github.io) for the feature, and
update it if necessary.
2022-12-03 11:44:12 +02:00
Stefan Holderbach
a9e6b1ec6b
Add did-you-mean suggestions for bitwise ops (#7252)
Continues work from #7251 to include the bitwise operations.
Covers the C style conventions as well as the typo `bits-*` instead of
`bit-*`
2022-12-01 11:34:41 +01:00
David Matos
fd503fceaf
allow tables in ++ operator (#7051)
This PR closes #6916, which now allows table/table operations on the
`++` operator.
```
[[a b]; [1 2]] ++ [[a b]; [1 3]]
╭───┬───┬───╮
│ # │ a │ b │
├───┼───┼───┤
│ 0 │ 1 │ 2 │
│ 1 │ 1 │ 3 │
╰───┴───┴───╯
```
2022-12-01 00:21:59 +01:00
Darren Schroeder
3caab5de36
bump to dev release v0.72.1 (#7281)
# Description

Just bumping to the next dev version. Submitting as a draft until we're
ready.

# 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.
2022-11-30 16:06:22 -06:00
JT
9c800bcb2c
bump to 0.72 (#7272)
# 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.
2022-11-29 20:17:23 +13:00
Stefan Holderbach
c4d2b787aa
Add did-you-mean suggestions for operators (#7251)
# Description

Adds a `ParseError::UnkownOperator` and covers `^`,`pow`,`is`,`===`,`%`,
and `contains` as likely operators based on other languages. Provides
suggestion for the user to find the nu language feature they are looking
for.


![image](https://user-images.githubusercontent.com/15833959/204108373-d1165988-ad87-4a2e-bd81-b67a44072571.png)


# Tests + Formatting

(-)
2022-11-27 10:59:43 +13:00
Access
9850fbd77d
chore: chrono_update (#7132)
chrono version update

# Description

upgrade chrono to 0.4.23

# Major Changes

If you're considering making any major change to nushell, before
starting work on it, seek feedback from regular contributors and get
approval for the idea from the core team either on
[Discord](https://discordapp.com/invite/NtAbbGn) or [GitHub
issue](https://github.com/nushell/nushell/issues/new/choose).
Making sure we're all on board with the change saves everybody's time.
Thanks!

# Tests + Formatting

Make sure you've done the following, if applicable:

- Add tests that cover your changes (either in the command examples, the
crate/tests folder, or in the /tests folder)
- Try to think about corner cases and various ways how your changes
could break. Cover those in the tests

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

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

# After Submitting

* Help us keep the docs up to date: If your PR affects the user
experience of Nushell (adding/removing a command, changing an
input/output type, etc.), make sure the changes are reflected in the
documentation (https://github.com/nushell/nushell.github.io) after the
PR is merged.

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2022-11-27 07:19:02 +13:00
Stefan Holderbach
2ccb91dc6a
Add logical xor operator (#7242)
We already have the binary `bit-xor` and the shortcircuiting logical
`or`(`||`) and `and`(`&&`).
This introduces `xor` as a compact form for both brevity and clarity.
You can express the operation through `not`/`and`/`or` with a slight
risk of introducing bugs through typos.

Operator precedence

`and` > `xor` > `or`

Added logic and precedence tests.
2022-11-26 17:02:37 +01:00
Jakub Žádník
2388e1e80b
Reorder export-env eval and allow reloading an overlay (#7231)
# Description

This PR is a response to the issues raised in
https://github.com/nushell/nushell/pull/7087. It consists of two
changes:
* `export-env`, when evaluated in `overlay use`, will see the original
environment. Previously, it would see the environment from previous
overlay activation.
* Added a new `--reload` flag that reloads the overlay. Custom
definitions will be kept but the original definitions and environment
will be reloaded.

This enables a pattern when an overlay is supposed to shadow an existing
environment variable, such as `PROMPT_COMMAND`, but `overlay use` would
keep loading the value from the first activation. You can easily test it
by defining a module
```
module prompt {
    export-env {
        let-env PROMPT_COMMAND = (date now | into string)
    }
}
```
Calling `overlay use prompt` for the first time changes the prompt to
the current time, however, subsequent calls of `overlay use` won't
change the time. That's because overlays, once activated, store their
state so they can be hidden and restored at later time. To force-reload
the environment, use the new flag: Calling `overlay use --reload prompt`
repeatedly now updates the prompt with the current time each time.

# User-Facing Changes

* When calling `overlay use`, if the module has an `export-env` block,
the block will see the environment as it is _before_ the overlay is
activated. Previously, it was _after_.
* A new `overlay use --reload` flag.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` 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.
2022-11-24 23:45:24 +01:00
JT
93202d4529
Remove And and Or pipeline elements (#7229)
# Description

Since we're not implementing `&&` or `||`, let's remove their pipeline
elements.

# User-Facing Changes

Nothing user facing. These were not yet implemented.

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` 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.
2022-11-25 07:06:12 +13:00
JT
8cca447e8c
A set of fixes for stderr redirect (#7219)
# Description

This is a set of fixes to `err>` to make it work a bit more predictably.

I've also revised the tests, which accidentally tested the wrong thing
for redirection, but should be more correct now.

# 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.
2022-11-24 16:58:15 +13:00
nibon7
0c38729735
Apply clippy fix (#7193)
# Description

rust 1.65.0 has been released for a while, this pr applies lint
suggestions from rust 1.65.0.

# User-Facing Changes

N/A

# Tests + Formatting

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

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace --features=extra -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect` to check that you're
using the standard code style
- `cargo test --workspace --features=extra` 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.
2022-11-23 16:57:27 +13:00
WindSoilder
b662c2eb96
Make external command substitution works friendly(like fish shell, trailing ending newlines) (#7156)
# Description

As title, when execute external sub command, auto-trimming end
new-lines, like how fish shell does.

And if the command is executed directly like: `cat tmp`, the result
won't change.

Fixes: #6816
Fixes: #3980


Note that although nushell works correctly by directly replace output of
external command to variable(or other places like string interpolation),
it's not friendly to user, and users almost want to use `str trim` to
trim trailing newline, I think that's why fish shell do this
automatically.

If the pr is ok, as a result, no more `str trim -r` is required when
user is writing scripts which using external commands.

# User-Facing Changes
Before:
<img width="523" alt="img"
src="https://user-images.githubusercontent.com/22256154/202468810-86b04dbb-c147-459a-96a5-e0095eeaab3d.png">

After:
<img width="505" alt="img"
src="https://user-images.githubusercontent.com/22256154/202468599-7b537488-3d6b-458e-9d75-d85780826db0.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 --features=extra -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect` to check that you're
using the standard code style
- `cargo test --workspace --features=extra` 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.
2022-11-23 16:51:57 +13:00
JT
74a73f9838
Stdout/Stderr redirection (#7185)
This adds new pipeline connectors called out> and err> which redirect either stdout or stderr to a file. You can also use out+err> (or err+out>) to redirect both streams into a file.
2022-11-23 07:26:13 +13:00
JT
6454bf69aa
Parser refactoring for improving pipelines (#7162)
* Remove lite_parse file

* Add LiteElement to represent different pipeline elem types

* Add PipelineElement to Pipelines

* Remove lite_parse specific tests
2022-11-19 10:46:48 +13:00
Filip Andersson
817eacccd8
removes unused features. (#6938)
* removes unused features.

* Adds back multithreading feature to sysinfo.

* Adds back alloc for percent-encoding

* Adds updated lock file.

* Missed one sysinfo.

* `indexmap` just defaults

* Revert `miette``default-features=false`

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
2022-11-12 18:44:56 +13:00
JT
c1105e945e
Add additional assignment operators (#7102) 2022-11-12 07:50:43 +13:00
JT
69b089845c
Add support for while loops (#7101) 2022-11-12 07:21:45 +13:00
JT
13515c5eb0
Limited mutable variables (#7089)
This adds support for (limited) mutable variables. Mutable variables are created with mut much the same way immutable variables are made with let.

Mutable variables allow mutation via the assignment operator (=).

❯ mut x = 100
❯ $x = 200
❯ print $x
200

Mutable variables are limited in that they're only tended to be used in the local code block. Trying to capture a local variable will result in an error:

❯ mut x = 123; {|| $x }
Error: nu::parser::expected_keyword (link)

  × Capture of mutable variable.

The intent of this limitation is to reduce some of the issues with mutable variables in general: namely they make code that's harder to reason about. By reducing the scope that a mutable variable can be used it, we can help create local reasoning about them.

Mutation can occur with fields as well, as in this case:

❯ mut y = {abc: 123}
❯ $y.abc = 456
❯ $y

On a historical note: mutable variables are something that we resisted for quite a long time, leaning as much as we could on the functional style of pipelines and dataflow. That said, we've watched folks struggle to work with reduce as an approximation for patterns that would be trivial to express with local mutation. With that in mind, we're leaning towards the happy path.
2022-11-11 19:51:08 +13:00
JT
18d7e64660
Convert 'for' to a statement (#7086) 2022-11-11 09:05:34 +13:00
JT
63433f1bc8
Split blocks and closures (#7075)
* Split closures and blocks

* Tests mostly working

* finish last fixes, passes all tests

* fmt
2022-11-10 21:21:49 +13:00
Darren Schroeder
2b9f258126
bump to dev release 0.71.1 (#7064) 2022-11-09 13:18:34 +01:00
JT
6cc4ef6c70
bump to 0.71, use 1.63 toolchain (#7061) 2022-11-09 06:54:00 +13:00
Darren Schroeder
a6118eed8d
Revert "Fix for escaping backslashes in interpolated strings (fixes #6737) (#7020)" (#7038)
This reverts commit d4798d6ee1.
2022-11-06 16:17:00 -06:00
Gavin Foley
d4798d6ee1
Fix for escaping backslashes in interpolated strings (fixes #6737) (#7020)
Co-authored-by: Gavin Foley <gavinmfoley@gmail.com>
2022-11-07 08:57:28 +13:00
Alex Saveau
be5d71ea47
Run a round of clippy --fix to fix a ton of lints (#7006)
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-11-04 15:11:17 -05:00
Stefan Holderbach
92ab8b831b
Reduce required dependencies for diagnostics (#6648)
Disable backtrace on miette
- gimli crate requires several seconds
Disable diagnostics on wax
- depends on an outdated miette version

Builds fine, no observable loss in diagnostics quality of life

Removes 10 crates that have to be compiled.
2022-10-24 21:42:32 +02:00
Stefan Holderbach
6a7a60429f
Remove unnecessary #[allow(...)] annotations (#6870)
* Remove unnecessary `#[allow]` annots

Reduce the number of lint exceptions that are not necessary with the
current state of the code (or more recent toolchain)

* Remove dead code from `FileStructure` in nu-command

* Replace `allow(unused)` with relevant feature switch

* Deal with `needless_collect` with annotations

* Change hack for needless_collect in `from json`

This change obviates the need for `allow(needless_collect)`
Removes a pessimistic allocation for empty strings, but increases
allocation size to `Value`

Probably not really worth it.

* Revert "Deal with `needless_collect` with annotations"

This reverts commit 05aca98445.

The previous state seems to better from a performance perspective as a
`Vec<String>` is lighter weight than `Vec<Value>`
2022-10-24 20:12:16 +02:00
pwygab
5e748ae8fc
make ++ append lists (#6766)
* make `++` append lists

* fmt

* fix for database
2022-10-20 23:28:18 +13:00
Darren Schroeder
a724a8fe7d
bump to dev version 0.70.1 (#6814) 2022-10-20 18:04:10 +13:00
JT
9ef65dcd69
Bump to 0.70 (#6800) 2022-10-19 07:13:36 +13:00
pwygab
5849e4f6e3
let alias list aliases (#6717)
* let `alias` list aliases

* fix highlighting

* Update parse_keywords.rs
2022-10-14 21:51:44 +02:00
pwygab
90ba39184a
allow for $in to affect environment (#6649)
* allow for `$in` to affect environment

* fix for vars, overlays, env_hidden

* fmt

* carry over variables properly

* add test

* modify name, remove redundant

* fmt
2022-10-13 12:04:34 +03:00
Darren Schroeder
6486364610
changed the way durations and filesizes are parsed (#6640) 2022-09-29 13:24:17 -05:00
pwygab
1a3762b905
prevent alias name from being filesize or number (#6595)
* prevent alias name from being filesize or number

* add test

* fmt
2022-09-28 17:08:38 -05:00
Darren Schroeder
dd578926c3
add some float operations with filesize (#6618)
* add some float operations with filesize

* more changes

* update return values on filesize-filesize, duration-duration

* missed filesize in floordiv

* missed float * duration
2022-09-28 17:07:50 -05:00
Darren Schroeder
23bba9935f
bump to dev version 0.69.2 (#6635) 2022-09-28 17:06:21 -05:00
JT
8a5abc7afc
bump to 0.69.1 (#6631) 2022-09-28 15:48:01 +13:00
JT
3beaca0d06
bump to 0.69 (#6623) 2022-09-28 07:14:31 +13:00
JT
d66a5398d1
Remove month and year duration constants (#6613)
remove month/year/decade durations for parsing and units, but leave the humanized output for viewing
2022-09-26 09:55:13 +13:00
WindSoilder
b47bd22b37
Removes export env command (#6468)
* remove export_env command

* remove several export env usage in test code

* adjust hiding relative test case

* fix clippy

* adjust tests

* update tests

* unignore these tests to expose ut failed

* using `use` instead of `overlay use` in some tests

* Revert "using `use` instead of `overlay use` in some tests"

This reverts commit 2ae24b24c3.

* Revert "adjust hiding relative test case"

This reverts commit 4369af6d05.

* Bring back module example

* Revert "update tests"

This reverts commit 6ae94ef513.

* Fix tests

* "Fix" a test

* Remove remaining deprecated env functionality

* Re-enable environment hiding for `hide`

To not break virtualenv since the overlay update is not merged yet

* Fix hiding env in `hide` and ignore some tests

Co-authored-by: kubouch <kubouch@gmail.com>
2022-09-25 19:52:43 +03:00
WindSoilder
5491634dda
escape external args (#6560) 2022-09-17 06:07:45 -05:00
Justin Ma
4490e97a13
Bump dev version to v0.68.2 (#6538) 2022-09-12 08:29:39 +12:00
Jakub Žádník
e76b3d61de
Require static path for source-env (#6526) 2022-09-08 23:41:49 +03:00
pwygab
b398448cd9
Stop panic when typing module spam { export def-env (#6523)
* Stop `panic` when typing `module spam { export def-env`

same goes for `export extern` and `export alias`

* fmt
2022-09-08 12:27:11 +03:00
WindSoilder
aa92141ad7
Remove --encoding argument during register plugin (#6486)
* first implement new plugin protocol core logic

* fix debug body construct

* fix output message from plugin

* finish plugin commands calling

* fix tests and adjust plugin_custom_value call

* fmt code

* fmt code, fix clippy

* add FIXME comment

* change from FIXME to TODO
2022-09-07 09:07:42 -05:00
Justin Ma
c902d8bc0c
bump dev version to v0.68.1 (#6504) 2022-09-07 14:27:33 +12:00
JT
9273bb3f72
bump to 0.68 (#6501) 2022-09-07 06:29:01 +12:00
JT
d86350af80
Revert "Make $ on variable names optional (#6434)" (#6446)
This reverts commit 3cb9147f22.
2022-09-06 05:42:47 +12:00
WindSoilder
a6ba58ec41
restrict plugin file name (#6479) 2022-09-04 18:00:20 -05:00
Jakub Žádník
65327e0e7e
Disable cyclical module imports (#6477) 2022-09-04 23:19:20 +03:00
Jakub Žádník
f46962d236
Fix scoped overlay use not finding a module (#6474)
* Add source-env test for dynamic path

* Use correct module ID for env overlay imports

* Remove parser check from "overlay list"

It would cause unnecessary errors from some inner scope if some
overlay module was also defined in some inner scope.

* Restore Cargo.lock back

* Remove comments
2022-09-04 18:36:42 +03:00
WindSoilder
3ec53e544c
remove capnp protocol for plugin... (#6421)
* remove capnp protocol for plugin...

* remove relative doc
2022-08-31 17:33:30 -05:00
JT
c52d45cb97
Move from source to source-env (#6277)
* start working on source-env

* WIP

* Get most tests working, still one to go

* Fix file-relative paths; Report parser error

* Fix merge conflicts; Restore source as deprecated

* Tests: Use source-env; Remove redundant tests

* Fmt

* Respect hidden env vars

* Fix file-relative eval for source-env

* Add file-relative eval to "overlay use"

* Use FILE_PWD only in source-env and "overlay use"

* Ignore new tests for now

This will be another issue

* Throw an error if setting FILE_PWD manually

* Fix source-related test failures

* Fix nu-check to respect FILE_PWD

* Fix corrupted spans in source-env shell errors

* Fix up some references to old source

* Remove deprecation message

* Re-introduce deleted tests

Co-authored-by: kubouch <kubouch@gmail.com>
2022-09-01 08:32:56 +12:00
JT
a03fb946d9
Allow parens around signatures (#6444)
* DRAFT: make var dollar optional

* couple fixes

* fix some tests + cleanup

* allow parens around signature

* clippy
2022-08-30 16:17:10 +12:00
JT
3cb9147f22
Make $ on variable names optional (#6434)
* DRAFT: make var dollar optional

* couple fixes

* fix some tests + cleanup
2022-08-29 14:35:55 +12:00
Jakub Žádník
34d7c17e78
Bring module's environment when activating overlay (#6425) 2022-08-27 01:32:19 +03:00
Jakub Žádník
d97975e9fa
Allow "export-env" parsing in modules (#6382)
* Allow "export-env" parsing in modules

* Fmt

* Add test for importing module's environment
2022-08-23 10:45:17 +03:00
Jakub Žádník
7ef4e5f940
Allow parsing modules as scripts (#6357)
* Allow parsing modules as scripts

* Remove 'export env' from the supported keywords

* Add test for export in blocks; Allow "export use"

* Allow evaluating "export alias"

* Fmt; Clippy

* Allow running "export extern" in scripts
2022-08-23 00:19:47 +03:00
WindSoilder
9c4bbe3c63
Rename overlay commands (#6375)
* rename from overlay add to overlay use

* rename from overlay remove to overlay hide

* rename add to use_
2022-08-21 17:27:56 +03:00
Darren Schroeder
5337a6dffa
add MessagePack as a plugin protocol (#6370) 2022-08-21 06:13:38 -05:00
Justin Ma
4bbdb73668
Bump dev version (#6350) 2022-08-18 21:14:17 +12:00
JT
33674d3a98
bump to 0.67 (#6336) 2022-08-17 05:47:47 +12:00
Richard Braakman
6145f734b7
Add repository info to all workspace crates (#6320)
This helps people who find these crates on crates.io
2022-08-14 07:21:20 -05:00
Reilly Wood
613d2fb8df
Bump chrono dependency to fix panic (#6317) 2022-08-13 11:21:28 -07:00
Jakub Žádník
8783742060
Add 'as' keyword to 'overlay add' (#6314) 2022-08-13 17:28:18 +03:00
Jakub Žádník
c3efb12733
Allow overlays to import prefixed definitions (#6301)
* WIP

* Fix overlay prefix not preserving correctly

* Work around failing REPL tests

* Remove wrong code when removing with --keep-custom
2022-08-12 21:06:51 +03:00
Stefan Holderbach
c2f4969d4f
Clippy fix for Rust 1.63 (#6299)
Take more sensitive lints into account

Somewhat ugly in some cases is the replacement of `.get(0)` with
`.first()`
2022-08-11 11:54:54 -05:00
JT
121b801baa
bump dev version ahead of language changes (#6267) 2022-08-09 08:15:41 +12:00
WindSoilder
aaf5684f9c
when spawned process during register plugin, pass env to child process (#6261)
* when spawned process during register plugin, pass env to child process

* tweak comment

* tweak comment

* remove trailing whitespace

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2022-08-08 07:26:49 -05:00
Justin Ma
cc99df5ef1
upgrade chrono to v0.4.20 (#6235) 2022-08-05 06:53:01 -05:00
Kangaxx-0
ebf845f431
Change how to identify custom comamnd (#6187)
Co-authored-by: Frank <v-frankz@microsoft.com>
2022-08-02 18:40:07 -05:00
pwygab
233afebdf0
allow -h flags for export subcommands (#6189)
* allow `-h` flags for `export` subcommands

* remove unnecessary check

* add tests

* fmt
2022-08-02 10:26:16 -05:00
Jakub Žádník
d6f4189c7b
Fix file lookup in parser keywords; Refactor nu_repl (#6185)
* Fix file lookup in parser keywords

* Make nu_repl a testbin; Fix wrong cwd test error
2022-07-29 23:42:00 +03:00
Justin Ma
767201c40d
bump to 0.66.3 dev version (#6183) 2022-07-30 05:48:10 +12:00
Jakub Žádník
2cffff0c1b
Allow modules to use other modules (#6162)
* Allow private imports inside modules

Can call `use ...` inside modules now.

* Add more tests

* Add a leak test

* Refactor exportables; Prepare for 'export use'

* Fix description

* Implement 'export use' command

This allows re-exporting module's commands and aliases from another
module.

* Add more tests; Fix import pattern list strings

The import pattern strings didn't trim the surrounding quotes.

* Add ignored test
2022-07-29 11:57:10 +03:00
Jakub Žádník
c9d0003818
Quickly patch wrong 'export' command name (#6168)
It was looked up as `alias` which explains issue #6167. Proper fix is still needed to enable the -h flag for `export` subcommands.
2022-07-28 21:06:50 +03:00
JT
e049ca8ebf
bump to 0.66.2 dev version (#6157) 2022-07-28 11:38:52 +12:00
Jakub Žádník
c92211c016
Use relative paths as file-relative when parsing a file (#6150)
* Make function local (not used anywhere else)

* Use path relative to the parsed file

* Do not use real cwd at all
2022-07-27 18:36:56 +03:00
JT
c8adb06ca7
fix var names coming from long/short flags (#6142) 2022-07-27 19:27:28 +12:00
JT
9695331eed
require variable names to follow additional restrictions (#6125) 2022-07-27 14:08:54 +12:00
JT
d42cfab6ef
bump to 0.66.1 dev version (#6140) 2022-07-27 13:15:04 +12:00
JT
c6cb491e77
bump to 0.66 (#6137) 2022-07-27 07:56:14 +12:00
Darren Schroeder
d856ac92f4
expand durations to include month, year, decade (#6123)
* expand durations to include month, year, decade

* remove commented out fn

* oops, found more debug comments

* tweaked tests for the new way, borrowed heavily from chrono-humanize-rs

* clippy

* grammar
2022-07-26 08:05:37 -05:00
JT
475d32045f
Revert "Refactor external command (#6083)" (#6116)
This reverts commit 0646f1118c.
2022-07-26 05:37:15 +12:00
Kangaxx-0
0646f1118c
Refactor external command (#6083)
Co-authored-by: Frank <v-frankz@microsoft.com>
2022-07-21 19:56:57 -04:00
Kangaxx-0
eeaca50dee
Conditionally disable expansion for external command (#6014)
* Fix 5978

* Add unit test for explicit glob

* Format

* Expansion vs none-expansion

* Add unit tests

* Fix format..

* Add debug message for MacOS

* Fix UT on Mac and add tests for windows

* cleanup

* clean up windows test

* single and double qoutes tests

* format...

* Save format.

* Add log to failed windows unit tests

* try `touch` a file

* PS or CMD

* roll back some change

* format

* Remove log and test case

* Add unit test comments

* Fix

Co-authored-by: Frank <v-frankz@microsoft.com>
2022-07-17 16:30:33 -05:00
Jack Clayton
9ced5915ff
Fix short-flag completion (#6067) 2022-07-17 07:46:40 -05:00
Jakub Žádník
26f31da711
Split merging of parser delta and stack environment (#6005)
* Remove comment

* Split delta and environment merging

* Move table mode to a more logical place

* Cleanup

* Merge environment after reading default_env.nu

* Fmt
2022-07-14 17:09:27 +03:00
pwygab
f85a1d003c
throw parser error when multiple short flags are defined without whitespace (#6000)
* throw error when multiple short flags are defined without whitespace

* add tests
2022-07-10 20:32:52 +12:00
Justin Ma
de162c9aea
Bump to 0.65.1 dev version (#5962) 2022-07-06 16:25:09 +12:00
JT
0d40d0438f
bump to 0.65 (#5952) 2022-07-05 17:54:16 +12:00
Justin Ma
4e90b478b7
Add bit operator: bit-xor (#5940) 2022-07-03 06:45:20 -05:00
JT
a48616697a
Rename bitwise operators for readability (#5937) 2022-07-02 17:05:02 -05:00
Justin Ma
b82dccf0bd
Add band and bor operator for bit operations (#5936)
* Add `band` and `bor` Operator

* Add tests
2022-07-02 13:03:36 -05:00
Justin Ma
3917fda7ed
Update #4202: Add shift operator bshl and bshr for integers (#5928)
* Update #4202: Add shift operator bshl and bshr for integers

* Add more tests
2022-07-02 06:48:43 -05:00
Michael Angerman
58fa2e51a2
update crate thiserror to version 1.0.31 in crates nu-cli, nu-command, nu-parser, nu-protocol (#5919) 2022-06-30 13:55:01 -07:00
pwygab
a0db4ce747
Better error handling using do (#5890)
* adds `capture-errors` flag for `do`

* adds `get-type` core command to get type

* fmt

* add tests in example

* fmt

* fix tests

* manually revert previous changes related to `get-type`

* adds method to check for error name using `into string`

* fix clippy
2022-06-29 20:01:34 -05:00
Benoît Cortier
228ede18cf
build: update miette dependency (#5889) 2022-06-26 07:03:38 -05:00
JT
f2989bf704
Move input/output type from Command to Signature (#5880) 2022-06-26 09:23:56 +12:00
JT
575ddbd4ef
Clippy and remove unused is_binary (#5879) 2022-06-26 08:20:28 +12:00
pwygab
1345f97202
Errors when let in, let env and similar commands are passed. (#5866)
* throw `let nu/env/nothing/in` error in parsing

* add tests and fmt

* fix clippy

* suggestions

* fmt

* `lvalue.span` instead of `spans[1]`

* clippy

* fmt
2022-06-25 00:55:25 +03:00
JT
533e04a60a
Bump to 0.64.1 dev version (#5865) 2022-06-24 16:47:00 +12:00
Fernando Herrera
44cbd88b55
allow comparison for similar types (#5844) 2022-06-21 12:15:31 -05:00
Reilly Wood
2caa44cea8
Fix parser panic (#5820) 2022-06-17 11:11:48 -07:00
JT
d1c719a8cc
bump to 0.64 (#5777)
Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
2022-06-15 14:39:17 +12:00
Fernando Herrera
8d5848c955
bool type for binary operations (#5779)
* bool type for binary operations

* fixed type in commands
2022-06-14 20:31:14 -05:00
pwygab
caafd26deb
Attempts to add // math operator (#5759)
* attempts to add `div` math operator

* allows `//` to be used too

* fmt:

* clippy issue

* returns appropriate type

* returns appropriate type 2

* fmt

* ensure consistency; rename to `fdiv`

* Update parser.rs
2022-06-13 13:54:47 +03:00
Fernando Herrera
11d7d8ea1e
Remove dfr from dataframe commands (#5760)
* input and output tests

* input and output types for dfr

* expression converter

* remove deprecated command

* correct expressions

* cargo clippy

* identifier for ls

* cargo clippy

* type for head and tail expression

* modify full cell path if block
2022-06-12 14:18:00 -05:00
WindSoilder
2dea9e6f1f
fix arg parse (#5754)
* fix arg parse

* add ut, fix clippy

* simplify code

* fmt code
2022-06-11 20:52:31 +12:00
Fernando Herrera
d5b99ae316
input and output types (#5750)
* input and output types

* added description

* type from stored variable

* string in custom value

* more tests with non custom
2022-06-10 10:59:35 -05:00
WindSoilder
75b2d26187
fix argument type (#5695)
* fix argument type

* while run external, convert list argument to str

* fix argument converting logic

* using parse_list_expression instead of parse_full_cell_path

* make parsing logic more explicit

* revert changes

* add tests
2022-06-06 13:19:06 +03:00
Stefan Holderbach
e5d38dcff6
Address lints from clippy for beta/nightly (#5709)
* Fix clippy lints in tests

* Replace `format!` in `.push_str()` with `write!`

Stylistically that might be a bit rough but elides an allocation.

Fallibility of allocation is more explicit, but ignored with `let _ =`
like in the clippy example:

https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string

* Remove unused lifetime

* Fix macro crate relative import

* Derive `Eq` for `PartialEq` with `Eq` members

https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq

* Remove unnnecessary `.to_string()` for Cow<str>

* Remove `.to_string()` for `tendril::Tendril`

Implements `Deref<Target = str>`
2022-06-04 18:47:36 +12:00
Stefan Holderbach
e2c015f725
Clarify error message for let in pipeline (#5677)
Refer to the suggestion as an assignment
2022-05-30 09:26:33 +02:00
pwygab
eb12fffbc6
prevent panic with let alone in pipeline (#5676)
* prevent panic with `let` alone in pipeline

* Update parser.rs
2022-05-29 22:16:41 +02:00
Clements
46eb34b35d
Differentiate internal signature from external signature w.r.t. help (#5667)
* Differentiate internal signature from external signature w.r.t. help

* Add in the --help flag to default externs in default config

* Remove unusued build_extern

Co-authored-by: mjclements <clements.michael.james@gmail.com>
2022-05-29 15:14:15 +02:00
Jakub Žádník
2042f7f769
Add 'overlay new' command (#5647)
* Add 'overlay new' command

* Add missing file
2022-05-26 17:47:04 +03:00
pwygab
3d62528d8c
Makes a more helpful error for let in pipeline (#5632)
* a more helpful error for let in pipeline

* a more helpful error for let in pipeline fmt

* changed help message

* type-o

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2022-05-25 19:13:14 -05:00
JT
8e98df8b28
bump to dev version (#5635) 2022-05-25 19:09:44 -05:00
JT
06cf3fa5ad
Bump to 0.63 (#5627) 2022-05-25 11:33:28 +12:00
Jakub Žádník
9a482ce284
Overlay keep (#5629)
* Allow env vars to be kept from removed overlay

* Rename --keep to --keep-custom; Add new test

* Rename some symbols

* (WIP) Start working on --keep for defs and aliases

* Fix decls/aliases not melting properly

* Use id instead of the whole cloned overlay

* Rewrite overlay remove for no reason

Doesn't fix the bug but at least looks better.

* Rename variable

* Fix adding overlay env vars

* Add more tests; Fmt + Clippy
2022-05-25 09:22:17 +12:00
Jason Toffaletti
98a4280c41
Add octal binary literals (#5604)
Schema `0o[77]` with the same padding behavior as the other binary literals

- this updates #5551
- test for parsing binary from octal
- test for string parsing
2022-05-23 11:01:15 +02:00
pwygab
6c56829976
Allowing for flags with '=' in them to register as flags. (#5579)
* hacky fix for registering flags with '='

* fmt
2022-05-18 11:26:58 -05:00
WindSoilder
5fa42eeb8c
Make format support nested column and use variable (#5570)
* fix format for nested structure

* make little revert

* add tests

* fix format

* better comment

* make better comment
2022-05-18 06:08:43 -05:00
Emilien Fugier
498672f5e5
feat(errors): more explicit module_or_overlay_not_found_error help message (#5564) 2022-05-17 06:22:31 -05:00
JT
e192684612
Revert "Try to do less work during capture discovery (#5560)" (#5561)
This reverts commit 5d40fc2726.
2022-05-17 10:49:59 +12:00
JT
5d40fc2726
Try to do less work during capture discovery (#5560) 2022-05-17 09:05:26 +12:00
pwygab
f311da9623
Adds fix for when multiple flags are in one line. (#5493) 2022-05-10 06:13:19 -05:00
pwygab
8d8f25b210
Fixing the flag issue (#5447)
* Fixing the flag issue

* whoops, forgot the original point of the function

* Update deparse.rs

* Update deparse.rs

* Update deparse.rs

* maybe this might work

* fmt

* quotation marks works now due to a rigorous check for args.

* fmt and clippy

* kept the original escape_quote_string(), escaped " and \

* removed script.nu

* Added appropriate comments.
2022-05-09 07:01:58 -05:00
JT
374757f286
Bump to the 0.62.1 dev version (#5473) 2022-05-08 08:38:12 +12:00
Jakub Žádník
9b99b2f6ac
Overlays (#5375)
* WIP: Start laying overlays

* Rename Overlay->Module; Start adding overlay

* Revamp adding overlay

* Add overlay add tests; Disable debug print

* Fix overlay add; Add overlay remove

* Add overlay remove tests

* Add missing overlay remove file

* Add overlay list command

* (WIP?) Enable overlays for env vars

* Move OverlayFrames to ScopeFrames

* (WIP) Move everything to overlays only

ScopeFrame contains nothing but overlays now

* Fix predecls

* Fix wrong overlay id translation and aliases

* Fix broken env lookup logic

* Remove TODOs

* Add overlay add + remove for environment

* Add a few overlay tests; Fix overlay add name

* Some cleanup; Fix overlay add/remove names

* Clippy

* Fmt

* Remove walls of comments

* List overlays from stack; Add debugging flag

Currently, the engine state ordering is somehow broken.

* Fix (?) overlay list test

* Fix tests on Windows

* Fix activated overlay ordering

* Check for active overlays equality in overlay list

This removes the -p flag: Either both parser and engine will have the
same overlays, or the command will fail.

* Add merging on overlay remove

* Change help message and comment

* Add some remove-merge/discard tests

* (WIP) Track removed overlays properly

* Clippy; Fmt

* Fix getting last overlay; Fix predecls in overlays

* Remove merging; Fix re-add overwriting stuff

Also some error message tweaks.

* Fix overlay error in the engine

* Update variable_completions.rs

* Adds flags and optional arguments to view-source (#5446)

* added flags and optional arguments to view-source

* removed redundant code

* removed redundant code

* fmt

* fix bug in shell_integration (#5450)

* fix bug in shell_integration

* add some comments

* enable cd to work with directory abbreviations (#5452)

* enable cd to work with abbreviations

* add abbreviation example

* fix tests

* make it configurable

* make cd recornize symblic link (#5454)

* implement seq char command to generate single character sequence (#5453)

* add tmp code

* add seq char command

* Add split number flag in `split row` (#5434)

Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com>

* Add two more overlay tests

* Add ModuleId to OverlayFrame

* Fix env conversion accidentally activating overlay

It activated overlay from permanent state prematurely which would
cause `overlay add` to misbehave.

* Remove unused parameter; Add overlay list test

* Remove added traces

* Add overlay commands examples

* Modify TODO

* Fix $nu.scope iteration

* Disallow removing default overlay

* Refactor some parser errors

* Remove last overlay if no argument

* Diversify overlay examples

* Make it possible to update overlay's module

In case the origin module updates, the overlay add loads the new module,
makes it overlay's origin and applies the changes. Before, it was
impossible to update the overlay if the module changed.

Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com>
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Co-authored-by: WindSoilder <WindSoilder@outlook.com>
Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
2022-05-08 07:39:22 +12:00
Reilly Wood
08e495ea67
Enable string interpolation for environment shorthand (#5463) 2022-05-07 06:21:29 -05:00
Tom
02a3430ef0
Use correct ParseError (#5431) 2022-05-05 07:41:32 +12:00
JT
d306b834ca
Bump to 0.62 (#5422) 2022-05-04 09:01:27 +12:00
JT
e36649f74b
Update path completions to handle spaces (#5419) 2022-05-03 12:37:38 +12:00
panicbit
49cbc30974
Add ends-with operator and fix dataframe operator behavior (#5395)
* add ends-with operator

* escape needles in dataframe operator regex patterns
2022-05-02 20:02:38 +12:00
JT
4a69819f9a
Rename =^ to 'starts-with' (#5407) 2022-05-02 19:20:07 +12:00
JT
92785ab92c
Add unescaping to external command parsing (#5399) 2022-05-02 07:26:29 +12:00
JT
98ab31e15e
Move uses of trim_quotes to unescape for filenames (#5398)
* Move uses of trim_quotes to unescape for filenames

* Fix Windows tests
2022-05-02 06:37:20 +12:00
Tomoki Aonuma
ae9c0fc138
Fix quoting for command line args (#5384)
* Fix quoting for command line args

* Replace custom quoting with escape_quote_string

* Use raw string for now
2022-04-30 13:23:05 -05:00
gipsyh
fb8f7b114e
Fix use of export/alias --help bug (#5332)
* fix alias --help bug

Signed-off-by: SuYuheng <yuheng.su@motiong.com>

* fix export --help bug

Signed-off-by: SuYuheng <yuheng.su@motiong.com>

Co-authored-by: SuYuheng <yuheng.su@motiong.com>
2022-04-26 11:51:49 -05:00
JT
3492d4015d
Allow bare words to interpolate (#5327)
* Allow bare words to interpolate

* fix highlighting
2022-04-26 11:44:44 +12:00
Herlon Aguiar
5ff2ae628b
nu-cli: directory syntax shape + completions (#5299) 2022-04-22 15:18:51 -05:00
JT
ee29a15119
Add 'and' and 'or' operators (#5297) 2022-04-23 07:14:31 +12:00
JT
76079d5183
Move config to be an env var (#5230)
* Move config to be an env var

* fix fmt and tests
2022-04-19 10:28:01 +12:00
Herlon Aguiar
dd1d9b7623
nu-cli/completions: completion for use and source (#5210)
* nu-cli/completions: completion for use and source

* handle subfolders for different base dirs

* fix clippy errors
2022-04-19 00:59:13 +12:00
Kat Marchán
1314a87cb0
update miette and switch to GenericErrors (#5222) 2022-04-19 00:34:10 +12:00
Hristo Filaretov
0a990ed105
Simplify known external name recovery (#5213)
Prior to this change we would recover the names for known
externals by looking up the span in the engine state. This would fail
when using an alias for two reasons:

1. In cases where we don't have a subcommand, like this:

```
>>> extern bat [filename: string]
>>> alias b = bat
>>> bat some_file
'b' is not recognized as an internal or external command,
operable program or batch file.
```

The problem is that after alias expansion, we replace the span of the
expanded name with the original alias (this is done to alleviate
non-related issues). The span contents we look up therefore contain `b`,
the alias, instead of the expanded command name.

2. In cases where there's a subcommand:
```
>>> alias g = git
>>> g push
thread 'main' panicked at 'internal error: span missing in file contents cache', crates\nu-protocol\src\engine\engine_state.rs:474:9
note: run with `RUST_BACKTRACE=1` environment variable to display a
backtrace
```

In this case, the span in call starts where the expansion for the `g`
alias is defined and end after `push` on the last command entered. This
is not a proper span and causes a panic when we try to look it up. Note
that this is the case for all expanded aliases that involve a
subcommand, but we never actually try to retrieve the contents for that
span in other cases.

Anyway, the new way of looking up the name is arguably cleaner
regardless of the issues mentioned above. But it's nice that it fixes
them too.

Co-authored-by: Hristo Filaretov <h.filaretov@protonmail.com>
2022-04-16 22:07:38 -05:00
Tomoki Aonuma
c17129a92a
Fix env capture (#5205)
* Fix env capture

* Add test for env capture
2022-04-16 10:38:27 +12:00
JT
5bf1c98a39
Move to dev version 0.61.1 (#5206) 2022-04-16 09:29:30 +12:00
Kat Marchán
3783c19d02
bump miette to 4.4.0 (#5167)
This fixes an issue where docsrs error links were not working.

Ref: https://github.com/zkat/miette/issues/147
2022-04-13 08:38:15 +12:00
JT
4566c904d0
Bump 0.61 (#5166) 2022-04-13 05:42:26 +12:00
Reilly Wood
57761149f4
Update incorrect crate descriptions (#5159) 2022-04-12 06:17:06 +12:00
merkrafter
a30930324d
Support binary literals with binary format (#5149)
* 4924 Support binary literals with binary format

* 4924 Support automatic padding for binary literals
2022-04-11 19:58:57 +12:00
JT
14066ccc30
Fix known externals, fix operator spans (#5140) 2022-04-09 17:17:48 +12:00
Hristo Filaretov
683b912263
Track call arguments in a single list (#5125)
* Initial implementation of ordered call args

* Run cargo fmt

* Fix some clippy lints

* Add positional len and nth

* Cargo fmt

* Remove more old nth calls

* Good ole rustfmt

* Add named len

Co-authored-by: Hristo Filaretov <h.filaretov@protonmail.com>
2022-04-09 14:55:02 +12:00
JT
97eb8492a3
Improve $in handling (#5137)
* Simplify in logic

* Add tests

* more tests, and fixes
2022-04-09 09:41:05 +12:00
JT
0b85938415
Soften the block arity checking (#5135) 2022-04-09 07:57:27 +12:00
Michel Alexandre Salim
6ed033737d
Include license text in all crates (#5094)
* Include license text in all crates

Three crates already have license texts, so I'm keeping them, but
symlinking the `LICENSE` from the top level to the rest of the crate
directories. This works as long as `cargo publish` is done on a Unix-y
system and not Windows.

Also bump the copyright year to end in 2022.

Signed-off-by: Michel Alexandre Salim <salimma@fedoraproject.org>

* Replace symlinks

Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
2022-04-08 10:47:13 +02:00
Reilly Wood
b2c52b51b7
Change string contains operators to regex (#5117) 2022-04-07 18:23:14 +12:00
JT
888369022f
Add datetime to math-like (#5118)
* Add datetime to math-like

* add test
2022-04-07 18:02:28 +12:00
JT
4409185e1b
Improve describe to be more accurate (#5116) 2022-04-07 16:34:09 +12:00
JT
ef1934a7ee
Remove external name exceptions (#5115) 2022-04-07 14:01:31 +12:00
JT
591fb4bd36
Add unary not (#5111) 2022-04-07 07:10:25 +12:00
Herlon Aguiar
13869e7d52
nu-cli: refactor completions (#5102) 2022-04-06 19:58:55 +12:00
JT
abe028f930
Add raw strings, use raw strings for env (#5090) 2022-04-05 08:42:26 +12:00
JT
6649da3f5d
Add support for single value row conditions (#5072) 2022-04-03 10:41:36 +12:00
Darren Schroeder
2cb815b7b4
Add starts with operator (#5061)
* add starts_with operator

* added a test
2022-04-01 13:35:46 -05:00
Jakub Žádník
d89ad4fafd
Add record, list, and table to signature types (#5040) 2022-03-31 11:11:03 +03:00
Reilly Wood
31a4fc41eb
Fix env var shorthand when value contains = (#5022) 2022-03-30 09:56:55 +13:00
JT
82e3bb0f38
Bump nushell to 0.60.1 (#4987) 2022-03-27 16:18:47 +13:00
JT
cf88c8eef3
Improve escaping in string interpolation (#4982) 2022-03-27 12:52:09 +13:00
JT
66087b01e6
Improve the 'use' and 'source' errors (#4966)
* Improve the 'use' and 'source' errors

* Add register
2022-03-26 10:43:46 +13:00
JT
d122827a30
Fix operator precedence parser (#4947) 2022-03-25 16:23:08 +13:00
Tomoki Aonuma
90013295aa
Fix parse_string_strict() to detect unbalanced quotes properly (#4928) 2022-03-25 05:57:03 +13:00
JT
eceae26b0a
Update Cargo.toml 2022-03-23 09:39:03 +13:00
JT
ec5fd62f9f
Add licenses (#4893)
* Add licenses

* Add licenses
2022-03-23 09:25:38 +13:00
JT
1c964cdfe7
Bump to 0.60 (#4892)
* WIP

* semi-revert metadata change
2022-03-23 07:32:03 +13:00
JT
66e736dab4
Externals shouldn't expand aliases (#4889) 2022-03-22 11:57:48 +13:00