-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from Astrotomic/dev
add output to github commands
- Loading branch information
Showing
8 changed files
with
101 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Closure; | ||
use Illuminate\Console\Command as IlluminateCommand; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\LazyCollection; | ||
|
||
abstract class Command extends IlluminateCommand | ||
{ | ||
/** | ||
* @param int|iterable|Builder $totalSteps | ||
*/ | ||
public function withProgressBar($totalSteps, Closure $callback): void | ||
{ | ||
if ($totalSteps instanceof Builder) { | ||
$query = $totalSteps; | ||
|
||
$this->output->progressStart($query->count()); | ||
$query->eachById(function (Model $value) use ($callback): void { | ||
$callback($value); | ||
$this->output->progressAdvance(); | ||
}); | ||
$this->output->progressFinish(); | ||
|
||
return; | ||
} | ||
|
||
if (is_iterable($totalSteps)) { | ||
$this->output->progressStart(count($totalSteps)); | ||
LazyCollection::make($totalSteps)->each(function (mixed $value) use ($callback): void { | ||
$callback($value); | ||
$this->output->progressAdvance(); | ||
}); | ||
$this->output->progressFinish(); | ||
|
||
return; | ||
} | ||
|
||
$this->output->progressStart($totalSteps); | ||
|
||
LazyCollection::range(1, $totalSteps)->each(function (int $value) use ($callback): void { | ||
$callback($value); | ||
$this->output->progressAdvance(); | ||
}); | ||
|
||
$this->output->progressFinish(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters