🚧 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;
use App\Exceptions\Quit;
use App\Models\Input;
class GetShow extends Command
{
protected $signature = 'get:show ' .
'{--i|input=* : Input files} ' .
'{--u|url= : URL to download} ' .
'{--d|destination= : Directory of show} ' .
'{--t|title= : The title of the episode} ' .
'{--l|low : Put on low priority queue}' .
@ -19,24 +21,22 @@ class GetShow extends Command
public function handle(): int
{
$this->line(json_encode($this->options()));
# $this->ask('What?');
# throw new Quit('Nope', 5);
$files = $this->getFiles();
$dest = $this->getDestination();
$input = $this->getInput();
if ($this->confirm('Do you wish to continue?', true)) {
$this->line(json_encode($files));
$this->line(json_encode([$input, $dest]));
}
return static::SUCCESS;
}
protected function getFiles(): array
protected function getInput(): Input
{
$ret = new 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)) {
throw new Quit("$file is not a valid file");
}
@ -44,6 +44,22 @@ class GetShow extends Command
return realpath($file);
}, $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);
}
}