forked from rkoesters/xdg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen.go
36 lines (33 loc) · 882 Bytes
/
open.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Package xdg provides access to the XDG specs. Most of the
// functionality can be found in the subpackages.
package xdg
import (
"errors"
"os/exec"
)
// These errors can be returned by Open.
var (
ErrSyntax = errors.New("error in command line syntax")
ErrFileNotFound = errors.New("one of the files passed on the command line did not exist")
ErrToolNotFound = errors.New("a required tool could not be found")
ErrFailed = errors.New("the action failed")
)
// Open runs the command xdg-open with the given uri as an argument.
func Open(uri string) error {
c := exec.Command("xdg-open", uri)
err := c.Run()
if err == nil {
return nil
}
switch err.Error() {
case "exit status 1":
return ErrSyntax
case "exit status 2":
return ErrFileNotFound
case "exit status 3":
return ErrToolNotFound
case "exit status 4":
return ErrFailed
}
return err
}