Skip to content

Commit

Permalink
Adds open command (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro authored Sep 17, 2021
1 parent d3b03a4 commit bd0cd3d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/Commands/OpenCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Laravel\VaporCli\Commands;

use Laravel\VaporCli\Helpers;
use Laravel\VaporCli\Manifest;
use Symfony\Component\Console\Input\InputArgument;

class OpenCommand extends Command
{
/**
* Configure the command options.
*
* @return void
*/
protected function configure()
{
$this
->setName('open')
->addArgument('environment', InputArgument::OPTIONAL, 'The environment name', 'staging')
->setDescription('Open an environment in your default browser');
}

/**
* Execute the command.
*
* @return void
*/
public function handle()
{
Helpers::ensure_api_token_is_available();

$environment = $this->vapor->environmentNamed(
Manifest::id(),
$this->argument('environment')
);

if (empty($environment)) {
Helpers::abort(sprintf(
'Environment [%s] not found.',
$this->argument('environment')
));
}

$domain = ! empty($environment['latest_deployment']['root_domains'])
? $environment['latest_deployment']['root_domains'][0]
: $environment['vanity_domain'];

if (empty($domain)) {
Helpers::abort(sprintf(
'No domain assigned to [%s] environment.',
$this->argument('environment')
));
}

passthru(sprintf('open https://%s', $domain));
}
}
1 change: 1 addition & 0 deletions vapor
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ $app->add(new Commands\EnvPullCommand);
$app->add(new Commands\EnvPushCommand);
$app->add(new Commands\EnvCloneCommand);
$app->add(new Commands\EnvDeleteCommand);
$app->add(new Commands\OpenCommand);

// Secrets
$app->add(new Commands\SecretListCommand);
Expand Down

0 comments on commit bd0cd3d

Please sign in to comment.