Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "open" command #91

Merged
merged 1 commit into from
Sep 4, 2024
Merged
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
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();
}
}