Skip to content
Open
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 app/Commands/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use RuntimeException;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function Laravel\Prompts\confirm;
Expand All @@ -30,6 +31,18 @@ abstract class BaseCommand extends Command
use HasAClient;
use Validates;

protected function configure(): void
{
parent::configure();

$this->addOption(
'token',
null,
InputOption::VALUE_REQUIRED,
'Laravel Cloud API token (overrides stored tokens and LARAVEL_CLOUD_API_TOKEN env var)',
);
}

protected Form $form;

protected ?Resolvers $resolvers;
Expand Down
20 changes: 20 additions & 0 deletions app/Concerns/HasAClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ protected function ensureClient(bool $ignoreLocalConfig = false)

protected function ensureApiTokenExists(): void
{
// If a token is available via env var, no need to check config
$envToken = getenv('LARAVEL_CLOUD_API_TOKEN');
if ($envToken !== false && $envToken !== '') {
return;
}

$config = app(ConfigRepository::class);
$apiTokens = $config->apiTokens();

Expand All @@ -35,6 +41,20 @@ protected function ensureApiTokenExists(): void

protected function resolveApiToken(bool $ignoreLocalConfig = false): string
{
// --token flag takes highest priority
if ($this instanceof \Symfony\Component\Console\Command\Command
&& $this->getDefinition()->hasOption('token')
&& ($flagToken = $this->option('token'))
) {
return $flagToken;
}

// LARAVEL_CLOUD_API_TOKEN env var takes second priority
$envToken = getenv('LARAVEL_CLOUD_API_TOKEN');
if ($envToken !== false && $envToken !== '') {
return $envToken;
}

$config = app(ConfigRepository::class);
$apiTokens = $config->apiTokens();

Expand Down
Loading