Allow passing block literals to do (#4798)

This commit is contained in:
JT 2022-03-09 09:56:19 -05:00 committed by GitHub
parent 355b1d9929
commit be43b3c5fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,11 +18,7 @@ impl Command for Do {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("do") Signature::build("do")
.desc(self.usage()) .desc(self.usage())
.required( .required("block", SyntaxShape::Any, "the block to run")
"block",
SyntaxShape::Block(Some(vec![])),
"the block to run",
)
.switch( .switch(
"ignore-errors", "ignore-errors",
"ignore errors as the block runs", "ignore errors as the block runs",
@ -115,6 +111,20 @@ impl Command for Do {
example: r#"do -i { thisisnotarealcommand }"#, example: r#"do -i { thisisnotarealcommand }"#,
result: None, 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 {})
}
}