99use CodeRhapsodie \DataflowBundle \Registry \DataflowTypeRegistryInterface ;
1010use CodeRhapsodie \DataflowBundle \Repository \ScheduledDataflowRepository ;
1111use Symfony \Component \Console \Attribute \AsCommand ;
12- use Symfony \Component \Console \Command \Command ;
13- use Symfony \Component \Console \Input \InputInterface ;
14- use Symfony \Component \Console \Input \InputOption ;
15- use Symfony \Component \Console \Output \OutputInterface ;
12+ use Symfony \Component \Console \Attribute \Option ;
1613use Symfony \Component \Console \Style \SymfonyStyle ;
1714use Symfony \Component \Validator \Validator \ValidatorInterface ;
1815
1916/**
2017 * @codeCoverageIgnore
2118 */
22- #[AsCommand('code-rhapsodie:dataflow:schedule:add ' , 'Create a scheduled dataflow ' )]
23- class AddScheduledDataflowCommand extends Command
19+ #[AsCommand('code-rhapsodie:dataflow:schedule:add ' , 'Create a scheduled dataflow ' , help: <<<'TXT'
20+ The <info>%command.name%</info> allows you to create a new scheduled dataflow.
21+ TXT)]
22+ final readonly class AddScheduledDataflowCommand
2423{
2524 public function __construct (private DataflowTypeRegistryInterface $ registry , private ScheduledDataflowRepository $ scheduledDataflowRepository , private ValidatorInterface $ validator , private ConnectionFactory $ connectionFactory )
2625 {
27- parent ::__construct ();
2826 }
2927
30- protected function configure (): void
31- {
32- $ this
33- ->setHelp ('The <info>%command.name%</info> allows you to create a new scheduled dataflow. ' )
34- ->addOption ('label ' , null , InputOption::VALUE_REQUIRED , 'Label of the scheduled dataflow ' )
35- ->addOption ('type ' , null , InputOption::VALUE_REQUIRED , 'Type of the scheduled dataflow (FQCN) ' )
36- ->addOption (
37- 'options ' ,
38- null ,
39- InputOption::VALUE_OPTIONAL ,
40- 'Options of the scheduled dataflow (ex: {"option1": "value1", "option2": "value2"}) '
41- )
42- ->addOption ('frequency ' , null , InputOption::VALUE_REQUIRED , 'Frequency of the scheduled dataflow ' )
43- ->addOption ('first_run ' , null , InputOption::VALUE_REQUIRED , 'Date for the first run of the scheduled dataflow (Y-m-d H:i:s) ' )
44- ->addOption ('enabled ' , null , InputOption::VALUE_REQUIRED , 'State of the scheduled dataflow ' )
45- ->addOption ('connection ' , null , InputOption::VALUE_REQUIRED , 'Define the DBAL connection to use ' );
46- }
47-
48- protected function execute (InputInterface $ input , OutputInterface $ output ): int
49- {
50- if ($ input ->getOption ('connection ' ) !== null ) {
51- $ this ->connectionFactory ->setConnectionName ($ input ->getOption ('connection ' ));
28+ public function __invoke (
29+ SymfonyStyle $ io ,
30+ #[Option('Label of the scheduled dataflow ' )] ?string $ label = null ,
31+ #[Option('Type of the scheduled dataflow (FQCN) ' )] ?string $ type = null ,
32+ #[Option('Options of the scheduled dataflow (ex: {"option1": "value1", "option2": "value2"}) ' )] ?string $ options = null ,
33+ #[Option('Frequency of the scheduled dataflow ' )] ?string $ frequency = null ,
34+ #[Option('Date for the first run of the scheduled dataflow (Y-m-d H:i:s) ' )] ?string $ firstRun = null ,
35+ #[Option('State of the scheduled dataflow ' )] ?bool $ enabled = null ,
36+ #[Option('Define the DBAL connection to use ' )] ?string $ connection = null ,
37+ ): int {
38+ if ($ connection !== null ) {
39+ $ this ->connectionFactory ->setConnectionName ($ connection );
5240 }
5341 $ choices = [];
5442 $ typeMapping = [];
@@ -57,36 +45,29 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5745 $ typeMapping [$ dataflowType ->getLabel ()] = $ fqcn ;
5846 }
5947
60- $ io = new SymfonyStyle ($ input , $ output );
61- $ label = $ input ->getOption ('label ' );
6248 if (!$ label ) {
6349 $ label = $ io ->ask ('What is the scheduled dataflow label? ' );
6450 }
65- $ type = $ input ->getOption ('type ' );
6651 if (!$ type ) {
6752 $ selectedType = $ io ->choice ('What is the scheduled dataflow type? ' , $ choices );
6853 $ type = $ typeMapping [$ selectedType ];
6954 }
70- $ options = $ input ->getOption ('options ' );
7155 if (!$ options ) {
7256 $ options = $ io ->ask (
7357 'What are the launch options for the scheduled dataflow? (ex: {"option1": "value1", "option2": "value2"}) ' ,
7458 json_encode ([])
7559 );
7660 }
77- $ frequency = $ input ->getOption ('frequency ' );
7861 if (!$ frequency ) {
7962 $ frequency = $ io ->choice (
8063 'What is the frequency for the scheduled dataflow? ' ,
8164 ScheduledDataflow::AVAILABLE_FREQUENCIES
8265 );
8366 }
84- $ firstRun = $ input ->getOption ('first_run ' );
8567 if (!$ firstRun ) {
8668 $ firstRun = $ io ->ask ('When is the first execution of the scheduled dataflow (format: Y-m-d H:i:s)? ' );
8769 }
88- $ enabled = $ input ->getOption ('enabled ' );
89- if (!$ enabled ) {
70+ if ($ enabled === null ) {
9071 $ enabled = $ io ->confirm ('Enable the scheduled dataflow? ' );
9172 }
9273
0 commit comments