-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
91 lines (81 loc) · 1.8 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/sethpollack/dockerbox/cmd"
"github.com/sethpollack/dockerbox/cue"
"github.com/sethpollack/dockerbox/dockerbox"
"github.com/sethpollack/dockerbox/runner"
"github.com/spf13/afero"
)
func main() {
fs := afero.NewOsFs()
// used to symlink to dockerbox binaries
exe, err := os.Executable()
if err != nil {
fmt.Printf("failed to get executable: %v", err)
os.Exit(1)
}
// used to find local config overrides
wd, err := os.Getwd()
if err != nil {
fmt.Printf("failed to get working directory: %v", err)
os.Exit(1)
}
cfg, err := dockerbox.New(
filepath.Base(os.Args[0]),
wd,
exe,
os.Args[1:],
)
if err != nil {
fmt.Printf("failed to create config: %v", err)
os.Exit(1)
}
files, err := dockerbox.GetConfigurations(fs, wd, cfg.RootDir)
if err != nil {
fmt.Printf("failed to get configurations: %v", err)
os.Exit(1)
}
root, err := cue.New(fs, files)
if err != nil {
fmt.Printf("failed to load applets: %v", err)
os.Exit(1)
}
if _, err := fs.Stat(cfg.InstallDir); os.IsNotExist(err) {
err := fs.MkdirAll(cfg.InstallDir, os.FileMode(0744))
if err != nil {
fmt.Printf("failed to create install directory: %v", err)
os.Exit(1)
}
}
switch cfg.EntryPoint {
case "dockerbox":
command, err := cmd.NewRootCmd(cfg, root)
if err != nil {
fmt.Printf("failed to create root command: %v", err)
os.Exit(1)
}
err = command.Execute()
if err != nil {
fmt.Printf("failed to run command: %v", err)
os.Exit(1)
}
default:
cmds, err := root.Compile(cfg)
if err != nil {
fmt.Printf("failed to compile applet: %v", err)
os.Exit(1)
}
err = runner.RunCmds(cmds)
if err != nil {
exiterr, ok := err.(*exec.ExitError)
if ok {
os.Exit(exiterr.ExitCode())
}
os.Exit(1)
}
}
}