Important: #101567 - Use Symfony attribute to autoconfigure cli commands

See forge#101567

Description

The Symfony PHP attribute \Symfony\Component\Console\Attribute\AsCommand is now accepted to register console commands. This way CLI commands can be registered by setting the attribute on the command class. Only the parameters command, description, aliases and hidden are still viable. In order to overwrite the schedulable parameter use the old Services.yaml way to register console commands. By default schedulable is true.

Before:

EXT:my_extension/Configuration/Services.yaml
MyVendor\MyExtension\Command\MyCommand:
  tags:
    - name: 'console.command'
      command: 'myprefix:dofoo'
      description: 'My description'
      schedulable: true
    - name: 'console.command'
      command: 'myprefix:dofoo-alias'
      alias: true
Copied!

After:

The registration can be removed from the Services.yaml file and the attribute is assigned to the command class instead:

EXT:my_extension/Classes/Command/MyCommand.php
<?php

namespace MyVendor\MyExtension\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(
    name: 'myprefix:dofoo',
    description: 'My description',
    aliases: ['myprefix:dofoo-alias']
)]
class MyCommand extends Command
{
}
Copied!

Impact

The registration of cli commands is simplified that way. When using this attribute there is no need to register the command in the Services.yaml file. Existing configurations work as before.