Skip to content

feat(cli): shell tab-completion — enum flag values + install.sh auto-setup#27

Merged
ysyneu merged 1 commit into
mainfrom
feat/cli-shell-completion
Jun 1, 2026
Merged

feat(cli): shell tab-completion — enum flag values + install.sh auto-setup#27
ysyneu merged 1 commit into
mainfrom
feat/cli-shell-completion

Conversation

@ysyneu
Copy link
Copy Markdown
Contributor

@ysyneu ysyneu commented Jun 1, 2026

What

Adds real shell tab-completion to the flashduty CLI, and makes installation set it up automatically.

Cobra already ships a hidden completion subcommand, but two gaps meant users saw nothing useful on <Tab>:

  1. Flag values never completed (e.g. --output-format <Tab> gave nothing).
  2. The generated script was never installed — generating ≠ activating.

Changes

  • Enum flag-value completion — new internal/cli/completion.go with a shared registerEnumFlag helper + single-source severityEnum, wired onto every closed-set flag:
    • global --output-formattable|json|toon
    • incident --severity (list/create/update) + --progress
    • alert / alert-event --severity
    • postmortem --statusdrafting|published
    • monit-query --ds-typeprometheus|victorialogs|loki|mysql
    • template --typecustom|sprig|all
    • statuspage --typeincident|maintenance
  • install.sh auto-install — best-effort, non-intrusive:
    • detects the user's $SHELL
    • fish → ~/.config/fish/completions/, bash → ~/.local/share/bash-completion/completions/ (auto-loaded user dirs)
    • zsh → only writes into an already-writable site-functions dir (e.g. Homebrew); otherwise prints copy-pasteable setup steps. Never edits ~/.zshrc.
    • never fails the install over completion (setup_completion || true)
    • handles a renamed binary (INSTALLED_NAME) by rewriting Cobra's baked root name with a |-delimited sed
  • Docs — document --output-format/toon in README.md and skills/flashduty-shared/SKILL.md (previously only table/JSON were listed).

Why non-intrusive for zsh

zsh has no guaranteed writable fpath dir, so the only ways to make it "just work" everywhere are writing to a system dir (sudo) or editing ~/.zshrc (intrusive, runs on every curl | sh). We deliberately do neither — we install where the shell already auto-loads, and otherwise hand the user exact instructions. This matches the gh/kubectl norm.

Verification

  • go build / go vet / go test ./... — green
  • gofmt clean on all touched files
  • sh -n install.sh + shellcheck -s sh install.sh — clean
  • flashduty __complete … --<flag> "" returns the enum values (with NoFileComp) for every wired flag
  • install.sh writes correct per-shell scripts for both the default name and a renamed (fduty) install; zsh fallback prints the right manual recipe

Note

This is release-gated: the flag completion reaches users only after a rebuild+release, and the install.sh change only after CI mirrors it to the CDN.

…setup

Cobra already ships a `completion` subcommand, but (a) flag values never tab-completed and (b) the generated script was never installed, so users saw nothing on Tab.

- Add internal/cli/completion.go: registerEnumFlag helper + shared severityEnum; wire it onto every closed-set flag (--output-format, incident --severity/--progress, alert/alert-event --severity, postmortem --status, monit-query --ds-type, template --type, statuspage --type).

- install.sh: best-effort, non-intrusive auto-install of completion for the user's $SHELL (fish/bash user dirs; zsh only into a writable site-functions dir, else print copy-pasteable setup steps). Never edits ~/.zshrc. Handles a renamed binary via a `|`-delimited sed rewrite of the Cobra-baked root name.

- Document --output-format/toon in README.md and skills/flashduty-shared/SKILL.md (previously only table/JSON were documented).

Verified: go build/vet/test green, gofmt clean, sh -n + shellcheck clean, __complete returns the enum values for every wired flag, and install.sh writes correct per-shell scripts (default + renamed).
@ysyneu ysyneu merged commit 7785aad into main Jun 1, 2026
14 checks passed
@ysyneu ysyneu deleted the feat/cli-shell-completion branch June 1, 2026 07:33
ysyneu added a commit that referenced this pull request Jun 2, 2026
Reconcile the full-OpenAPI-coverage feature with main's #26 (incident
6-char short-id resolution in detail/get + list --nums) and #27 (shell
tab-completion + install.sh auto-setup).

incident.go conflicts resolved to main's design:
- list: keep --nums (#26) plus the eval's "--since→--until window < 31d"
  help text.
- get: adopt #26's resolveIncidentArg→List-by-incident_ids body; the
  full-coverage branch's /incident/info get is superseded by #26's new
  `detail` command (which carries the no-window Info path). All 7
  incident short-id tests pass.

postmortem.go / status_page.go (deleted by the coverage branch in favor
of generated commands) kept deleted; #27's registerEnumFlag additions to
them drop with the files — generated post-mortem/status-page commands
cover those ops. completion.go + install.sh + the curated commands'
registerEnumFlag calls retained.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant