HerokuPhilipe NavarroExplainer
Heroku CLI: Completing Autocomplete
Summary
Heroku CLI Autocomplete had to support a dynamic, plugin-based command set while completing values that often reside behind the Heroku API. Instead of static shell case statements, its cache builder iterates through installed commands and generates setters that supply command, flag, and value completions when the user presses Tab. A shim sourced from the user’s .bashrc or .zshrc limits profile changes, fails silently when unavailable, and permits updates without repeated edits. API-backed values are cached on disk, while oclif custom hooks invalidate or rebuild relevant caches after commands change data. The completion function also parses the partially entered command line to provide contextual results, such as add-on aliases for a specified app; the work is being incorporated into an oclif plugin.
Context
The Heroku CLI supports user-installed plugins, varied shell configurations, and completion data stored behind an API rather than locally. The work also needed to address cache invalidation and completions dependent on values already supplied in a command.
Approach / What changed
The implementation builds a cache from installed commands, generates setters for dynamic completion, sources a controlled shim from the shell profile, caches API responses on disk, uses oclif custom hooks for invalidation, and parses existing command-line input for contextual completions.
Takeaways
The autocomplete cache builder includes commands from installed plugins and generates setters containing the information needed to complete each command’s flags and values.
A shim stored in the user’s cache directories can be updated without further shell-profile edits and fails silently if it cannot be found, preventing autocomplete problems from blocking the shell.
oclif custom hooks let commands trigger targeted completion-cache invalidation or rebuilding without coupling the CLI lifecycle to whether the autocomplete plugin is installed.
Source and freshness
- Source
- heroku.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.