nushell/crates/nu-parser/src
Leonhard Kipp d0a2a02eea
Add possibility to declare optional parameters and switch flags (#2966)
* Add possibility to declare optional parameters and switch flags

With this commit applied it is now possible to specify optional parameters and flags
as switches. This PR **only** makes guarantees about **parsing** optional flags and
switches correctly. This PR **does not guarantee flawless functionality** of
optional parameters / switches within scripts.
functionality within scripts. Example:

test.nu
```shell
def my_command [
    opt_param?
    opt_param2?: int
    --switch
] {echo hi nushell}
```

```shell
> source test.nu
> my_command -h
───┬─────────
 0 │ hi
 1 │ nushell
───┴─────────
Usage:
  > my_command <mandatory_param> (opt_param) (opt_param2) {flags}

Parameters:
  <mandatory_param>
  (opt_param)
  (opt_param2)

Flags:
  -h, --help: Display this help message
  --switch
  --opt_flag <any>
```

* Update def docs
2021-01-28 06:31:29 +13:00
..
parse Add possibility to declare optional parameters and switch flags (#2966) 2021-01-28 06:31:29 +13:00
errors.rs Getting ready for multiline scripts (#2737) 2020-11-10 05:27:07 +13:00
lex.rs parser/split long short flags (#2944) 2021-01-20 07:19:53 +13:00
lib.rs Feature/def signature with comments (#2905) 2021-01-12 06:53:58 +13:00
parse.rs Fix bug #2921 (#2945) 2021-01-21 07:58:37 +13:00
path.rs Support completion for paths with multiple dots (#1640) 2020-04-23 16:17:38 +12:00
scope.rs Multiline scripts part 2 (#2795) 2020-12-18 20:53:49 +13:00
shapes.rs Multiline scripts part 2 (#2795) 2020-12-18 20:53:49 +13:00
signature.rs Pipeline blocks (#1579) 2020-04-13 19:59:57 +12:00