forked from vbatts/gobox
/
main.go
53 lines (47 loc) · 999 Bytes
/
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
package main
import (
"errors"
"github.com/surma/gobox/pkg/common"
"os"
"path/filepath"
)
func init() {
// "gobox" has to be added here for two reasons
// 1.) So it can't be removed, it's core functionalty
// 2.) It causes cyclic dependencies otherwise
Applets["gobox"] = Gobox
}
func run() {
callname := filepath.Base(os.Args[0])
applet, ok := Applets[callname]
if !ok {
panic(errors.New("Could not find applet \"" + callname + "\""))
}
// If the Gobox applet is called (i.e. the executable itself)
// check, if the second parameter is an applet name.
// If so, call that applet instead
args := os.Args
if callname == "gobox" && len(args) >= 2 {
subapplet, ok := Applets[args[1]]
if ok {
applet = subapplet
args = args[1:]
}
}
e := applet(args)
if e != nil {
panic(e)
}
}
func main() {
defer func() {
if p := recover(); p != nil {
e, ok := p.(error)
if !ok {
e = errors.New("Some error occured")
}
common.DumpError(e)
}
}()
run()
}