Skip to content

Commit

Permalink
add information about switches (#1182)
Browse files Browse the repository at this point in the history
* add information about switches

* Update book/custom_commands.md

Co-authored-by: Antoine Stevan <[email protected]>

---------

Co-authored-by: Antoine Stevan <[email protected]>
  • Loading branch information
WindSoilder and amtoine authored Dec 21, 2023
1 parent 0b78b79 commit e4d6203
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions book/custom_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,25 @@ Or just without the switch flag:
> greet -a 10 hello
```

You can also assign it to true/false to enable/disable the flag too:

```nu
> greet -a 10 --switch=false
> greet -a 10 --switch=true
```

But note that this is not the behavior you want: `> greet -a 10 --switch false`, here the value `false` will pass as a positional argument.

To avoid confusion, it's not allowed to annotate a boolean type on a flag:

```nu
def greet [
--twice: bool # Not allowed
] { ... }
```

instead, you should define it as a basic switch: `def greet [--twice] { ... }`

Flags can contain dashes. They can be accessed by replacing the dash with an underscore:

```nu
Expand Down

0 comments on commit e4d6203

Please sign in to comment.