turtle icon indicating copy to clipboard operation
turtle copied to clipboard

GH-115: Multiplatform open command

Open lordcodes opened this issue 2 years ago • 3 comments

Checklist

  • [X] I've read the guide for contributing.
  • [X] I've checked there are no other open pull requests for the same change.
  • [X] I've formatted all code changes with ./gradlew lcCodeFormat.
  • [X] I've ran all checks with ./gradlew lcChecks.
  • [X] I've updated documentation if needed.
  • [x] I've added or updated tests for changes.

Reason for change

Closes #115

Description

  • There was already openFile that works on Mac and takes a path. This path could actually be a web URL or a file path.
  • Added open that openFile just calls, to avoid changing public API.
  • Make open run different commands for Mac, Windows and Linux to make it multiplatform.

lordcodes avatar Aug 06 '22 00:08 lordcodes

So now that can be simplified quite a bit :)

object Multiplatform {
    /**
     * Open a given url in the default browser
     */
    fun openUrl(url: URL): Command = when(OS.current) {
        Mac -> Executable("open") + Arguments(url)
        Linux -> Executable("xdg-open") + Arguments(url) 
        Windows -> Executable("cmd.exe") + Arguments("/c", url))
    }
}

jmfayard avatar Aug 29 '22 22:08 jmfayard

@jmfayard you beat me to it, I was going to check if this PR could change based on the other changes.

Although the main reason this has sat open is I need to actually test it on Windows and Linux.

lordcodes avatar Aug 30 '22 07:08 lordcodes

yes that's the hard part, I was wondering what's the best way to have Linx/Windows VM on my mac

jmfayard avatar Aug 30 '22 07:08 jmfayard