Skip to content

Commit

Permalink
Move method to helper
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 10, 2024
1 parent 6cb8db3 commit 85989f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
11 changes: 1 addition & 10 deletions packages/framework/src/Console/Commands/PublishViewsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function handleInteractivePublish(string $selected): void
});

// Now we need to prompt the user for which files to publish
$selectedFiles = $this->promptForFiles($files, basename($target));
$selectedFiles = $publisher->promptForFiles($files, basename($target));

// Now we filter the files to only include the selected ones
$selectedFiles = $files->filter(fn (string $file): bool => in_array($file, $selectedFiles));
Expand All @@ -154,13 +154,4 @@ protected function handleInteractivePublish(string $selected): void

$this->infoComment($message);
}

protected function promptForFiles(Collection $files, string $baseDir): array
{
$choices = $files->mapWithKeys(/** @return array<string, string> */ function (string $source) use ($baseDir): array {
return [$source => Str::after($source, $baseDir.'/')];
});

return 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.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@

namespace Hyde\Console\Helpers;

use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use function Laravel\Prompts\multiselect;

/**
* @internal This class offloads logic from the PublishViewsCommand class and should not be used elsewhere.
*/
class InteractivePublishCommandHelper
{
//
public function promptForFiles(Collection $files, string $baseDir): array
{
$choices = $files->mapWithKeys(/** @return array<string, string> */ function (string $source) use ($baseDir): array {
return [$source => Str::after($source, $baseDir.'/')];
});

return 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.');
}
}

0 comments on commit 85989f4

Please sign in to comment.