diff --git a/src/Console/Commands/MakeAuthenticator.php b/src/Console/Commands/MakeAuthenticator.php index 27c8db4..98574de 100644 --- a/src/Console/Commands/MakeAuthenticator.php +++ b/src/Console/Commands/MakeAuthenticator.php @@ -40,4 +40,17 @@ class MakeAuthenticator extends MakeCommand * @var string */ protected $stub = 'saloon.authenticator.stub'; + + /** + * Prompt for missing input arguments using the returned questions. + * + * @return array + */ + protected function promptForMissingArgumentsUsing(): array + { + return [ + ...parent::promptForMissingArgumentsUsing(), + 'name' => 'What should the Saloon authenticator be named?', + ]; + } } diff --git a/src/Console/Commands/MakeCommand.php b/src/Console/Commands/MakeCommand.php index 8eab5f9..e7a3350 100644 --- a/src/Console/Commands/MakeCommand.php +++ b/src/Console/Commands/MakeCommand.php @@ -4,6 +4,8 @@ namespace Saloon\Laravel\Console\Commands; +use Illuminate\Support\Facades\File; +use function Laravel\Prompts\suggest; use Illuminate\Console\GeneratorCommand; use Symfony\Component\Console\Input\InputArgument; @@ -86,6 +88,49 @@ protected function getArguments(): array ]; } + /** + * Prompt for missing input arguments using the returned questions. + * + * @return array + */ + protected function promptForMissingArgumentsUsing(): array + { + return [ + 'integration' => fn () => suggest( + label: 'What is the related integration?', + options: fn (string $value) => $this->getExistingIntegrations($value), + required: true, + hint: 'Start typing to search or enter a new integration name' + ), + ]; + } + + /** + * Get existing integrations filtered by search value via prompt + * + * @return array + */ + protected function getExistingIntegrations(string $search = ''): array + { + $integrationsPath = config('saloon.integrations_path'); + + if (! File::isDirectory($integrationsPath)) { + return []; + } + + $directories = File::directories($integrationsPath); + $integrations = array_map(fn ($path) => basename($path), $directories); + + if (mb_strlen($search) === 0) { + return $integrations; + } + + return array_values(array_filter( + $integrations, + fn ($integration) => str_contains(mb_strtolower($integration), mb_strtolower($search)) + )); + } + /** * Returns the namespace without the default Saloon parts */ diff --git a/src/Console/Commands/MakeConnector.php b/src/Console/Commands/MakeConnector.php index e9cafe0..db3e723 100644 --- a/src/Console/Commands/MakeConnector.php +++ b/src/Console/Commands/MakeConnector.php @@ -72,4 +72,17 @@ protected function afterPromptingForMissingArguments(InputInterface $input, Outp $input->setOption('oauth', $supportOauth); } + + /** + * Prompt for missing input arguments using the returned questions. + * + * @return array + */ + protected function promptForMissingArgumentsUsing(): array + { + return [ + ...parent::promptForMissingArgumentsUsing(), + 'name' => 'What should the Saloon connector be named?', + ]; + } } diff --git a/src/Console/Commands/MakePlugin.php b/src/Console/Commands/MakePlugin.php index 6880cdb..92dc810 100644 --- a/src/Console/Commands/MakePlugin.php +++ b/src/Console/Commands/MakePlugin.php @@ -40,4 +40,17 @@ class MakePlugin extends MakeCommand * @var string */ protected $stub = 'saloon.plugin.stub'; + + /** + * Prompt for missing input arguments using the returned questions. + * + * @return array + */ + protected function promptForMissingArgumentsUsing(): array + { + return [ + ...parent::promptForMissingArgumentsUsing(), + 'name' => 'What should the Saloon plugin be named?', + ]; + } } diff --git a/src/Console/Commands/MakeRequest.php b/src/Console/Commands/MakeRequest.php index c4bc5ee..eaba0ed 100644 --- a/src/Console/Commands/MakeRequest.php +++ b/src/Console/Commands/MakeRequest.php @@ -62,6 +62,19 @@ protected function getOptions(): array ]; } + /** + * Prompt for missing input arguments using the returned questions. + * + * @return array + */ + protected function promptForMissingArgumentsUsing(): array + { + return [ + ...parent::promptForMissingArgumentsUsing(), + 'name' => 'What should the Saloon request be named?', + ]; + } + /** * Interact further with the user if they were prompted for missing arguments. */ diff --git a/src/Console/Commands/MakeResponse.php b/src/Console/Commands/MakeResponse.php index 1ec0339..e099b36 100644 --- a/src/Console/Commands/MakeResponse.php +++ b/src/Console/Commands/MakeResponse.php @@ -40,4 +40,17 @@ class MakeResponse extends MakeCommand * @var string */ protected $stub = 'saloon.response.stub'; + + /** + * Prompt for missing input arguments using the returned questions. + * + * @return array + */ + protected function promptForMissingArgumentsUsing(): array + { + return [ + ...parent::promptForMissingArgumentsUsing(), + 'name' => 'What should the Saloon response be named?', + ]; + } }