-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
main.go
76 lines (59 loc) · 1.63 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
package main
import (
"fmt"
"log"
"os"
"runtime"
"github.com/go-errors/errors"
"github.com/integrii/flaggy"
"github.com/jesseduffield/lazynpm/pkg/app"
"github.com/jesseduffield/lazynpm/pkg/config"
)
var (
commit string
version = "unversioned"
date string
buildSource = "unknown"
)
func main() {
flaggy.DefaultParser.ShowVersionWithVersionFlag = false
packagePath := "."
flaggy.String(&packagePath, "p", "path", "Path of package")
versionFlag := false
flaggy.Bool(&versionFlag, "v", "version", "Print the current version")
debuggingFlag := false
flaggy.Bool(&debuggingFlag, "d", "debug", "Run in debug mode with logging")
configFlag := false
flaggy.Bool(&configFlag, "c", "config", "Print the current default config")
flaggy.Parse()
if versionFlag {
fmt.Printf("commit=%s, build date=%s, build source=%s, version=%s, os=%s, arch=%s\n", commit, date, buildSource, version, runtime.GOOS, runtime.GOARCH)
os.Exit(0)
}
if configFlag {
fmt.Printf("%s\n", config.GetDefaultConfig())
os.Exit(0)
}
if packagePath != "." {
if err := os.Chdir(packagePath); err != nil {
log.Fatal(err.Error())
}
}
appConfig, err := config.NewAppConfig("lazynpm", version, commit, date, buildSource, debuggingFlag)
if err != nil {
log.Fatal(err.Error())
}
app, err := app.NewApp(appConfig)
if err == nil {
err = app.Run()
}
if err != nil {
if errorMessage, known := app.KnownError(err); known {
log.Fatal(errorMessage)
}
newErr := errors.Wrap(err, 0)
stackTrace := newErr.ErrorStack()
app.Log.Error(stackTrace)
log.Fatal(fmt.Sprintf("%s\n\n%s", app.Tr.SLocalize("ErrorOccurred"), stackTrace))
}
}