Home Explore Blog CI



nushell

commands/docs/attr_example.md
2b0b50108b812d176bec24c9feb8c1543c99f3def556a8c90000000300000486
---
title: attr example
categories: |
  core
version: 0.104.0
core: |
  Attribute for adding examples to custom commands.
usage: |
  Attribute for adding examples to custom commands.
editLink: false
contributors: false
---
<!-- This file is automatically generated. Please edit the command in https://github.com/nushell/nushell instead. -->

# `attr example` for [core](/commands/categories/core.md)

<div class='command-title'>Attribute for adding examples to custom commands.</div>

## Signature

```> attr example {flags} (description) (example)```

## Flags

 -  `--result {any}`: Expected output of example.

## Parameters

 -  `description`: Description of the example.
 -  `example`: Example code snippet.


## Input/output types:

| input   | output                                       |
| ------- | -------------------------------------------- |
| nothing | record\<description: string, example: string\> |
## Examples

Add examples to custom command
```nu
> # Double numbers
    @example "double an int" { 2 | double } --result 4
    @example "double a float" { 0.25 | double } --result 0.5
    def double []: [number -> number] { $in * 2 }

```

Chunks
d601241d (1st chunk of `commands/docs/attr_example.md`)
Title: attr example
Summary
The `attr example` command is used to add examples to custom commands in Nushell. It takes a description and an example code snippet as input, and can optionally include the expected output using the `--result` flag. The command outputs a record containing the description and example.