Add match examples for simple value and alternative values (#15732)

Even with some experience in Nushell I did not find information about
the match syntax for alternative value matches. The `match` command help
does not mention it at all. I suggest we add an example.

Previously, the examples only had "advanced" matching operations. It
seems appropriate to start with the simplest one: Matching by value.

Add both of these examples.

# User-Facing Changes

`help match` and the [command reference
docs](https://www.nushell.sh/commands/docs/match.html) now have examples
for

* simple value matching
* alternative value matching
This commit is contained in:
Jan Klass 2025-05-11 12:41:24 +02:00 committed by GitHub
parent 0beb28e827
commit 6a8c183c1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -49,6 +49,17 @@ impl Command for Match {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![ vec![
Example {
description: "Match on a value",
example: "match 3 { 1 => 'one', 2 => 'two', 3 => 'three' }",
result: Some(Value::test_string("three")),
},
Example {
description: "Match against alternative values",
example:
"match 'three' { 1 | 'one' => '-', 2 | 'two' => '--', 3 | 'three' => '---' }",
result: Some(Value::test_string("---")),
},
Example { Example {
description: "Match on a value in range", description: "Match on a value in range",
example: "match 3 { 1..10 => 'yes!' }", example: "match 3 { 1..10 => 'yes!' }",