The platform CLI tool contains a large library of commands, and trying to list them each time you can’t quite remember the names or options can fill up your screen really fast. Tab-completion will be able to help us out here.
Goal
We want autocomplete support (press tab to get command and option suggestions) for the platform CLI tool.
Assumptions
As it’s a symfony component, these commands can be programmatically extracted in a standard way.
The symfony-console-autocomplete tool does this for us.
Instructions here for OSX, the setup instructions are similar for other systems and shells
Prerequisites
If you don’t have bash-completion installed by default, get that first.
Using brew on OSX. *nix sessions probably already have it.
brew install bash-completion
Add the startup line to your ~/.bash_profile like it advises.
Scripts found in /usr/local/etc/bash_completion.d/ can support individual commands now.
Steps
Install symfony-console-autocomplete
composer global require bamarni/symfony-console-autocomplete
Now we can generate a dump of all symfony-console-based CLI commands, and use that dump to generate the autocomplete prompts.
Auto-generate autocomplete hints for platform
symfony-autocomplete platform --script-options=list > /usr/local/etc/bash_completion.d/platform
Restart your shell session (or at least source ~/.bash_profile) and autocomplete should be available for platform cli now.
The location
/usr/local/etc/bash_completion.d/will differ depending on your OS, version, and preferred shell. Alternate instructions forfish,zshetc are in the README. The only difference from the examples there is that we have to add--script-options=listto extract the commands forplatform.
Test
Pressing [TAB] part-way through entering platform commands will now provide either autocompletion or a list of suggestions, for both commands and options to those commands.
Examples:
$ platform pr[TAB]
platform project:
$ platform project:[TAB]
clear-build-cache curl get list variable:delete variable:set
create delete info set-remote variable:get
$ platform project:l[TAB]
platform project:list
$ platform project:list --[TAB]
--columns --help --my --no-header --quiet --reverse --title --version
--format --host --no --pipe --refresh --sort --verbose --yes