🚧 Work on command

This commit is contained in:
Dan Jones 2022-03-05 19:51:04 -06:00
commit b1f1f77b17
2 changed files with 51 additions and 10 deletions

View file

@ -3,11 +3,13 @@
namespace App\Commands; namespace App\Commands;
use App\Exceptions\Quit; use App\Exceptions\Quit;
use App\Models\Input;
class GetShow extends Command class GetShow extends Command
{ {
protected $signature = 'get:show ' . protected $signature = 'get:show ' .
'{--i|input=* : Input files} ' . '{--i|input=* : Input files} ' .
'{--u|url= : URL to download} ' .
'{--d|destination= : Directory of show} ' . '{--d|destination= : Directory of show} ' .
'{--t|title= : The title of the episode} ' . '{--t|title= : The title of the episode} ' .
'{--l|low : Put on low priority queue}' . '{--l|low : Put on low priority queue}' .
@ -19,24 +21,22 @@ class GetShow extends Command
public function handle(): int public function handle(): int
{ {
$this->line(json_encode($this->options())); $this->line(json_encode($this->options()));
# $this->ask('What?'); $dest = $this->getDestination();
# throw new Quit('Nope', 5); $input = $this->getInput();
$files = $this->getFiles();
if ($this->confirm('Do you wish to continue?', true)) { if ($this->confirm('Do you wish to continue?', true)) {
$this->line(json_encode($files)); $this->line(json_encode([$input, $dest]));
} }
return static::SUCCESS; return static::SUCCESS;
} }
protected function getFiles(): array protected function getInput(): Input
{ {
$ret = new Input;
$input = $this->option('input'); $input = $this->option('input');
if (empty($input)) {
throw new Quit('No files given');
}
$files = array_map(function (string $file) { $ret->files = array_map(function (string $file) {
if (!file_exists($file)) { if (!file_exists($file)) {
throw new Quit("$file is not a valid file"); throw new Quit("$file is not a valid file");
} }
@ -44,6 +44,22 @@ class GetShow extends Command
return realpath($file); return realpath($file);
}, $input); }, $input);
return $files; // @todo Get additional files
$ret->url = $this->option('url');
$this->line(json_encode($ret));
$ret->assertValid();
return $ret;
}
protected function getDestination(): string
{
$dir = $this->option('destination');
throw_if(!is_dir($dir), Quit::class, "$dir is not a valid directory");
// @todo find show title
return realpath($dir);
} }
} }

25
app/Models/Input.php Normal file
View file

@ -0,0 +1,25 @@
<?php
namespace App\Models;
use App\Exceptions\Quit;
class Input
{
public ?array $files;
public ?string $url;
public function assertValid(): void
{
throw_if(
empty($this->files) && empty($this->url),
Quit::class,
'Must have either a valid file or URL'
);
}
public function hasURL(): bool
{
return !empty($this->url);
}
}