From 6a8c183c1a68818c5d5052ccd6435a0b71ef6544 Mon Sep 17 00:00:00 2001 From: Jan Klass Date: Sun, 11 May 2025 12:41:24 +0200 Subject: [PATCH] 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 --- crates/nu-cmd-lang/src/core_commands/match_.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/nu-cmd-lang/src/core_commands/match_.rs b/crates/nu-cmd-lang/src/core_commands/match_.rs index db2bc2e1f0..bda42ac575 100644 --- a/crates/nu-cmd-lang/src/core_commands/match_.rs +++ b/crates/nu-cmd-lang/src/core_commands/match_.rs @@ -49,6 +49,17 @@ impl Command for Match { fn examples(&self) -> 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 { description: "Match on a value in range", example: "match 3 { 1..10 => 'yes!' }",