1010use Symfony \Component \Console \Command \Command ;
1111use Symfony \Component \Console \Helper \Table ;
1212use Symfony \Component \Console \Input \InputInterface ;
13+ use Symfony \Component \Console \Input \InputOption ;
1314use Symfony \Component \Console \Output \OutputInterface ;
1415
1516class ListCommand extends Command {
17+ private const NUMBER_OF_RUN_DATES = 3 ;
18+
1619 /**
1720 * @var Scheduler
1821 */
@@ -28,19 +31,32 @@ protected function configure() {
2831 $ this
2932 ->setName ("ts:list " )
3033 ->setDescription ("List the existing tasks " )
31- ->setHelp ("This command display the list of registered tasks. " );
34+ ->setHelp ("This command display the list of registered tasks. " )
35+ ->addOption ("show-run-dates " , null , InputOption::VALUE_OPTIONAL , "Show next run dates (default value: " . self ::NUMBER_OF_RUN_DATES . ") " , false );
3236 }
3337
3438 protected function execute (InputInterface $ input , OutputInterface $ output ) {
39+ $ numberOfRunDates = $ input ->getOption ('show-run-dates ' ) ?? self ::NUMBER_OF_RUN_DATES ;
40+ $ showRunDates = $ numberOfRunDates !== false ;
41+
3542 $ table = new Table ($ output );
36- $ table ->setHeaders ([
37- "ID " ,
38- "Class " ,
39- ]);
40-
41- $ id = 1 ;
42- foreach ($ this ->scheduler ->getTasks () as $ task ) {
43- $ table ->addRow ([$ id ++, get_class ($ task )]);
43+ $ tableHeaders = ["ID " , "Class " ];
44+
45+ if ($ showRunDates ) {
46+ $ tableHeaders [] = "Next " . $ numberOfRunDates . " run dates " ;
47+ }
48+
49+ $ table ->setHeaders ($ tableHeaders );
50+
51+ foreach ($ this ->scheduler ->getTasks () as $ id => $ task ) {
52+ $ row = [($ id + 1 ), get_class ($ task )];
53+
54+ if ($ showRunDates ) {
55+ $ nextRunDates = $ task ->getNextRunDates ($ numberOfRunDates );
56+ $ row [] = implode (', ' , $ nextRunDates );
57+ }
58+
59+ $ table ->addRow ($ row );
4460 };
4561
4662 $ table ->render ();
0 commit comments