feature #42251 [Console] Bash completion integration (wouterj)
feature #42251 [Console] Bash completion integration (wouterj)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[Console] Bash completion integration

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #38275
| License       | MIT
| Doc PR        | -

This is a first shot at implementing interactive bash completion support in the Console component. Besides completing option and command names, commands can override `Command::complete()` to implement completing values.

I've added an example code to the `secrets:remove` command, which now supports autocompletion quite nicely: ![render1630315116886](https://user-images.githubusercontent.com/749025/136708284-bf2e4c12-7cb7-4d5e-9c8d-68bcdca6fd7c.gif)

And support for other applications using `symfony/console` is automatically included (if the autocompletion script is installed for that specific application):
![render1630314403752](https://user-images.githubusercontent.com/749025/136708323-dfbccb77-dcbd-4d1e-8bb5-85b88f0b358b.gif)

This PR only implements Bash completion. Zsh and Fish have much more sophisticated completion systems, but I propose to keep those for a future PR if there is a need for this.

### How it works

1. A bash completion function (`_console`) is defined by `bin/console completion bash` for the `console` command (name of the "binary" file)
2. This completion function calls the local `bin/console _complete` command to come up with suggestions
3. Bash parses these suggestions and shows them to the user.

This has one drawback: the `_console` function is defined globally only once. This means we cannot easily change it, as it would break if you run different Symfony versions. We should probably add versioning (e.g. `bin/console _complete --version=1.0`) and don't suggest anything if the version doesn't match.

<s> **Maybe it would be safer to mark this feature as experimental and target 6.0, to allow us to fine tune the shell related sides over the lifespan of 6.x?** </s> https://github.com/symfony/symfony/pull/42251#issuecomment-890925658

### Steps to test yourself

Load this PR in your project, open a bash shell and run this command to "install" completion for this project:

```
bin/console completion bash > /etc/bash_completion.d/console
````

Then reload the bash shell and enjoy autocompletion.

### TODO

* [x] Autocompleting in the middle of the input doesn't work yet (i.e. `bin/console --en<TAB> cache:clear`)
* [x] Better error handling
* [x] Add a `bin/console completion` command to dump the `_console` file, so users can install this locally
* [x] Add some versioning, to allow us to change the `_console` file in the future
* [x] <s>See how we can better support standalone usage (e.g. Composer)</s> Tested on Laravel's artisan, works flawlessly

Commits
-------

e0a174f877 [FrameworkBundle] Add CLI completion to secrets:remove
82ef399de3 [Console] Bash completion integration

symfony/framework-bundle