Skip to content

Commit

Permalink
Add OpenCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Sep 4, 2024
1 parent 0b355da commit b127b4d
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions app/Commands/OpenCommand.php
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();
}
}

0 comments on commit b127b4d

Please sign in to comment.