From c18e6bfca01dac00f089458aa766fb3c8d3e317b Mon Sep 17 00:00:00 2001 From: NotTheDr01ds <32344964+NotTheDr01ds@users.noreply.github.com> Date: Tue, 6 Aug 2024 22:40:30 -0400 Subject: [PATCH] Add type signature example for def command (#13561) # Description By popular demand (a.k.a. https://github.com/nushell/nushell.github.io/issues/1035), provide an example of a type signature in the `def` help. # User-Facing Changes Help/Doc # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :green_circle: `toolkit test` - :green_circle: `toolkit test stdlib # After Submitting N/A --- crates/nu-cmd-lang/src/core_commands/def.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/nu-cmd-lang/src/core_commands/def.rs b/crates/nu-cmd-lang/src/core_commands/def.rs index 913f74803c..7f8613f315 100644 --- a/crates/nu-cmd-lang/src/core_commands/def.rs +++ b/crates/nu-cmd-lang/src/core_commands/def.rs @@ -70,6 +70,11 @@ impl Command for Def { example: r#"def --wrapped my-echo [...rest] { ^echo ...$rest }; my-echo -e 'spam\tspam'"#, result: Some(Value::test_string("spam\tspam")), }, + Example { + description: "Define a custom command with a type signature. Passing a non-int value will result in an error", + example: r#"def only_int []: int -> int { $in }; 42 | only_int"#, + result: Some(Value::test_int(42)), + }, ] } }