-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (47 loc) · 1.17 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
package main
import (
"fmt"
"os"
"github.com/bernos/ecso/pkg/ecso"
"github.com/bernos/ecso/pkg/ecso/cli"
"github.com/bernos/ecso/pkg/ecso/config"
"github.com/bernos/ecso/pkg/ecso/dispatcher"
"github.com/bernos/ecso/pkg/ecso/ui"
)
var (
errWriter = ui.NewErrWriter(os.Stderr)
version = "0.0.2"
)
func main() {
project := MustLoadProject(ecso.LoadCurrentProject())
cfg := MustLoadConfig(config.NewConfig(version))
prefs := MustLoadUserPreferences(ecso.LoadCurrentUserPreferences())
dispatcher := dispatcher.NewDispatcher(project, cfg, prefs)
app := cli.NewApp(cfg, project, dispatcher)
err := app.Run(os.Args)
if err != nil {
ExitWithError(err, 1)
}
}
func ExitWithError(err error, code int) {
fmt.Fprintf(errWriter, "%s\n", err.Error())
os.Exit(code)
}
func MustLoadConfig(cfg *config.Config, err error) *config.Config {
if err != nil {
ExitWithError(err, 1)
}
return cfg
}
func MustLoadUserPreferences(prefs *ecso.UserPreferences, err error) *ecso.UserPreferences {
if err != nil {
ExitWithError(err, 1)
}
return prefs
}
func MustLoadProject(project *ecso.Project, err error) *ecso.Project {
if err != nil {
ExitWithError(err, 1)
}
return project
}