mpyw / streamable-console
Call interactive artisan command using arbitrary stream
v1.1.2
2023-03-13 11:51 UTC
Requires
- php: ^8.0
- guzzlehttp/psr7: ^1.7
- illuminate/console: ^9.0 || ^10.0 || ^11.0
- illuminate/contracts: ^9.0 || ^10.0 || ^11.0
Requires (Dev)
- mockery/mockery: ^1.3.3 || ^1.4.2
- orchestra/testbench: *
- orchestra/testbench-core: ^4.9 || ^5.9 || >=6.6
- phpunit/phpunit: >=9.5
README
Call interactive artisan command using arbitrary stream.
Requirements
- PHP:
^8.0
- Laravel:
^9.0 || ^10.0
- guzzlehttp/psr7:
^1.7
Installing
composer require mpyw/streamable-console
Usage
Using Stream
<?php namespace App\Console\Commands; use Illuminate\Console\Command; class QuizCommand extends Command { protected $signature = 'example:quiz'; /** * @return int */ public function handle(): int { // We need to type "no" and press Enter to pass if ($this->confirm('Is one plus one equals to three?', true)) { return 1; } return 0; } }
<?php namespace App\Console\Commands; use Illuminate\Console\Command; use Mpyw\StreamableConsole\Streamable; class RunCommand extends Command { use Streamable; protected $signature = 'example:run'; /** * @return int */ public function handle(): int { // Type "no" and press Enter return $this->usingInputStream("no\n")->call('example:quiz'); } }
Using Infinite Input (yes
command emulation)
<?php namespace App\Console\Commands; use Illuminate\Console\Command; class QuizCommand extends Command { protected $signature = 'example:quiz'; /** * @return int */ public function handle(): int { // We need to type "no" and press Enter to pass at least for three times if ($this->confirm('Is one plus one equals to three?', true)) { return 1; } if ($this->confirm('Is one plus one equals to three?', true)) { return 1; } if ($this->confirm('Is one plus one equals to three?', true)) { return 1; } return 0; } }
<?php namespace App\Console\Commands; use Illuminate\Console\Command; use Mpyw\StreamableConsole\Streamable; class RunCommand extends Command { use Streamable; protected $signature = 'example:run'; /** * @return int */ public function handle(): int { // Infinitely type "no" and press Enter return $this->usingInfiniteInput("no\n")->call('example:quiz'); } }
Note that you can use yes()
as an alias of usingInfiniteInput()
.