Skip to content

Add completion auto-install and plugin completion protocol#1486

Closed
mnorth-stripe wants to merge 2 commits into
sentinel-block-managementfrom
plugin-completion
Closed

Add completion auto-install and plugin completion protocol#1486
mnorth-stripe wants to merge 2 commits into
sentinel-block-managementfrom
plugin-completion

Conversation

@mnorth-stripe
Copy link
Copy Markdown
Contributor

Summary

Adds --install and --uninstall flags to stripe completion that automatically write the completion script to the right location and configure the user's shell profile. Also adds the plugin completion protocol for dynamic tab completion of plugin subcommands.

Depends on #1485 (sentinel block management utilities).

stripe completion --install

  1. Detects the user's shell (bash/zsh/fish) from $SHELL
  2. Generates the completion script via Cobra
  3. Writes it to ~/.stripe/stripe-completion.{bash,zsh} (or ~/.config/fish/completions/stripe.fish for fish)
  4. For bash/zsh: adds a sentinel-managed source line to the shell config file
  5. Warns if pre-existing manual completion references are found (with line numbers)

stripe completion --uninstall

  1. Removes the completion script file
  2. For bash/zsh: removes the sentinel block from the shell config
  3. Warns about any surviving manual references that need manual cleanup

stripe completion --install: Output example

Completion installed for zsh.
Script written to: /Users/jane/.stripe/stripe-completion.zsh
Shell config updated: /Users/jane/.zshrc
Restart your shell or run: source /Users/jane/.stripe/stripe-completion.zsh

stripe completion --install with pre-existing manual config

Completion installed for zsh.
Script written to: /Users/jane/.stripe/stripe-completion.zsh
Shell config updated: /Users/jane/.zshrc
Restart your shell or run: source /Users/jane/.stripe/stripe-completion.zsh

Warning: found a manually-added completion reference outside the managed block in /Users/jane/.zshrc:
  line 47: source ~/.stripe/stripe-completion.zsh
You may want to remove this line manually to avoid loading completions twice.

stripe completion --help: New flags

   --shell string         The shell to generate completion commands for. Supports "bash", "zsh", or "fish"
   --write-to-stdout      Print completion script to stdout rather than creating a new file.
+  --install              Install completion script to ~/.stripe and configure your shell profile automatically
+  --uninstall            Remove installed completion script and configuration from your shell profile

Plugin completion protocol

When a plugin command receives a tab completion request, the host CLI now invokes the plugin binary with Cobra's __complete protocol and parses the response. This enables dynamic completion for plugin subcommands and flags.

Test plan

  • Install for bash, zsh, fish — script created, config updated (bash/zsh), no config for fish
  • Install idempotency — running twice doesn't duplicate the sentinel block
  • Install with pre-existing manual references — detected and warned
  • Install permission denied — clear error message
  • Mutual exclusion — --install --uninstall rejected by Cobra
  • Uninstall — script removed, sentinel block removed, other config preserved
  • Uninstall when not installed — no error
  • Uninstall with surviving manual references — detected and warned
  • Home directory error — clear error message
  • Script generation for all shells + unsupported shell error
  • Plugin completion protocol parsing (11 test cases for Cobra output format)

@mnorth-stripe mnorth-stripe requested a review from a team as a code owner March 15, 2026 21:08
@mnorth-stripe
Copy link
Copy Markdown
Contributor Author

Part of completion auto-install work (2 of 2)

This PR adds the --install/--uninstall flags and plugin completion protocol, building on the sentinel block utilities in #1485.

Stack:

  1. stripe completion --install Add sentinel block management for shell config files #1485 — sentinel block management (base: fish-completion)
  2. Add completion auto-install and plugin completion protocol #1486 ← you are here — completion auto-install + plugin completion protocol (base: stripe completion --install Add sentinel block management for shell config files #1485)

Enables dynamic shell completion for plugin subcommands by invoking
the plugin binary with Cobra's __complete protocol and parsing the
response. When a user presses tab on a plugin command, the host CLI
delegates completion to the plugin process.

- GetPluginCompletions: invokes plugin binary with __complete args,
  parses Cobra-format output (completions + directive)
- parseCompletionOutput: parses the tab-separated completion format
- resolvePluginBinary / buildPluginCommand: locate and construct the
  plugin invocation, including Node.js runtime detection
- Wires ValidArgsFunction into plugin template commands

Committed-By-Agent: claude
Adds --install and --uninstall flags to `stripe completion` that
automatically write the completion script and configure the user's
shell profile. Detects and warns about pre-existing manual completion
references to avoid double-loading.

Also adds the plugin completion protocol: when a plugin command
receives tab completion requests, the host CLI invokes the plugin
binary with Cobra's __complete protocol and returns the results.

Committed-By-Agent: claude
@mnorth-stripe
Copy link
Copy Markdown
Contributor Author

Splitting into two smaller PRs for easier review.

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