parser/add rest args to def (#2961)

* Add rest arg to def

This commit applied adds the ability to define the rest parameter of a def
command. It does not implement the functionality to expand the rest argument in
a user defined def function.

The rest argument has to be exactly worded "...rest".

Example after this PR is applied:

file test.nu
```shell
def my_command [
    ...rest:int # My rest arg
] {
    echo 1 2 3
}
```

```shell
> source test.nu
> my_command -h
Usage:
  > my_command ...args {flags}

Parameters:
  ...args: My rest arg

Flags:
  -h, --help: Display this help message
```

* Fix space in help on wrong side
This commit is contained in:
Leonhard Kipp
2021-01-22 19:13:29 +01:00
committed by GitHub
parent 64553ddcb7
commit 71b99edd48
3 changed files with 152 additions and 5 deletions

View File

@ -160,7 +160,7 @@ pub fn get_documentation(
}
if signature.rest_positional.is_some() {
one_liner.push_str(" ...args");
one_liner.push_str("...args ");
}
if !subcommands.is_empty() {