-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfp.go
47 lines (38 loc) · 1014 Bytes
/
sfp.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
37
38
39
40
41
42
43
44
45
46
47
// Package sfp provides utilities for cross-platform file selection using native dialogs
package sfp
import (
"fmt"
"io"
"io/ioutil"
"os/exec"
)
// Pick shells out to the system's native file selection dialog and returns the selected filepath along with any errors encountered
func Pick() (string, error) {
return pick()
}
// PickMultiple shells out to the system's native file selection dialog and returns all selected filepaths along with any errors encountered
func PickMultiple() ([]string, error) {
return pickMultiple()
}
func run(cmd *exec.Cmd) (io.Reader, error) {
stdout, err := cmd.StdoutPipe()
if err != nil {
return stdout, err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return stdout, err
}
if err := cmd.Start(); err != nil {
return stdout, err
}
e, err := ioutil.ReadAll(stderr)
if err != nil {
return stdout, err
}
// stderr should not report anything. If it does, bail
if string(e) != "" {
return stdout, fmt.Errorf(string(e))
}
return stdout, nil
}