🚧 Work on command
This commit is contained in:
parent
b7f5ee034a
commit
2fb1f346a9
7 changed files with 87 additions and 57 deletions
22
app/Commands/Command.php
Normal file
22
app/Commands/Command.php
Normal 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
49
app/Commands/GetShow.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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
8
app/Exceptions/Quit.php
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
class Quit extends \RuntimeException
|
||||||
|
{
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
@ -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,
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
7
tests/Feature/Commands/GetShowTest.php
Normal file
7
tests/Feature/Commands/GetShowTest.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
test('example', function () {
|
||||||
|
$response = $this->get('/');
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
});
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
it('inspire artisans', function () {
|
|
||||||
$this->artisan('inspire')->assertExitCode(0);
|
|
||||||
});
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue