-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3b03a4
commit bd0cd3d
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters