Debian Codegraph @

open.go

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