Commit Graph

45 Commits

Author SHA1 Message Date
JT
eaec480f42
Improve empty pipelines (#7383)
# Description

This fix changes pipelines to allow them to actually be empty. Mapping
over empty pipelines gives empty pipelines. Empty pipelines immediately
return `None` when iterated.

This removes a some of where `Span::new(0, 0)` was coming from, though
there are other cases where we still use it.

# 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-08 07:31:57 +13:00
Jakub Žádník
cf0a18be51
Fix where -b flag (#7313)
# Description

The `where -b` flag was broken. The following now works:
```
let cond = {|x| $x.name !~ 'foo'}; ls | where -b $cond
```

This is just a quick fix. Ultimately, the `where` command shouldn't need
the flag and `where $cond` should work. The first step, however, is to
move `where` away from shape-directed parsing and make it a parser
keyword.

# User-Facing Changes

`where -b` is not broken

# 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-01 15:11:03 -08:00
sholderbach
64f226f7da Add math pi and math e constants (#7258)
Currently implemented as commands

Work towards #7073

Add them to the example test harness together with `math round`
2022-12-01 15:58:05 +01:00
JT
62e34b69b3
New commands: break, continue, return, and loop (#7230)
# Description

This adds `break`, `continue`, `return`, and `loop`.

* `break` - breaks out a loop
* `continue` - continues a loop at the next iteration
* `return` - early return from a function call
* `loop` - loop forever (until the loop hits a break)

Examples:
```
for i in 1..10 {
    if $i == 5 {
       continue
    } 
    print $i
}
```

```
for i in 1..10 {
    if $i == 5 {
        break
    } 
    print $i
}
```

```
def foo [x] {
    if true {
        return 2
    }
    $x
}
foo 100
```

```
loop { print "hello, forever" }
```

```
[1, 2, 3, 4, 5] | each {|x| 
    if $x > 3 { break }
    $x
}
```

# User-Facing Changes

Adds the above commands.

# Tests + Formatting

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

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

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

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2022-11-25 09:39:16 +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
Reilly Wood
7098e56ccf
Remove build-string command (#7144) 2022-11-16 09:37:52 -08: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
Dan Davison
df94052180
Declare input and output types of commands (#6796)
* Add failing test that list of ints and floats is List<Number>

* Start defining subtype relation

* Make it possible to declare input and output types for commands

- Enforce them in tests

* Declare input and output types of commands

* Add formatted signatures to `help commands` table

* Revert SyntaxShape::Table -> Type::Table change

* Revert unnecessary derive(Hash) on SyntaxShape

Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
2022-11-10 10:55:05 +13:00
Dan Davison
4926865c4e
str collect => str join (#6531)
* 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
Jakub Žádník
5a56d47f25
Add export-env command (#6355)
* WIP Start export-env

* Add missing file

* Do not modify the parser

Let's leave that for later

* Enable tests for export-env; Fmt
2022-08-18 23:24:39 +03: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
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
Darren Schroeder
4129f15eb9
update str find-replace to str replace (#5120) 2022-04-07 08:41:09 -05:00
JT
983d115bc0
Add an alias denylist for expansions (#4871) 2022-03-19 08:03:57 +13:00
JT
9888f8f298
Add pipeline redirection support (#4594)
* redirection

* Remove commented-out

* fix tests

* more fixes
2022-02-21 17:22:21 -05:00
Fernando Herrera
fcc13224c1
headers command (#4414)
* headers command

* correct behaviour headers
2022-02-11 21:06:49 -05:00
Jakub Žádník
564c2dd7d1
Port merge command from Nushell (#808)
* Add example test to zip

* Port merge command from Nushell

On top of the original merge, this one should not collect a stream
returned from the merged block and allows merging records.
2022-01-22 01:50:26 +02:00
Jakub Žádník
3b467bedd9
Add reduce command (#700)
* Add reduce command

* Fix example and missing test commands

* Add forgotten file
2022-01-08 02:40:40 +02:00
JT
41dbc641cc
Some cleanups for cd/PWD (#667)
* Some cleanups for cd/PWD

* Some cleanups for cd/PWD
2022-01-05 11:26:01 +11:00
Jakub Žádník
74dcd91cc3
Use only $nu.env.PWD for getting the current directory (#587)
* Use only $nu.env.PWD for getting current directory

Because setting and reading to/from std::env changes the global state
shich is problematic if we call `cd` from multiple threads (e.g., in a
`par-each` block).

With this change, when engine-q starts, it will either inherit existing
PWD env var, or create a new one from `std::env::current_dir()`.
Otherwise, everything that needs the current directory will get it from
`$nu.env.PWD`. Each spawned external command will get its current
directory per-process which should be thread-safe.

One thing left to do is to patch nu-path for this as well since it uses
`std::env::current_dir()` in its expansions.

* Rename nu-path functions

*_with is not *_relative which should be more descriptive and frees
"with" for use in a followup commit.

* Clone stack every each iter; Fix some commands

Cloning the stack each iteration of `each` makes sure we're not reusing
PWD between iterations.

Some fixes in commands to make them use the new PWD.

* Post-rebase cleanup, fmt, clippy

* Change back _relative to _with in nu-path funcs

Didn't use the idea I had for the new "_with".

* Remove leftover current_dir from rebase

* Add cwd sync at merge_delta()

This makes sure the parser and completer always have up-to-date cwd.

* Always pass absolute path to glob in ls

* Do not allow PWD a relative path; Allow recovery

Makes it possible to recover PWD by proceeding with the REPL cycle.

* Clone stack in each also for byte/string stream

* (WIP) Start moving env variables to engine state

* (WIP) Move env vars to engine state (ugly)

Quick and dirty code.

* (WIP) Remove unused mut and args; Fmt

* (WIP) Fix dataframe tests

* (WIP) Fix missing args after rebase

* (WIP) Clone only env vars, not the whole stack

* (WIP) Add env var clone to `for` loop as well

* Minor edits

* Refactor merge_delta() to include stack merging.

Less error-prone than doing it manually.

* Clone env for each `update` command iteration

* Mark env var hidden only when found in eng. state

* Fix clippt warnings

* Add TODO about env var reading

* Do not clone empty environment in loops

* Remove extra cwd collection

* Split current_dir() into str and path; Fix autocd

* Make completions respect PWD env var
2022-01-05 09:30:34 +11:00
JT
7f0921a14b
Add metadata command (#569)
* Add metadata command

* Add string interpolation to testing
2021-12-24 11:16:50 +11:00
JT
2883d6cd1e
Remove Span::unknown (#525) 2021-12-19 18:46:13 +11:00
Matthew Auld
6ba1e6172c
Port 'ansi strip' command from nushell to engine-q (#511)
* Port 'ansi strip' command from nushell to engine-q

* added example
2021-12-18 07:32:03 +11:00
Matthew Auld
89e2169521
Porting 'char' command from nushell to engine-q (#500)
* Port 'char' command from nushell to engine-q

* fixed unit tests

* Actually fixed unit tests
2021-12-16 10:08:12 +11:00
Matthew Auld
e289630920
Porting 'ansi' command from nushell to engine-q (#494)
* Porting 'ansi' command from nushell to engine-q

* Added StrCollect to example_test.rs to allow example tests to run

* Run 'cargo fmt' to fix formatting

* Update command.rs

* Update command.rs

* Update command.rs

* Added a category

Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
2021-12-16 10:06:35 +11:00
Hilmar Gústafsson
90ddb23492
Add Path commands (#280)
* Add Path command

* Add `path basename`

* Refactor operate into `mod`

* Add `path dirname`

* Add `path exists`

* Add `path expand`

* Remove Arc wrapper for args

* Add `path type`

* Add `path relative`

* Add `path parse`

* Add `path split`

* Add `path join`

* Fix errors after rebase

* Convert to Path in `operate`

* Fix table behavior in `path join`

* Use conditional import in `path parse`

* Fix missing cases for `path join`

* Update default_context.rs

* clippy

* Fix tests

* Fix tests

Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
Co-authored-by: JT <jonathan.d.turner@gmail.com>
2021-12-13 12:47:14 +11:00
Jae-Heon Ji
c3b6e07de6
Port network/url command (#452)
* feat: add url command

* feat(network/url): add sub-command for url
2021-12-09 18:09:30 -06:00
Jae-Heon Ji
21ddfc61f4
add random commands (#366)
* feat: add random command

* feat: add bool sub-command
2021-11-30 19:12:19 +13:00
Fernando Herrera
88988dc9f4
Plugins signature load (#349)
* saving signatures to file

* loading plugin signature from file

* is_plugin column for help command
2021-11-19 15:51:42 +13:00
JT
0f107b2830
Add a config variable with engine support (#332)
* Add a config variable with engine support

* Add a config variable with engine support

* Oops, cleanup
2021-11-15 08:25:57 +13:00
JT
47628946b6
Add str collect (#311)
* Add str collect

* Oops, missing file
2021-11-09 14:59:44 +13:00
onthebridgetonowhere
a1f141d18a
Port str case commands (#287)
* Port camel case and kebab case

* Port pascal case

* Port snake case and screaming snake case

* Cleanup before PR

* Add back cell path support for str case commands

* Add cell path tests for str case command

* Revert "Add cell path tests for str case command"

This reverts commit a0906318d95fd2b5e4f8ca42f547a7e4c5db381a.

* Add cell path test cases for str case command

* Move cell path tests from tests.rs to Examples in each of the command's file

Co-authored-by: Stefan Stanciulescu <contact@stefanstanciulescu.com>
2021-11-07 06:55:25 +13:00
JT
02b8027749
Improve external output in subexprs (#294) 2021-11-06 18:50:33 +13:00
Antonio Natilla
806cd4851f Format implementation, fix on Echo
Now, Echo converts multiple values in a ValueStream, but it simply
forwards a single Value; if no PipelineData is detected as an input, an
empty string is returned as a single Value.
2021-11-03 19:57:30 +01:00
JT
5e42b14026 Documenting some code and doing cleanups 2021-11-03 08:53:48 +13:00
Stefan Stanciulescu
20c770370b Port date commands to engine-q 2021-10-31 07:54:51 +01:00
JT
624edce4f7 Add 'to json' 2021-10-29 19:26:29 +13:00
Luccas Mateus de Medeiros Gomes
2ce034d0f0 linting 2021-10-25 20:57:45 -03:00
Luccas Mateus de Medeiros Gomes
017b1d8996 Updated to new PipeLineData and made the tests run 2021-10-25 20:56:22 -03:00
JT
5d19017603 WIP 2021-10-26 05:58:58 +13:00
JT
b5965ee8ef WIP 2021-10-25 19:31:39 +13:00
JT
b6d269e90a WIP 2021-10-25 17:01:02 +13:00
JT
c3a032950d Add initial batch of into conversions 2021-10-11 14:56:19 +13:00
Fernando Herrera
8756e88e3c command split 2021-10-09 14:28:09 +01:00
Fernando Herrera
e3e4ae0591 example unit test 2021-10-09 14:10:10 +01:00