Issue #111: Open a site up in the browser on upping site#112
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements the feature requested in Issue #111 to automatically open the site URL in the user's default browser when a site is brought up via mchef. It adds OS detection helpers, a cross-platform browser-open method in CliService, and integrates it into both the Main::up() flow and the Up command.
Changes:
- Added
isMac()andisLinux()static methods to theOShelper class for cross-platform OS detection. - Added
openSite()method toCliServicethat opens a URL in the default browser, with CI mode detection and OS-specific command selection. - Integrated
openSite()into bothMain::up()and theUpcommand'sexecute()method to open the Moodle site after containers start.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Helpers/OS.php |
Added isMac() and isLinux() detection methods to complement existing isWindows(). |
src/Service/CliService.php |
Added openSite() method with CI-mode guard and cross-platform browser-open logic. |
src/Service/Main.php |
Added CliService dependency and call to openSite() after the up() workflow completes. |
src/Command/Up.php |
Added CliService dependency, wwwRoot notice, and openSite() call in the Up command. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (OS::isWindows()) { | ||
| $cmd = "start $url"; | ||
| } elseif (OS::isMac()) { | ||
| $cmd = "open $url"; | ||
| } elseif (OS::isLinux()) { | ||
| $cmd = "xdg-open $url"; |
There was a problem hiding this comment.
On Windows, the start command interprets the first quoted argument as a window title, not a URL. If you add escapeshellarg() around $url (as recommended for security), start will treat the quoted URL as a window title and fail to open the browser. The conventional fix is to use start "" <url> to provide an empty title first. Even without escaping, this is a good practice to handle URLs that might contain spaces.
| if (OS::isWindows()) { | |
| $cmd = "start $url"; | |
| } elseif (OS::isMac()) { | |
| $cmd = "open $url"; | |
| } elseif (OS::isLinux()) { | |
| $cmd = "xdg-open $url"; | |
| $escapedUrl = escapeshellarg($url); | |
| if (OS::isWindows()) { | |
| $cmd = 'start "" ' . $escapedUrl; | |
| } elseif (OS::isMac()) { | |
| $cmd = 'open ' . $escapedUrl; | |
| } elseif (OS::isLinux()) { | |
| $cmd = 'xdg-open ' . $escapedUrl; |
No description provided.