Commit Graph

101 Commits

Author SHA1 Message Date
8e1112c1dd Change other instances of $nothing to null ()
# 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
f43edbccdc Make env-related tests more resilient ()
# Description

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

The error message of environment variable not found could change
depending on the `$env` content which can produce random failures on
different systems. This PR hopefully makes the tests more resilient.

# 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.
2022-12-10 19:23:34 +02:00
JT
18d7e64660 Convert 'for' to a statement () 2022-11-11 09:05:34 +13:00
5add5cbd12 Further edits to help messages () 2022-10-26 09:36:42 -07:00
ad0c6bf7d5 Improve "Did you mean?" suggestions ()
* Copy lev_distance.rs from the rust compiler

* Minor changes to code from rust compiler

* "Did you mean" suggestions: test instrumented to generate markdown report

* Did you mean suggestions: delete test instrumentation

* Fix tests

* Fix test

`foo` has a genuine match: `for`

* Improve tests
2022-09-20 19:46:01 -05:00
4926865c4e str collect => str join ()
* Initialize join.rs as a copy of collect.rs

* Evolve StrCollect into StrJoin

* Replace 'str collect' with 'str join' everywhere

git ls-files | lines | par-each { |it| sed -i 's,str collect,str join,g' $it }

* Deprecate 'str collect'

* Revert "Deprecate 'str collect'"

This reverts commit 959d14203e.

* Change `str collect` help message to say that it is deprecated

