From 81c32184b1fa2273c7ba7c57ef85cad65bef4135 Mon Sep 17 00:00:00 2001 From: Reilly Wood <26268125+rgwood@users.noreply.github.com> Date: Sat, 5 Mar 2022 15:17:26 -0500 Subject: [PATCH] Update command input/output docs - Make it a bit more clear that input/output refers to pipeline input/output - Fix pipeline input example for engine-q --- book/custom_commands.md | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/book/custom_commands.md b/book/custom_commands.md index 00b552c6e70..ad0ce2ca22e 100644 --- a/book/custom_commands.md +++ b/book/custom_commands.md @@ -224,7 +224,7 @@ Flags: -a, --age : The age of the person ``` -## Output +## Pipeline Output Custom commands stream their output just like built-in commands. For example, let's say we wanted to refactor this pipeline: @@ -251,29 +251,26 @@ We can use the output from this command just as we would `ls`. This lets us easily build custom commands and process their output. Note, we don't use return statements like other languages. Instead, we build pipelines that output streams of data that can be connected to other pipelines. -## Input +## Pipeline Input -Custom commands can also take input, just like other commands. This input is passed from the pipeline to the block that the custom command uses. +Custom commands can also take input from the pipeline, just like other commands. This input is automatically passed to the block that the custom command uses. -Let's make our own echo command that also outputs a line after each value that it gets from the input: +Let's make our own command that doubles every value it receives as input: ```nushell -def my-echo [] { - each { - echo $it "--" - } +def double [] { + each { |it| 2 * $it } } ``` Now, if we call the above command later in a pipeline, we can see what it does with the input: ``` -> echo foo bar | my-echo +> [1 2 3] | double ───┬───── - 0 │ foo - 1 │ -- - 2 │ bar - 3 │ -- + 0 │ 2 + 1 │ 4 + 2 │ 6 ───┴───── ```