Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update command input/output docs #254

Merged
merged 1 commit into from
Mar 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 10 additions & 13 deletions book/custom_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ Flags:
-a, --age <integer>: 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:

Expand All @@ -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
───┴─────
```

Expand Down