Skip to content

Commit 9b6bf80

Browse files
committed
Document CLI shell completion (viam completion)
rdk#5947 enabled urfave/cli v3 shell completion, adding a hidden `viam completion` subcommand that outputs completion scripts for bash, zsh, fish, and PowerShell. Add setup instructions to the CLI overview and a reference entry for the completion command. https://claude.ai/code/session_01EFZQ9UyvXPCRPfr1XcAXC7
1 parent e554446 commit 9b6bf80

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

docs/cli/overview.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,51 @@ viam --help
202202
viam machines --help
203203
viam machines part shell --help
204204
```
205+
206+
## Enable shell completion
207+
208+
The CLI supports tab completion for commands, subcommands, and flag names.
209+
To enable it, source the completion script for your shell.
210+
211+
{{< tabs >}}
212+
{{% tab name="bash" %}}
213+
214+
Add to your `~/.bashrc`:
215+
216+
```sh {class="command-line" data-prompt="$"}
217+
source <(viam completion bash)
218+
```
219+
220+
{{% /tab %}}
221+
{{% tab name="zsh" %}}
222+
223+
Add to your `~/.zshrc`:
224+
225+
```sh {class="command-line" data-prompt="$"}
226+
source <(viam completion zsh)
227+
```
228+
229+
{{% /tab %}}
230+
{{% tab name="fish" %}}
231+
232+
```sh {class="command-line" data-prompt="$"}
233+
viam completion fish > ~/.config/fish/completions/viam.fish
234+
```
235+
236+
{{% /tab %}}
237+
{{% tab name="PowerShell" %}}
238+
239+
```powershell {class="command-line" data-prompt=">"}
240+
viam completion pwsh | Out-String | Invoke-Expression
241+
```
242+
243+
{{% /tab %}}
244+
{{< /tabs >}}
245+
246+
After sourcing the script, press **Tab** to complete commands and flags:
247+
248+
```sh {class="command-line" data-prompt="$"}
249+
viam <Tab> # lists all commands
250+
viam machines <Tab> # lists subcommands of machines
251+
viam data export <Tab> # lists subcommands of export
252+
```

docs/cli/reference.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@ viam [global options] command [command options] [arguments...]
1919

2020
## Commands
2121

22+
### `completion`
23+
24+
The `completion` command outputs a shell completion script.
25+
Source the output in your shell to enable tab completion for commands, subcommands, and flag names.
26+
27+
```sh {class="command-line" data-prompt="$"}
28+
viam completion bash
29+
viam completion zsh
30+
viam completion fish
31+
viam completion pwsh
32+
```
33+
34+
<!-- prettier-ignore -->
35+
| Argument | Description |
36+
| -------- | ----------- |
37+
| `bash` | Output a bash completion script. |
38+
| `zsh` | Output a zsh completion script. |
39+
| `fish` | Output a fish completion script. |
40+
| `pwsh` | Output a PowerShell completion script. |
41+
42+
For setup instructions, see [Enable shell completion](/cli/overview/#enable-shell-completion).
43+
2244
### `data`
2345

2446
The `data` command allows you to manage machine data.

0 commit comments

Comments
 (0)