Skip to content

Commit

Permalink
add convenient progress bar method
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Nov 17, 2020
1 parent 22e4182 commit 4e52a60
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Illuminate/Console/Concerns/InteractsWithIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Console\Concerns;

use Closure;
use Illuminate\Console\OutputStyle;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -237,6 +238,38 @@ public function table($headers, $rows, $tableStyle = 'default', array $columnSty
$table->render();
}

/**
* Execute a given callback while advancing a progress bar.
*
* @param iterable|int $totalSteps
* @param \Closure $callback
* @return mixed|void
*/
public function withProgressBar($totalSteps = 0, Closure $callback)

This comment has been minimized.

Copy link
@crynobone

crynobone Nov 18, 2020

Member
During class fetch: Uncaught ErrorException: Required parameter $callback follows optional parameter $totalSteps in /home/runner/work/testbench-core/testbench-core/vendor/laravel/framework/src/Illuminate/Console/Concerns/InteractsWithIO.php:248

This code failed on PHP 8.

https://github.com/orchestral/testbench-core/runs/1415242530?check_suite_focus=true

{
$bar = $this->output->createProgressBar(
is_iterable($totalSteps) ? count($totalSteps) : $totalSteps
);

$bar->start();

if (is_iterable($totalSteps)) {
foreach ($totalSteps as $value) {
$callback($value, $bar);

$bar->advance();
}
} else {
$callback($bar);
}

$bar->finish();

if (is_iterable($totalSteps)) {
return $totalSteps;
}
}

/**
* Write a string as information output.
*
Expand Down

0 comments on commit 4e52a60

Please sign in to comment.