symfonyconsole
Genere une commande console Symfony avec arguments, options et interaction
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Genere une commande console Symfony avec arguments, options et interaction
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Audite un projet API Platform existant et produit un rapport de bonnes pratiques, performances et sécurité
Génère des DTOs (input/output) API Platform avec mapping vers les entités
Génère des filtres API Platform (search, date, range, order, boolean, exists, custom)
Génère un State Processor API Platform pour personnaliser la persistence des données
Génère un State Provider API Platform pour personnaliser la récupération de données
Génère une API Resource complète avec attribut
| name | symfony:console |
| description | Genere une commande console Symfony avec arguments, options et interaction |
| model | sonnet |
| allowed-tools | ["AskUserQuestion","Bash","Read","Write","Edit","Grep","Glob"] |
| version | 1.0.0 |
| license | MIT |
Genere une commande console Symfony complete avec arguments, options, interaction utilisateur et bonnes pratiques.
src/Command/{CommandName}.phpIMPORTANT : Execute ce workflow etape par etape :
Question: "Quel est le nom de la commande ? (ex: app:import-users)"
Header: "Commande"
app:import-users -> ImportUsersCommand:, prefixer par app:Question: "Quelle est la description de la commande ?"
Header: "Description"
Question: "Quels arguments et options ? Format: arg:username:required,opt:verbose:v:bool,opt:format:f:string=json (laisser vide si aucun)"
Header: "Parametres"
arg:name:required|optional - Argument positionnelopt:name:shortcut:type=default - Option avec shortcut et valeur par defautQuestion: "Quelles options activer ?"
Header: "Options"
Options:
- "ProgressBar" : "Barre de progression pour les traitements longs"
- "Table output" : "Affichage tabulaire des resultats"
- "Lock" : "Empecher l'execution simultanee (LockableTrait)"
- "Schedulable" : "Attribut AsScheduledTask pour l'execution planifiee"
composer.json avec Readautoload.psr-4App par defautsrc/Command/{CommandName}.php avec Write<?php
declare(strict_types=1);
namespace {namespace}\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(
name: '{commandName}',
description: '{description}',
)]
final class {CommandName} extends Command
{
public function __construct(
// Injecter les services necessaires
) {
parent::__construct();
}
protected function configure(): void
{
$this
// ->addArgument('name', InputArgument::REQUIRED, 'Description')
// ->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'Output format', 'json')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
// Logique de la commande
$io->success('Commande executee avec succes.');
return Command::SUCCESS;
}
}
Regles de generation :
final#[AsCommand] avec name et descriptionparent::__construct() appele dans le constructeurSymfonyStyle pour les I/O$io->createProgressBar($count) dans execute()$io->table($headers, $rows) dans execute()use LockableTrait; et verifier $this->lock() au debut de execute()#[AsScheduledTask('* * * * *')] apres #[AsCommand]Command::SUCCESS, Command::FAILURE ou Command::INVALIDAffiche :
Commande {commandName} generee avec succes
Fichiers crees :
- src/Command/{CommandName}.php
Utilisation :
php bin/console {commandName}
php bin/console {commandName} --help
Prochaines etapes :
- Implementer la logique dans execute()
- Injecter les services necessaires dans le constructeur
- Ajouter des tests : tests/Command/{CommandName}Test.php
final, attribut #[AsCommand]#[AsCommand] (Symfony 6.1+) plutot que $defaultNameSymfonyStyle a OutputInterface directementInputArgument::REQUIRED ou OPTIONAL explicitementInputOption::VALUE_NONE