File: open.go

package info (click to toggle)
golang-github-rkoesters-xdg 0.0~git20181125.edd15b8-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 220 kB
  • sloc: makefile: 5
file content (37 lines) | stat: -rw-r--r-- 904 bytes parent folder | download | duplicates (2)
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
37
// 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 {
		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
		default:
			return err
		}
	}
	return nil
}