Merge pull request #3 from sorcix/master

Use build tags instead of checking platform at runtime.
This commit is contained in:
skratchdot 2014-02-04 10:56:14 -08:00
commit 79de5dd3fd
4 changed files with 49 additions and 30 deletions

19
open/exec.go Normal file
View File

@ -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)
}

15
open/exec_darwin.go Normal file
View File

@ -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)
}

15
open/exec_windows.go Normal file
View File

@ -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)
}

View File

@ -15,12 +15,6 @@
*/
package open
import (
"os/exec"
"path"
"runtime"
)
/*
Open a file, directory, or URI using the OS's default
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 {
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)
}
}