-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.go
58 lines (51 loc) · 1.22 KB
/
utils.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
48
49
50
51
52
53
54
55
56
57
58
package dialog
// Copyright 2016 Valeriy Solovyov <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
import (
// "bytes"
"fmt"
"os"
"os/exec"
// "strconv"
// "strings"
// "log"
// "time"
)
const (
DIALOG_PACKAGE_AUTO_NOT_FOUND = "Package not found!\nPlease install " + KDE + " or " + GTK + " or " + X + " or " + CONSOLE
)
// helper function that checks path and return error, nil
func getPathOeRaiseError(environment string) error {
var err error
switch environment {
case CONSOLE, KDE, GTK, X:
_, execution_error := exec.LookPath(environment)
if execution_error != nil {
err = fmt.Errorf("Package not found!\nPlease install " + environment)
}
case AUTO:
env := ""
for _, pkg := range []string{KDE, GTK, X, CONSOLE} {
_, execution_error := exec.LookPath(pkg)
if execution_error == nil {
env = pkg
break
}
}
if env == "" {
err = fmt.Errorf(DIALOG_PACKAGE_AUTO_NOT_FOUND)
}
case DIALOG_TEST_ENV:
break
default:
err = fmt.Errorf("Unknown package " + environment)
}
return err
}
func DialogFindPathOrExit(environment string) {
err := getPathOeRaiseError(environment)
if err != nil {
fmt.Println(os.Stderr, err.Error())
os.Exit(1)
}
}