-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
64 lines (53 loc) · 1.11 KB
/
main.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
59
60
61
62
63
64
// Copyright 1999-2024. Plesk International GmbH.
package main
import (
"fmt"
"github.com/plesk/pleskapp/plesk/cmd"
"github.com/plesk/pleskapp/plesk/internal/config"
"github.com/plesk/pleskapp/plesk/internal/locales"
"os"
)
var (
commit string
date string
version string
)
func init() {
cmd.Commit = commit
cmd.BuildTime = date
cmd.Version = version
}
func main() {
home, err := os.UserHomeDir()
if err != nil {
panic(fmt.Errorf("failed obtaining current user home directory: %s", err))
}
path := home + "/.pleskrc"
f, err := os.Open(path)
if err != nil {
config.New(nil)
} else {
defer f.Close()
err = config.New(f)
if err != nil {
panic(err)
}
}
exitCode := 0
err = cmd.Execute()
if err != nil {
fmt.Println(locales.L.Get("errors.execution.failed.generic", err.Error()))
exitCode = 1
}
f, err = os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
if err != nil {
fmt.Println("Could not open the configuration for saving")
panic(err)
}
err = config.Save(f)
if err != nil {
fmt.Println("Could not save the configuration")
panic(err)
}
os.Exit(exitCode)
}