Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 11, 2024
1 parent 18ae73c commit 0fc9330
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Hyde\Hyde;
use Illuminate\Support\Facades\Artisan;

use function Laravel\Prompts\multiselect;
use function str_replace;
use function sprintf;
use function strstr;
Expand Down Expand Up @@ -114,7 +115,11 @@ protected function handleInteractivePublish(string $selected): void
$group = $this->options[$selected]['group'];
$publisher = new InteractivePublishCommandHelper($group);

$message = $publisher->handle();
$choices = $publisher->getFileChoices();

$selectedFiles = multiselect('Select the files you want to publish (CTRL+A to toggle all)', $choices, [], 10, 'required', hint: 'Navigate with arrow keys, space to select, enter to confirm.');

$message = $publisher->handle($selectedFiles);
$this->infoComment($message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,26 @@ class InteractivePublishCommandHelper
protected readonly string $source;
protected readonly string $target;

/** @var \Illuminate\Support\Collection<string, string> Map of source files to target files */
protected readonly Collection $publishableFilesMap;

public function __construct(string $group)
{
$this->group = $group;
}

public function handle(): string
public function getFileChoices(): Collection
{
$publishableFilesMap = $this->mapPublishableFiles($this->findAllFilesForTag());
$this->publishableFilesMap = $this->mapPublishableFiles($this->findAllFilesForTag());

return $this->publishableFilesMap->mapWithKeys(/** @return array<string, string> */ function (string $source): array {
return [$source => Str::after($source, basename($this->target) . '/')];
});
}

$choices = $this->getFileChoices($publishableFilesMap);
$selectedFiles = multiselect('Select the files you want to publish (CTRL+A to toggle all)', $choices, [], 10, 'required', hint: 'Navigate with arrow keys, space to select, enter to confirm.');
$filesToPublish = $publishableFilesMap->filter(fn (string $file): bool => in_array($file, $selectedFiles));
public function handle(array $selectedFiles): string
{
$filesToPublish = $this->publishableFilesMap->filter(fn (string $file): bool => in_array($file, $selectedFiles));

$this->publishFiles($filesToPublish);

Expand Down Expand Up @@ -74,11 +82,4 @@ protected function getPublishedFilesForOutput(Collection $selectedFiles): string
{
return collect($selectedFiles)->map(fn (string $file): string => Str::after($file, basename($this->source).'/'))->implode(', ');
}

public function getFileChoices(Collection $publishableFilesMap): Collection
{
return $publishableFilesMap->mapWithKeys(/** @return array<string, string> */ function (string $source): array {
return [$source => Str::after($source, basename($this->target) . '/')];
});
}
}

0 comments on commit 0fc9330

Please sign in to comment.