diff --git a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php index a3556e35a13d..d67c3cd562e2 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php @@ -62,13 +62,17 @@ public function handle(Schedule $schedule) $expressionSpacing = $this->getCronExpressionSpacing($events); + $repeatExpressionSpacing = $this->getRepeatExpressionSpacing($events); + $timezone = new DateTimeZone($this->option('timezone') ?? config('app.timezone')); $events = $this->sortEvents($events, $timezone); - $events = $events->map(function ($event) use ($terminalWidth, $expressionSpacing, $timezone) { + $events = $events->map(function ($event) use ($terminalWidth, $expressionSpacing, $repeatExpressionSpacing, $timezone) { $expression = $this->formatCronExpression($event->expression, $expressionSpacing); + $repeatExpression = str_pad($this->getRepeatExpression($event), $repeatExpressionSpacing); + $command = $event->command ?? ''; $description = $event->description ?? ''; @@ -101,15 +105,16 @@ public function handle(Schedule $schedule) $hasMutex = $event->mutex->exists($event) ? 'Has Mutex › ' : ''; $dots = str_repeat('.', max( - $terminalWidth - mb_strlen($expression.$command.$nextDueDateLabel.$nextDueDate.$hasMutex) - 8, 0 + $terminalWidth - mb_strlen($expression.$repeatExpression.$command.$nextDueDateLabel.$nextDueDate.$hasMutex) - 8, 0 )); // Highlight the parameters... $command = preg_replace("#(php artisan [\w\-:]+) (.+)#", '$1 $2', $command); return [sprintf( - ' %s %s%s %s%s %s', + ' %s %s %s%s %s%s %s', $expression, + $repeatExpression, $command, $dots, $hasMutex, @@ -141,6 +146,28 @@ private function getCronExpressionSpacing($events) return collect($rows[0] ?? [])->keys()->map(fn ($key) => $rows->max($key))->all(); } + /** + * Gets the spacing to be used on each event row. + * + * @param \Illuminate\Support\Collection $events + * @return int + */ + private function getRepeatExpressionSpacing($events) + { + return $events->map(fn ($event) => mb_strlen($this->getRepeatExpression($event)))->max(); + } + + /** + * Gets the repeat expression for an event. + * + * @param \Illuminate\Console\Scheduling\Event $event + * @return string + */ + private function getRepeatExpression($event) + { + return $event->isRepeatable() ? "{$event->repeatSeconds}s " : ''; + } + /** * Sorts the events by due date if option set. *