nushell/crates/nu-protocol/src
Bahex a0d7c1a4fd
Add SyntaxShape::OneOf syntax users can use (#15646)
# Description
Built-in commands can have parameter of `SyntaxShape::OneOf`.
This PR changes `OneOf`'s string representation and gives users the
ability to use it in definitions.

> _Syntax updated after discussion on discord._

```nushell
def foo [
    param: oneof<binary, string>
] { .. }
```
```
Usage:
  > foo <param> 

Flags:
  -h, --help: Display the help message for this command

Parameters:
  param <oneof<binary, string>>

Input/output types:
  ╭───┬───────┬────────╮
  │ # │ input │ output │
  ├───┼───────┼────────┤
  │ 0 │ any   │ any    │
  ╰───┴───────┴────────╯
```

<details><summary>Previous iterations</summary>
<p>

> ```nushell
> def foo [
>     param: (binary | string)
> ] { .. }
> ```

> ---
>
> ```nushell
> def foo [
>     param: one_of(binary, string)
> ] { .. }
> ```

</p>
</details> 


# User-Facing Changes

# Tests + Formatting
Added some test cases.

- 🟢 toolkit fmt
- 🟢 toolkit clippy
- 🟢 toolkit test
- 🟢 toolkit test stdlib

# After Submitting
- Update the website to include the new syntax
[here](https://github.com/nushell/nushell.github.io/blob/main/book/custom_commands.md)
- Update [tree-sitter-nu](https://github.com/nushell/tree-sitter-nu)
- Update `std` and `std-rfc` where applicable

---------

Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
2025-05-07 15:43:01 -05:00
..
ast refactor(lsp): flat_map with mutable accumulator (#15567) 2025-04-15 07:21:23 -05:00
config feat(table): Add new 'single' table mode (#15672) 2025-05-01 15:30:57 -05:00
debugger Custom command attributes (#14906) 2025-02-11 06:34:51 -06:00
engine fix: clear jobs _after_ traversing jobs for kill_all (#15685) 2025-05-07 17:25:16 +08:00
errors Inter-Job direct messaging (#15253) 2025-04-26 23:24:35 +08:00
ir fix: clippy warning of rust 1.8.4 (#14984) 2025-02-02 07:56:54 -06:00
pipeline refactor Value::follow_cell_path to reduce clones and return Cow (#15640) 2025-05-01 09:43:57 -05:00
plugin Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
process Inter-Job direct messaging (#15253) 2025-04-26 23:24:35 +08:00
value refactor Value::follow_cell_path to reduce clones and return Cow (#15640) 2025-05-01 09:43:57 -05:00
alias.rs Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
did_you_mean.rs Improve case insensitivity consistency (#10884) 2023-11-08 23:58:54 +01:00
eval_base.rs refactor Value::follow_cell_path to reduce clones and return Cow (#15640) 2025-05-01 09:43:57 -05:00
eval_const.rs Reminder comment to update doc when adding $nu constants (#15481) 2025-04-07 00:38:17 -04:00
example.rs Overhaul the plugin cache file with a new msgpack+brotli format (#12579) 2024-04-21 07:36:26 -05:00
id.rs Jobs (#14883) 2025-02-25 12:09:52 -05:00
lev_distance.rs Fix clippy (#15489) 2025-04-06 09:49:28 +08:00
lib.rs Start to Add WASM Support Again (#14418) 2024-11-30 07:57:11 -06:00
module.rs fix(parser): namespace pollution of constants by use module.nu (#15518) 2025-05-01 09:47:16 -05:00
parser_path.rs Replace raw usize IDs with new types (#13832) 2024-09-30 13:20:15 +02:00
signature.rs add attr category @category to custom command attributes (#15137) 2025-02-18 15:35:52 -06:00
span.rs Parse XML documents with DTDs by default, and add --disallow-dtd flag (#15272) 2025-03-12 08:09:55 -05:00
syntax_shape.rs Add SyntaxShape::OneOf syntax users can use (#15646) 2025-05-07 15:43:01 -05:00
ty.rs Rename user-facing 'date' to 'datetime' (#15264) 2025-03-21 13:36:21 -04:00