-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from mpociot/feature/forge-open-command
- Loading branch information
Showing
1 changed file
with
55 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,55 @@ | ||
<?php | ||
|
||
namespace App\Commands; | ||
|
||
use Symfony\Component\Process\Process; | ||
|
||
class OpenCommand extends Command | ||
{ | ||
use Concerns\InteractsWithEvents; | ||
|
||
/** | ||
* The signature of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'open {site? : The site name}'; | ||
|
||
/** | ||
* The description of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Open a site in forge.laravel.com'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$siteId = $this->askForSite('Which site would you like to open'); | ||
$serverId = $this->currentServer()->id; | ||
|
||
$url = "https://forge.laravel.com/servers/$serverId/sites/$siteId"; | ||
|
||
$os = strtolower(php_uname(PHP_OS)); | ||
|
||
if (strpos($os, 'darwin') !== false) { | ||
$open = 'open'; | ||
} elseif (strpos($os, 'linux') !== false) { | ||
$open = 'xdg-open'; | ||
} else { | ||
$this->step("Can't open your browser, you'll have to manually navigate to {$url}"); | ||
return; | ||
} | ||
|
||
$this->step("Opening site in your browser..."); | ||
|
||
$command = [$open, $url]; | ||
|
||
$process = new Process($command); | ||
$process->run(); | ||
} | ||
} |