From 2b97bc54c52bd9599b9545e6e834fd7c84d91e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Mon, 14 Aug 2023 16:41:25 +0300 Subject: [PATCH] Fix example for `extern-wrapped` (#10004) Fixes example and some signature text of `extern-wrapped`. # User-Facing Changes Minor help text changes --- .../src/core_commands/extern_wrapped.rs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/crates/nu-cmd-lang/src/core_commands/extern_wrapped.rs b/crates/nu-cmd-lang/src/core_commands/extern_wrapped.rs index aeac5fb1ab..d54ea1e49a 100644 --- a/crates/nu-cmd-lang/src/core_commands/extern_wrapped.rs +++ b/crates/nu-cmd-lang/src/core_commands/extern_wrapped.rs @@ -1,6 +1,8 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type}; +use nu_protocol::{ + Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value, +}; #[derive(Clone)] pub struct ExternWrapped; @@ -11,15 +13,16 @@ impl Command for ExternWrapped { } fn usage(&self) -> &str { - "Define a signature for an external command." + "Define a signature for an external command with a custom code block." } fn signature(&self) -> nu_protocol::Signature { Signature::build("extern-wrapped") .input_output_types(vec![(Type::Nothing, Type::Nothing)]) + .allow_variants_without_examples(true) .required("def_name", SyntaxShape::String, "definition name") .required("params", SyntaxShape::Signature, "parameters") - .required("body", SyntaxShape::Block, "wrapper function block") + .required("body", SyntaxShape::Block, "wrapper code block") .category(Category::Core) } @@ -44,9 +47,19 @@ impl Command for ExternWrapped { fn examples(&self) -> Vec { vec![Example { - description: "Write a signature for an external command", - example: r#"extern-wrapped echo [text: string] { print $text }"#, - result: None, + description: "Define a custom wrapper for an external command", + example: r#"extern-wrapped my-echo [...rest] { echo $rest }; my-echo spam"#, + result: Some(Value::test_list(vec![Value::test_string("spam")])), }] } } + +#[cfg(test)] +mod test { + #[test] + fn test_examples() { + use super::ExternWrapped; + use crate::test_examples; + test_examples(ExternWrapped {}) + } +}