We cannot remove `str collect` currently (i.e. via
`nu_protocol::ShellError::DeprecatedCommand` since a prominent project
uses the API:

b85542c31c/src/virtualenv/activation/nushell/activate.nu (L43)
2022-09-11 11:48:27 +03:00
14512988ba Rename all?, any? and empty? ()
Rename `all?`, `any?` and `empty?` to `all`, `any` and `is-empty` for sake of simplicity and consistency.

- More understandable for newcomers, that these commands are no special to others.
- `?` syntax did not really aprove readability. For me it made it worse.
- We can reserve `?` syntax for any other nushell feature.
2022-09-05 16:41:06 +02:00
20528e96c7 Add hide-env to hide environment variables ()
* Add hide-env to hide env vars; Cleanup tests

Also, there were some old unalias tests that I converted to hide.

* Add missing file

* Re-enable hide for env vars

* Fix test

* Rename did you mean error back

It was causing random tests to break
2022-08-13 12:55:06 +03:00
79182db587 Clean up which/which-support Cargo feature ()
* Rename "which" feature to "which-support"

* Ignore currently broken environment tests
2022-03-29 06:10:43 -05:00
JT
983d115bc0 Add an alias denylist for expansions () 2022-03-19 08:03:57 +13:00
JT
d0cbb2d12c Allow expanding aliases before keywords, improve hiding ()
* Allow aliasing source

* Add test

* improve hiding

* Finish adding tests

* fix test
2022-03-18 11:35:50 +13:00
JT
96a1bf5f8d Experiment: Allow both $true/true and $false/false ()
* Change true/false to keywords

* oops, clippy

* Both kinds of bools

* Add in some boolean variables

* disable py virtualenv test for now
2022-03-02 19:55:03 -05:00
JT
6e733f49bc Require block params ()
* Require block params

* Improve errors
2022-02-17 06:40:24 -05:00
JT
fc88a8538b Make let-env work like let ()
* Make let-env work like let

* Fix tests
2022-02-09 13:41:41 -05:00
JT
f9e1c4ef50 Use 'table' on scripts and -c commands ()
* Use 'table' on scripts and -c commands

* Fix tests

* Oops, missed a spot
2022-02-09 05:58:54 -05:00
JT
d70d91e559 Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
fdce6c49ab engine-q merge 2022-02-07 19:11:34 +00:00
JT
cc1b784e3d Add initial nu-test-support port ()
* Add initial nu-test-support port

* finish changing binary name

* Oops, these aren't Windows-safe tests
2022-02-02 15:59:01 -05:00
c9c6bd4836 Create errors from tables. ()
```
> [
  [          msg,                 labels,                      span];
  ["The message", "Helpful message here", ([[start, end]; [0, 141]])]
] | error make

error: The message
  ┌─ shell:1:1
  │
1 │ ╭ [
2 │ │   [          msg,                 labels,                      span];
3 │ │   ["The message", "Helpful message here", ([[start, end]; [0, 141]])]
  │ ╰─────────────────────────────────────────────────────────────────────^ Helpful message here
```

Adding a more flexible approach for creating error values. One use case, for instance is the
idea of a test framework. A failed assertion instead of printing to the screen it could create
tables with more details of the failed assertion and pass it to this command for making a full
fledge error that Nu can show. This can (and should) be extended for capturing error values as well
in the pipeline. One could also use it for inspection.

For example: `.... | error inspect { # inspection here }`

or "error handling" as well, like so: `.... | error capture { fix here }`

However, we start here only with `error make` that creates an error value for you with limited support for the time being.
2021-09-02 21:07:26 -05:00
b8e2bdd6b1 Allow different names for ...rest ()
* Allow different names for ...rest

* Resolves 

* This change requires an explicit name for the rest argument in `WholeStreamCommand`,
  which is why there are so many changed files.

* Remove redundant clone

* Add tests
2021-08-27 05:58:53 +12:00
88817a8f10 Allow environment variables to be hidden ()
* Allow environment variables to be hidden

This change allows environment variables in Nushell to have a value of
`Nothing`, which can be set by the user by passing `$nothing` to
`let-env` and friends.

Environment variables with a value of Nothing behave as if they are not
set at all. This allows a user to shadow the value of an environment
variable in a parent scope, effectively removing it from their current
scope. This was not possible before, because a scope can not affect its
parent scopes.

This is a workaround for issues like .

Additionally, this allows a user to simultaneously set, change and
remove multiple environment variables via `load-env`. Any environment
variables set to $nothing will be hidden and thus act as if they are
removed. This simplifies working with virtual environments, which rely
on setting multiple environment variables, including PATH, to specific
values, and remove/change them on deactivation.

One surprising behavior is that an environment variable set to $nothing
will act as if it is not set when querying it (via $nu.env.X), but it is
still possible to remove it entirely via `unlet-env`. If the same
environment variable is present in the parent scope, the value in the
parent scope will be visible to the user. This might be surprising
behavior to users who are not familiar with the implementation details.

An additional corner case is the the shorthand form of `with-env` does
not work with this feature. Using `X=$nothing` will set $nu.env.X to the
string "$nothing". The long-form works as expected: `with-env [X
$nothing] {...}`.

* Remove unused import

* Allow all primitives to be convert to strings
2021-08-26 08:15:58 -05:00
6db5692be4 Only allow unaliasing in current scope, add tests ()
* unalias only removes aliases in the current scope

* Add a test and fix previous ones which did not function as expected
2021-08-19 19:05:36 +12:00
JT
ead4029d49 Bump rustyline and add unalias test () 2021-08-18 05:55:34 +12:00
9bd408449e Add the ability to remove and list aliases ()
* Add the ability to remove and list aliases

* Fix failing unit tests

* Add a test to check unalias shadowing blocks
2021-08-17 08:56:35 -05:00
JT
b6728efcd4 in/not-in for strings () 2021-08-07 09:49:37 +12:00
1e15f26e98 fix interpolated strings when using unicode ()
* fix interpolated strings when using unicode

* added test case
2021-07-29 19:07:34 -05:00
JT
69fa040361 Fix nothing string comparison () 2021-07-08 07:21:02 +12:00
JT
b1970f79ee Add support for arbitrarily nested subcommands () 2021-06-26 09:09:06 +12:00
JT
93b5f3f421 Make lexing configurable wrt newlines () 2021-06-25 17:50:24 +12:00
JT
318d13ed58 Add built-in var to refer to pipeline values () 2021-06-21 12:31:01 +12:00
9e39284de9 Add unlet_env command ()
* Add ability to remove env variables

Signed-off-by: nathom <nathanthomas707@gmail.com>

* Implement unlet_env command

Signed-off-by: nathom <nathanthomas707@gmail.com>

* Update parameter description

Signed-off-by: nathom <nathanthomas707@gmail.com>

* Migrate to new filestructure

Signed-off-by: nathom <nathanthomas707@gmail.com>

* Added tests for unlet-env

Signed-off-by: nathom <nathanthomas707@gmail.com>

* Formatting

Signed-off-by: nathom <nathanthomas707@gmail.com>
2021-06-19 15:00:07 +12:00
JT
e8a2250ef8 Improve expr parse ()
* Require '-' to be a number for math

* Add test

* improve parse logic, add test
2021-06-10 05:17:45 +12:00
JT
16faafb7a8 Rename the use of invocation to subexpression ()
* Rename the use of invocation to subexpression

* Fix test name
2021-06-07 20:08:35 +12:00
JT
a2e6f5ebdb Add hex, octal, binary () 2021-06-06 17:14:51 +12:00
JT
1d0d0425d4 More fixes for bigint duration () 2021-06-05 04:54:18 +12:00
JT
131b5b56d7 Finish removing arg deserialization ()
* WIP remove process

* WIP

* WIP

* Finish removing arg deserialization
2021-06-04 18:23:57 +12:00
JT
290c712cde Retain tag when accessing a var () 2021-06-02 19:49:14 +12:00
JT
41834d16d6 Allow aliases to expand and ignore painting outside of lines () 2021-05-26 17:58:32 +12:00
1ee51f2afa Add the load-env command ()
* Add the load-env command

load-env can be used to add environment variables dynamically via an
InputStream. This allows developers to create tools that output environment
variables as key-value pairs, then have the user load those variables in using
load-env. This supplants most of the need for an `eval` command, which is
mostly used in POSIX envs for setting env vars.

Fixes 

* fixup! Add the load-env command
2021-05-26 06:18:20 +12:00
JT
5fcc7f2328 Fix bad operator () 2021-05-24 17:27:10 +12:00
JT
751de20f93 Do a bit more cleanup of block params ()
* Do a bit more cleanup of block params

* Do a bit more cleanup of block params
2021-05-21 19:04:27 +12:00
JT
4fdbf30308 Paren interpolation ()
* Switch interp to use parens

* improve interp parsing
2021-05-21 10:55:38 +12:00
JT
20f6114617 Improve block params () 2021-05-20 16:26:54 +12:00
JT
efac712f62 Fix string interp/shorthand overlap () 2021-05-12 16:20:29 +12:00
JT
311c0e3f50 Simplify string interpolation ()
* [DRAFT] simplify string interpolation

* Fix test
2021-05-12 13:53:57 +12:00
JT
25a8caa9b0 Simplify expressions ()
* WIP: experiment with simpler expressions

* fix simple invoke

* update tests

* fix a few tests

* Make paren parsing more robust

* fix external args

* Remove old invocation

* Update tests

* Update tests
2021-05-12 13:01:48 +12:00
JT
02d5729941 Properly evaluate dynamic blocks () 2021-04-21 14:31:54 +12:00
JT
61768aa2fd Fix parsing dot dot path () 2021-04-20 08:18:29 +12:00
611103d211 Fix Running echo .. starts printing integers forever () 2021-04-16 07:07:06 +12:00
52d69bb021 Fix Rest arg is not optional () 2021-04-12 14:37:36 +12:00