From be43b3c5fc2c79db24dda6a6c4f88441abb1909c Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Wed, 9 Mar 2022 09:56:19 -0500 Subject: [PATCH] Allow passing block literals to do (#4798) --- crates/nu-command/src/core_commands/do_.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/nu-command/src/core_commands/do_.rs b/crates/nu-command/src/core_commands/do_.rs index 4d63ab73e..f493b8725 100644 --- a/crates/nu-command/src/core_commands/do_.rs +++ b/crates/nu-command/src/core_commands/do_.rs @@ -18,11 +18,7 @@ impl Command for Do { fn signature(&self) -> nu_protocol::Signature { Signature::build("do") .desc(self.usage()) - .required( - "block", - SyntaxShape::Block(Some(vec![])), - "the block to run", - ) + .required("block", SyntaxShape::Any, "the block to run") .switch( "ignore-errors", "ignore errors as the block runs", @@ -115,6 +111,20 @@ impl Command for Do { example: r#"do -i { thisisnotarealcommand }"#, result: None, }, + Example { + description: "Run the block, with a positional parameter", + example: r#"do {|x| 100 + $x } 50"#, + result: Some(Value::test_int(150)), + }, ] } } + +mod test { + #[test] + fn test_examples() { + use super::Do; + use crate::test_examples; + test_examples(Do {}) + } +}