Symfony 6 brings its CLI to the next level

Brace yourself: autocompletion on options and arguments is finally here!

Alexandre Daubois

--

One the most useful thing ever when using a command line interface is autocompletion. You know about it. If you don’t, well I hope your new to command line interfaces, otherwise you’re missing a whole world.

Anyway, just to be super quick and that everybody understands this, autocompletion gives you suggestion often based on a context. For example, let’s say you want to change the directory you’re in, autocompletion can give you the list of available directories. It can even “type” itself the end of your command if only one result match. It is way more powerful than that, but you get it.

Let’s see how Symfony is bringing its CLI user experience (UX) and developer experience (DX) to the next level since version 5.4/6.0.

Internal commands

If you used Symfony, you are probably familiar to its command line interface. The one you’re using when calling commands like php bin/console c:c and so on. One big withdrawn before Symfony 5.4 is the lack of autocompletion. Wouldn’t it be nice to have command options and arguments values suggestions?

Thanks to Wouter de Jong and the whole Symfony community after the call to contributions, nearly all framework’s base command have autocompletion for most of their options and arguments! Here are a few examples:

  • Suggest secrets names on secret:remove ;
  • Translation domains on debug:translation ;
  • Bus and queues in messenger:consume ;
  • Available services in debug:autowiring ;
  • And so on.

When typing a command, simply press TAB and boom! Suggestions will appear like magic. It will save us so much time. Adding this feature to all already available features of the Console component is absolutely mind blowing.

For now, this completion is available for bash only, but it is already planned to bring it to other shells as well.

What’s exciting is that you can also adapt this behavior to your own commands. Let’s see how!

On your custom commands

--

--