nushell/crates/nu-command/tests/commands
JT 53ae03bd63
Custom command input/output types (#9690)
# Description

This adds input/output types to custom commands. These are input/output
pairs that related an input type to an output type.

For example (a single int-to-int input/output pair):

```
def foo []: int -> int { ... }
```

You can also have multiple input/output pairs:
```
def bar []: [int -> string, string -> list<string>] { ... }
```

These types are checked during definition time in the parser. If the
block does not match the type, the user will get a parser error.

This `:` to begin the input/output signatures should immediately follow
the argument signature as shown above.

The PR also improves type parsing by re-using the shape parser. The
shape parser is now the canonical way to parse types/shapes in user
code.

This PR also splits `extern` into `extern`/`extern-wrapped` because of
the parser limitation that a multi-span argument (which Signature now
is) can't precede an optional argument. `extern-wrapped` now takes the
required block that was previously optional.

# User-Facing Changes

The change to `extern` to split into `extern` and `extern-wrapped` is a
breaking change.

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

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

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

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

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-07-15 09:51:28 +12:00
..
assignment allow different types of lists to be appended (#8157) 2023-02-22 12:53:36 +00:00
date Standardise the use of ShellError::UnsupportedInput and ShellError::TypeMismatch and add spans to every instance of the former (#7217) 2022-12-23 01:48:53 -05:00
hash_ Deprecate hash base64, extend decode and add encode commands (#5863) 2022-06-26 00:35:23 +03:00
math Input output checking (#9680) 2023-07-14 15:20:35 +12:00
move_ Fix cp -u/mv -u when the dst doesn't exist (#9662) 2023-07-12 18:12:59 +02:00
network add http options command (#9365) 2023-06-09 08:00:40 -05:00
path Refactor path commands (#9687) 2023-07-15 00:04:22 +03:00
platform Fix a panic bug in platform ansi logic (Closes #9448) (#9458) 2023-06-16 11:40:03 -05:00
query Feature cleanup (#7182) 2022-11-22 16:58:11 -08:00
random Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
skip Input output checking (#9680) 2023-07-14 15:20:35 +12:00
str_ move 'str substring' to only use ranges (#8660) 2023-03-29 20:01:42 +13:00
take Input output checking (#9680) 2023-07-14 15:20:35 +12:00
url Add a check for empty params for url join (#9356) 2023-06-07 19:08:21 +02:00
alias.rs split $nu variable into scope commands and simpler $nu (#9487) 2023-06-21 09:33:01 +12:00
all.rs Removes unnecessary cwd and pipeline from various tests (#9202) 2023-05-17 18:55:26 -05:00
any.rs Removes unnecessary cwd and pipeline from various tests (#9202) 2023-05-17 18:55:26 -05:00
append.rs fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793) 2023-04-07 14:09:55 -07:00
break_.rs fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793) 2023-04-07 14:09:55 -07:00
cal.rs fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793) 2023-04-07 14:09:55 -07:00
cd.rs fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793) 2023-04-07 14:09:55 -07:00
compact.rs fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793) 2023-04-07 14:09:55 -07:00
continue_.rs fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793) 2023-04-07 14:09:55 -07:00
cp.rs Fix cp -u/mv -u when the dst doesn't exist (#9662) 2023-07-12 18:12:59 +02:00
def.rs Custom command input/output types (#9690) 2023-07-15 09:51:28 +12:00
default.rs fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793) 2023-04-07 14:09:55 -07:00
do_.rs fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793) 2023-04-07 14:09:55 -07:00
drop.rs Input output checking (#9680) 2023-07-14 15:20:35 +12:00
each.rs REFACTOR: move the 0% commands to nu-cmd-extra (#9404) 2023-07-06 08:31:31 -07:00
echo.rs fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793) 2023-04-07 14:09:55 -07:00
empty.rs fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793) 2023-04-07 14:09:55 -07:00
error_make.rs fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793) 2023-04-07 14:09:55 -07:00
every.rs fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793) 2023-04-07 14:09:55 -07:00
exec.rs Add "fall-through" signatures (#7527) 2022-12-22 00:33:26 +02:00
export_def.rs Removes unnecessary cwd and pipeline from various tests (#9202) 2023-05-17 18:55:26 -05:00
fill.rs Removes unnecessary cwd and pipeline from various tests (#9202) 2023-05-17 18:55:26 -05:00
find.rs Fix find puts extra cols into record (#9397) 2023-06-10 16:57:26 -05:00
first.rs simplify the nu! tests for last and first commands (#9608) 2023-07-05 12:30:53 +02:00
flatten.rs str collect => str join (#6531) 2022-09-11 11:48:27 +03:00
for_.rs Loops return external stream when external command failed. (#8646) 2023-04-05 20:38:04 +03:00
format.rs Fix warnings and old names (#8457) 2023-03-15 18:54:55 +13:00
get.rs Removes unnecessary cwd and pipeline from various tests (#9202) 2023-05-17 18:55:26 -05:00
glob.rs Fix warnings and old names (#8457) 2023-03-15 18:54:55 +13:00
group_by.rs Change group-by to accept cell paths (#9020) 2023-05-17 18:34:44 -05:00
headers.rs Fix headers command handling of missing values (#9603) 2023-07-06 19:54:59 +02:00
help.rs Change input/output types in help to a table (#9686) 2023-07-15 06:23:21 +12:00
histogram.rs Slim down tests (#9021) 2023-04-28 13:25:44 +02:00
insert.rs make insert, update, upsert support lazy records (#9323) 2023-05-31 06:27:55 -05:00
inspect.rs throw an error instead of a panic if no input is provided to inspect (#9259) 2023-05-22 13:54:04 -05:00
into_filesize.rs fix overflow on negative bytes (#7070) 2022-11-10 22:33:15 +01:00
into_int.rs Fix 8244 -- store timestamps with nanosecond resolution (consistently) (#8337) 2023-03-07 17:02:15 -06:00
join.rs Removes unnecessary cwd and pipeline from various tests (#9202) 2023-05-17 18:55:26 -05:00
last.rs Input output checking (#9680) 2023-07-14 15:20:35 +12:00
length.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
let_.rs remove warning: unused import pipeline (#9675) 2023-07-13 09:12:20 -07:00
lines.rs Replace row conditions with closures in commands (#7428) 2022-12-10 19:24:06 +02:00
loop_.rs Loops return external stream when external command failed. (#8646) 2023-04-05 20:38:04 +03:00
ls.rs chore: rename uid to user column in ls --long (#9407) 2023-06-11 18:02:08 +02:00
match_.rs Add rest and ignore-rest patterns (#8681) 2023-03-31 11:08:53 +13:00
merge.rs Fix warnings and old names (#8457) 2023-03-15 18:54:55 +13:00
mkdir.rs Input output checking (#9680) 2023-07-14 15:20:35 +12:00
mod.rs REFACTOR: move the 0% commands to nu-cmd-extra (#9404) 2023-07-06 08:31:31 -07:00
mut_.rs support env and mut assignment with if block and match guard (#9650) 2023-07-13 10:55:41 +02:00
nu_check.rs remove let-env, focus on mutating $env (#9574) 2023-07-01 07:57:51 +12:00
open.rs Add rest and glob support to 'open' (#8506) 2023-03-18 08:51:39 +13:00
par_each.rs Fix unexpected flattening of data by par-each (Issue #8497) (#9007) 2023-04-26 23:27:27 +02:00
parse.rs Fix warnings and old names (#8457) 2023-03-15 18:54:55 +13:00
prepend.rs Fix warnings and old names (#8457) 2023-03-15 18:54:55 +13:00
print.rs add -e flag to print, to print the value to stderr (#5935) 2022-07-02 09:54:49 -05:00
range.rs Use 'table' on scripts and -c commands (#4377) 2022-02-09 05:58:54 -05:00
redirection.rs remove let-env, focus on mutating $env (#9574) 2023-07-01 07:57:51 +12:00
reduce.rs Test return in reduce closure from #7961 (#7973) 2023-02-06 11:01:08 +01:00
reject.rs Slim down tests (#9021) 2023-04-28 13:25:44 +02:00
rename.rs Input output checking (#9680) 2023-07-14 15:20:35 +12:00
return_.rs ensure that when nu evaluates files, it allows early returns (#7415) 2023-02-02 00:02:27 +01:00
reverse.rs Input output checking (#9680) 2023-07-14 15:20:35 +12:00
rm.rs remove let-env, focus on mutating $env (#9574) 2023-07-01 07:57:51 +12:00
roll.rs Fix warnings and old names (#8457) 2023-03-15 18:54:55 +13:00
rotate.rs str collect => str join (#6531) 2022-09-11 11:48:27 +03:00
run_external.rs Add --redirect-combine option to run-external (#8918) 2023-04-28 07:55:48 -05:00
save.rs remove let-env, focus on mutating $env (#9574) 2023-07-01 07:57:51 +12:00
select.rs Fix select on empty lists (#8651) 2023-03-28 12:40:29 -07:00
semicolon.rs Slim down tests (#9021) 2023-04-28 13:25:44 +02:00
seq_char.rs Slim down tests (#9021) 2023-04-28 13:25:44 +02:00
seq.rs Slim down tests (#9021) 2023-04-28 13:25:44 +02:00
sort_by.rs Input output checking (#9680) 2023-07-14 15:20:35 +12:00
sort.rs Slim down tests (#9021) 2023-04-28 13:25:44 +02:00
source_env.rs remove let-env, focus on mutating $env (#9574) 2023-07-01 07:57:51 +12:00
split_by.rs Fix warnings and old names (#8457) 2023-03-15 18:54:55 +13:00
split_column.rs Add regex separators for split row/list/column (#8707) 2023-04-07 06:46:11 -05:00
split_row.rs Add regex separators for split row/list/column (#8707) 2023-04-07 06:46:11 -05:00
table.rs remove let-env, focus on mutating $env (#9574) 2023-07-01 07:57:51 +12:00
to_text.rs Make to text stream ListStreams (#7577) 2022-12-22 16:38:07 -08:00
touch.rs Correction bug multiple dots mkdir and touch (#8486) 2023-04-05 20:22:56 +03:00
transpose.rs Slim down tests (#9021) 2023-04-28 13:25:44 +02:00
try_.rs Disable pipeline echo (#8292) 2023-03-17 11:53:46 +13:00
uniq_by.rs Slim down tests (#9021) 2023-04-28 13:25:44 +02:00
uniq.rs Slim down tests (#9021) 2023-04-28 13:25:44 +02:00
update.rs make insert, update, upsert support lazy records (#9323) 2023-05-31 06:27:55 -05:00
upsert.rs make insert, update, upsert support lazy records (#9323) 2023-05-31 06:27:55 -05:00
use_.rs remove let-env, focus on mutating $env (#9574) 2023-07-01 07:57:51 +12:00
where_.rs Input output checking (#9680) 2023-07-14 15:20:35 +12:00
which.rs fixes which showing aliases as built-in nushell commands (#9580) 2023-07-08 10:48:42 +02:00
while_.rs Loops return external stream when external command failed. (#8646) 2023-04-05 20:38:04 +03:00
with_env.rs remove let-env, focus on mutating $env (#9574) 2023-07-01 07:57:51 +12:00
wrap.rs Fix warnings and old names (#8457) 2023-03-15 18:54:55 +13:00
zip.rs Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00