Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Console/Commands/MakeAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string|\Closure>
*/
protected function promptForMissingArgumentsUsing(): array
{
return [
...parent::promptForMissingArgumentsUsing(),
'name' => 'What should the Saloon authenticator be named?',
];
}
}
45 changes: 45 additions & 0 deletions src/Console/Commands/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -86,6 +88,49 @@ protected function getArguments(): array
];
}

/**
* Prompt for missing input arguments using the returned questions.
*
* @return array<string, string|\Closure>
*/
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<int, string>
*/
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
*/
Expand Down
13 changes: 13 additions & 0 deletions src/Console/Commands/MakeConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string|\Closure>
*/
protected function promptForMissingArgumentsUsing(): array
{
return [
...parent::promptForMissingArgumentsUsing(),
'name' => 'What should the Saloon connector be named?',
];
}
}
13 changes: 13 additions & 0 deletions src/Console/Commands/MakePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string|\Closure>
*/
protected function promptForMissingArgumentsUsing(): array
{
return [
...parent::promptForMissingArgumentsUsing(),
'name' => 'What should the Saloon plugin be named?',
];
}
}
13 changes: 13 additions & 0 deletions src/Console/Commands/MakeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ protected function getOptions(): array
];
}

/**
* Prompt for missing input arguments using the returned questions.
*
* @return array<string, string|\Closure>
*/
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.
*/
Expand Down
13 changes: 13 additions & 0 deletions src/Console/Commands/MakeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string|\Closure>
*/
protected function promptForMissingArgumentsUsing(): array
{
return [
...parent::promptForMissingArgumentsUsing(),
'name' => 'What should the Saloon response be named?',
];
}
}