summaryrefslogtreecommitdiff
path: root/vendor/github.com/skratchdot/open-golang
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2019-01-12 18:39:45 +0100
committerRuben Pollan <meskio@sindominio.net>2019-01-17 12:30:32 +0100
commitb1247d2d0d51108c910a73891ff3116e5f032ab1 (patch)
treee9948964f0bfb1ad2df3bc7bad02aa1f41ccfbd8 /vendor/github.com/skratchdot/open-golang
parentefcb8312e31b5c2261b1a1e95ace55b322cfcc27 (diff)
[pkg] all your deps are vendored to us
Diffstat (limited to 'vendor/github.com/skratchdot/open-golang')
-rw-r--r--vendor/github.com/skratchdot/open-golang/LICENSE-MIT22
-rw-r--r--vendor/github.com/skratchdot/open-golang/open/exec.go18
-rw-r--r--vendor/github.com/skratchdot/open-golang/open/exec_darwin.go15
-rw-r--r--vendor/github.com/skratchdot/open-golang/open/exec_windows.go33
-rw-r--r--vendor/github.com/skratchdot/open-golang/open/open.go50
-rw-r--r--vendor/github.com/skratchdot/open-golang/open/open_test.go70
6 files changed, 208 insertions, 0 deletions
diff --git a/vendor/github.com/skratchdot/open-golang/LICENSE-MIT b/vendor/github.com/skratchdot/open-golang/LICENSE-MIT
new file mode 100644
index 0000000..afd04c8
--- /dev/null
+++ b/vendor/github.com/skratchdot/open-golang/LICENSE-MIT
@@ -0,0 +1,22 @@
+Copyright (c) 2013 skratchdot
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/vendor/github.com/skratchdot/open-golang/open/exec.go b/vendor/github.com/skratchdot/open-golang/open/exec.go
new file mode 100644
index 0000000..1b0e713
--- /dev/null
+++ b/vendor/github.com/skratchdot/open-golang/open/exec.go
@@ -0,0 +1,18 @@
+// +build !windows,!darwin
+
+package open
+
+import (
+ "os/exec"
+)
+
+// http://sources.debian.net/src/xdg-utils/1.1.0~rc1%2Bgit20111210-7.1/scripts/xdg-open/
+// http://sources.debian.net/src/xdg-utils/1.1.0~rc1%2Bgit20111210-7.1/scripts/xdg-mime/
+
+func open(input string) *exec.Cmd {
+ return exec.Command("xdg-open", input)
+}
+
+func openWith(input string, appName string) *exec.Cmd {
+ return exec.Command(appName, input)
+}
diff --git a/vendor/github.com/skratchdot/open-golang/open/exec_darwin.go b/vendor/github.com/skratchdot/open-golang/open/exec_darwin.go
new file mode 100644
index 0000000..16160e6
--- /dev/null
+++ b/vendor/github.com/skratchdot/open-golang/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/vendor/github.com/skratchdot/open-golang/open/exec_windows.go b/vendor/github.com/skratchdot/open-golang/open/exec_windows.go
new file mode 100644
index 0000000..59f56b0
--- /dev/null
+++ b/vendor/github.com/skratchdot/open-golang/open/exec_windows.go
@@ -0,0 +1,33 @@
+// +build windows
+
+package open
+
+import (
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "syscall"
+)
+
+var (
+ cmd = "url.dll,FileProtocolHandler"
+ runDll32 = filepath.Join(os.Getenv("SYSTEMROOT"), "System32", "rundll32.exe")
+)
+
+func cleaninput(input string) string {
+ r := strings.NewReplacer("&", "^&")
+ return r.Replace(input)
+}
+
+func open(input string) *exec.Cmd {
+ cmd := exec.Command(runDll32, cmd, input)
+ cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
+ return cmd
+}
+
+func openWith(input string, appName string) *exec.Cmd {
+ cmd := exec.Command("cmd", "/C", "start", "", appName, cleaninput(input))
+ cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
+ return cmd
+}
diff --git a/vendor/github.com/skratchdot/open-golang/open/open.go b/vendor/github.com/skratchdot/open-golang/open/open.go
new file mode 100644
index 0000000..b1f648f
--- /dev/null
+++ b/vendor/github.com/skratchdot/open-golang/open/open.go
@@ -0,0 +1,50 @@
+/*
+
+ Open a file, directory, or URI using the OS's default
+ application for that object type. Optionally, you can
+ specify an application to use.
+
+ This is a proxy for the following commands:
+
+ OSX: "open"
+ Windows: "start"
+ Linux/Other: "xdg-open"
+
+ This is a golang port of the node.js module: https://github.com/pwnall/node-open
+
+*/
+package open
+
+/*
+ Open a file, directory, or URI using the OS's default
+ application for that object type. Wait for the open
+ command to complete.
+*/
+func Run(input string) error {
+ return open(input).Run()
+}
+
+/*
+ Open a file, directory, or URI using the OS's default
+ application for that object type. Don't wait for the
+ open command to complete.
+*/
+func Start(input string) error {
+ return open(input).Start()
+}
+
+/*
+ Open a file, directory, or URI using the specified application.
+ Wait for the open command to complete.
+*/
+func RunWith(input string, appName string) error {
+ return openWith(input, appName).Run()
+}
+
+/*
+ Open a file, directory, or URI using the specified application.
+ Don't wait for the open command to complete.
+*/
+func StartWith(input string, appName string) error {
+ return openWith(input, appName).Start()
+}
diff --git a/vendor/github.com/skratchdot/open-golang/open/open_test.go b/vendor/github.com/skratchdot/open-golang/open/open_test.go
new file mode 100644
index 0000000..5db2da2
--- /dev/null
+++ b/vendor/github.com/skratchdot/open-golang/open/open_test.go
@@ -0,0 +1,70 @@
+package open
+
+import "testing"
+
+func TestRun(t *testing.T) {
+ // shouldn't error
+ input := "https://google.com/"
+ err := Run(input)
+ if err != nil {
+ t.Errorf("open.Run(\"%s\") threw an error: %s", input, err)
+ }
+
+ // should error
+ input = "xxxxxxxxxxxxxxx"
+ err = Run(input)
+ if err == nil {
+ t.Errorf("Run(\"%s\") did not throw an error as expected", input)
+ }
+}
+
+func TestStart(t *testing.T) {
+ // shouldn't error
+ input := "https://google.com/"
+ err := Start(input)
+ if err != nil {
+ t.Errorf("open.Start(\"%s\") threw an error: %s", input, err)
+ }
+
+ // shouldn't error
+ input = "xxxxxxxxxxxxxxx"
+ err = Start(input)
+ if err != nil {
+ t.Errorf("open.Start(\"%s\") shouldn't even fail on invalid input: %s", input, err)
+ }
+}
+
+func TestRunWith(t *testing.T) {
+ // shouldn't error
+ input := "https://google.com/"
+ app := "firefox"
+ err := RunWith(input, app)
+ if err != nil {
+ t.Errorf("open.RunWith(\"%s\", \"%s\") threw an error: %s", input, app, err)
+ }
+
+ // should error
+ app = "xxxxxxxxxxxxxxx"
+ err = RunWith(input, app)
+ if err == nil {
+ t.Errorf("RunWith(\"%s\", \"%s\") did not throw an error as expected", input, app)
+ }
+}
+
+func TestStartWith(t *testing.T) {
+ // shouldn't error
+ input := "https://google.com/"
+ app := "firefox"
+ err := StartWith(input, app)
+ if err != nil {
+ t.Errorf("open.StartWith(\"%s\", \"%s\") threw an error: %s", input, app, err)
+ }
+
+ // shouldn't error
+ input = "[<Invalid URL>]"
+ err = StartWith(input, app)
+ if err != nil {
+ t.Errorf("StartWith(\"%s\", \"%s\") shouldn't even fail on invalid input: %s", input, app, err)
+ }
+
+}