cli: shell completion via cobra + dynamic resource name lookups
Re-enable cobra's default `completion` subcommand (`banger completion bash|zsh|fish|powershell`). Plus live resource-name suggestions that hit the running daemon via the same RPC the real commands use: vm start/stop/restart/delete/kill/set → completeVMNames (variadic) vm ssh/show/logs/stats/ports/... → completeVMNameOnlyAtPos0 vm session list/start → completeVMNameOnlyAtPos0 vm session show/logs/stop/kill/attach/send → completeSessionNames (vm + session) image show/delete/promote → completeImageNameOnlyAtPos0 kernel show/rm → completeKernelNameOnlyAtPos0 vm run/create --image, image pull/register --kernel-ref → flag-value completion Design notes in internal/cli/completion.go: completers never auto-start the daemon (ping-check, bail with NoFileComp on miss), so tab-completion stays a zero-cost probe. Variadic completers exclude already-entered args to avoid duplicate suggestions. README: install recipes for bash / zsh / fish.
This commit is contained in:
parent
346eaba673
commit
e3eaa0c797
4 changed files with 556 additions and 76 deletions
22
README.md
22
README.md
|
|
@ -32,6 +32,28 @@ Installs `banger` (CLI), `bangerd` (daemon, auto-starts on first
|
|||
CLI call), and `banger-vsock-agent` (companion, under
|
||||
`$PREFIX/lib/banger/`).
|
||||
|
||||
### Shell completion
|
||||
|
||||
`banger` ships completion scripts for bash, zsh, fish, and
|
||||
powershell. Tab-completion covers subcommands, flags, and live
|
||||
resource names (VM, image, kernel, session) looked up from the
|
||||
daemon. With the daemon down, resource completion silently
|
||||
returns nothing — no file-completion fallback.
|
||||
|
||||
```bash
|
||||
# bash (system-wide)
|
||||
banger completion bash | sudo tee /etc/bash_completion.d/banger
|
||||
|
||||
# zsh (user-local; ~/.zfunc must be on fpath)
|
||||
banger completion zsh > ~/.zfunc/_banger
|
||||
|
||||
# fish
|
||||
banger completion fish > ~/.config/fish/completions/banger.fish
|
||||
```
|
||||
|
||||
`banger completion --help` shows the shell-specific loading
|
||||
recipes.
|
||||
|
||||
## `vm run`
|
||||
|
||||
One command, four common shapes:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue