🚧 Work on command

This commit is contained in:
Dan Jones 2022-03-03 22:55:57 -06:00
commit 2fb1f346a9
7 changed files with 87 additions and 57 deletions

22
app/Commands/Command.php Normal file
View file

@ -0,0 +1,22 @@
<?php
namespace App\Commands;
use App\Exceptions\Quit;
use LaravelZero\Framework\Commands\Command as BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
abstract class Command extends BaseCommand
{
public function run(InputInterface $input, OutputInterface $output): int
{
try {
return parent::run($input, $output);
} catch (Quit $quit) {
$this->error($quit->getMessage());
return $quit->getCode() > 0 ? $quit->getCode() : 1;
}
}
}

49
app/Commands/GetShow.php Normal file
View file

@ -0,0 +1,49 @@
<?php
namespace App\Commands;
use App\Exceptions\Quit;
class GetShow extends Command
{
protected $signature = 'get:show ' .
'{--i|input=* : Input files} ' .
'{--d|destination= : Directory of show} ' .
'{--t|title= : The title of the episode} ' .
'{--l|low : Put on low priority queue}' .
'{--s|sync : Run synchronously}'
;
protected $description = 'Queue a show to re-encode or download';
public function handle(): int
{
$this->line(json_encode($this->options()));
# $this->ask('What?');
# throw new Quit('Nope', 5);
$files = $this->getFiles();
if ($this->confirm('Do you wish to continue?', true)) {
$this->line(json_encode($files));
}
return static::SUCCESS;
}
protected function getFiles(): array
{
$input = $this->option('input');
if (empty($input)) {
throw new Quit('No files given');
}
$files = array_map(function (string $file) {
if (!file_exists($file)) {
throw new Quit("$file is not a valid file");
}
return realpath($file);
}, $input);
return $files;
}
}

View file

@ -1,52 +0,0 @@
<?php
namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
use function Termwind\{render};
class InspireCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'inspire {name=Artisan}';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Display an inspiring quote';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
render(<<<'HTML'
<div class="py-1 ml-2">
<div class="px-1 bg-blue-300 text-black">Laravel Zero</div>
<em class="ml-1">
Simplicity is the ultimate sophistication.
</em>
</div>
HTML);
}
/**
* Define the command's schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
public function schedule(Schedule $schedule)
{
// $schedule->command(static::class)->everyMinute();
}
}

8
app/Exceptions/Quit.php Normal file
View file

@ -0,0 +1,8 @@
<?php
namespace App\Exceptions;
class Quit extends \RuntimeException
{
// ...
}

View file

@ -47,6 +47,7 @@ return [
\Illuminate\Queue\Console\PruneBatchesCommand::class, \Illuminate\Queue\Console\PruneBatchesCommand::class,
\Illuminate\Queue\Console\PruneFailedJobsCommand::class, \Illuminate\Queue\Console\PruneFailedJobsCommand::class,
\Illuminate\Queue\Console\RetryBatchCommand::class, \Illuminate\Queue\Console\RetryBatchCommand::class,
\Illuminate\Foundation\Console\TestMakeCommand::class,
], ],
/* /*

View file

@ -0,0 +1,7 @@
<?php
test('example', function () {
$response = $this->get('/');
$response->assertStatus(200);
});

View file

@ -1,5 +0,0 @@
<?php
it('inspire artisans', function () {
$this->artisan('inspire')->assertExitCode(0);
});