forked from mirror/open-golang
Merge pull request #3 from sorcix/master
Use build tags instead of checking platform at runtime.
This commit is contained in:
commit
79de5dd3fd
|
@ -0,0 +1,19 @@
|
||||||
|
// +build !windows,!darwin
|
||||||
|
|
||||||
|
package open
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func open(input string) *exec.Cmd {
|
||||||
|
_, file, _, _ := runtime.Caller(0)
|
||||||
|
app := path.Join(path.Dir(file), "..", "vendor", "xdg-open")
|
||||||
|
return exec.Command(app, input)
|
||||||
|
}
|
||||||
|
|
||||||
|
func openWith(input string, appName string) *exec.Cmd {
|
||||||
|
return exec.Command(appName, input)
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
// +build darwin
|
||||||
|
|
||||||
|
package open
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func open(input string) *exec.Cmd {
|
||||||
|
return exec.Command("open", input)
|
||||||
|
}
|
||||||
|
|
||||||
|
func openWith(input string, appName string) *exec.Cmd {
|
||||||
|
return exec.Command("open", "-a", appName, input)
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package open
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func open(input string) *exec.Cmd {
|
||||||
|
return exec.Command("start", "", input)
|
||||||
|
}
|
||||||
|
|
||||||
|
func openWith(input string, appName string) *exec.Cmd {
|
||||||
|
return exec.Command("start", "", appName, input)
|
||||||
|
}
|
30
open/open.go
30
open/open.go
|
@ -15,12 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package open
|
package open
|
||||||
|
|
||||||
import (
|
|
||||||
"os/exec"
|
|
||||||
"path"
|
|
||||||
"runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Open a file, directory, or URI using the OS's default
|
Open a file, directory, or URI using the OS's default
|
||||||
application for that object type. Wait for the open
|
application for that object type. Wait for the open
|
||||||
|
@ -54,27 +48,3 @@ func RunWith(input string, appName string) error {
|
||||||
func StartWith(input string, appName string) error {
|
func StartWith(input string, appName string) error {
|
||||||
return openWith(input, appName).Start()
|
return openWith(input, appName).Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
func open(input string) *exec.Cmd {
|
|
||||||
switch runtime.GOOS {
|
|
||||||
case "darwin":
|
|
||||||
return exec.Command("open", input)
|
|
||||||
case "windows":
|
|
||||||
return exec.Command("start", "", input)
|
|
||||||
default:
|
|
||||||
_, file, _, _ := runtime.Caller(0)
|
|
||||||
app := path.Join(path.Dir(file), "..", "vendor", "xdg-open")
|
|
||||||
return exec.Command(app, input)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func openWith(input string, appName string) *exec.Cmd {
|
|
||||||
switch runtime.GOOS {
|
|
||||||
case "darwin":
|
|
||||||
return exec.Command("open", "-a", appName, input)
|
|
||||||
case "windows":
|
|
||||||
return exec.Command("start", "", appName, input)
|
|
||||||
default:
|
|
||||||
return exec.Command(appName, input)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue