From 515ecbcfed3d4db3955303ae14e8ba1c7775515c Mon Sep 17 00:00:00 2001 From: Vic Demuzere Date: Tue, 4 Feb 2014 17:11:26 +0100 Subject: [PATCH] Use build tags instead of checking platform at runtime. --- open/exec.go | 19 +++++++++++++++++++ open/exec_darwin.go | 15 +++++++++++++++ open/exec_windows.go | 15 +++++++++++++++ open/open.go | 30 ------------------------------ 4 files changed, 49 insertions(+), 30 deletions(-) create mode 100644 open/exec.go create mode 100644 open/exec_darwin.go create mode 100644 open/exec_windows.go diff --git a/open/exec.go b/open/exec.go new file mode 100644 index 0000000..b225286 --- /dev/null +++ b/open/exec.go @@ -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) +} diff --git a/open/exec_darwin.go b/open/exec_darwin.go new file mode 100644 index 0000000..16160e6 --- /dev/null +++ b/open/exec_darwin.go @@ -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) +} diff --git a/open/exec_windows.go b/open/exec_windows.go new file mode 100644 index 0000000..b3b9b4d --- /dev/null +++ b/open/exec_windows.go @@ -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) +} diff --git a/open/open.go b/open/open.go index c90b693..b1f648f 100644 --- a/open/open.go +++ b/open/open.go @@ -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) - } -}