-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (54 loc) · 1.41 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
package main
import (
"flag"
"fmt"
"github.com/TwiN/go-color"
"os"
"rockstaedt/commit-message-check/cmd"
"rockstaedt/commit-message-check/internal/model"
"rockstaedt/commit-message-check/util"
)
var version string
func main() {
flag.Usage = func() {
util.PrintManual(os.Stderr)
}
var versionFlag bool
flag.BoolVar(&versionFlag, "v", false, "Shows the current version of the executable.")
flag.Parse()
if versionFlag {
fmt.Println(version)
os.Exit(0)
}
if len(os.Args) == 1 {
fmt.Println(color.InRed("No subcommands given. Please check manual."))
os.Exit(1)
}
cwd, err := os.Getwd()
if err != nil {
fmt.Println(color.InRed("Could not determine working directory: ") + err.Error())
os.Exit(1)
}
gitPath := fmt.Sprintf("%s/.git", cwd)
_, err = os.Stat(gitPath)
if err != nil {
fmt.Println(color.InRed("No git repository could be found."))
os.Exit(1)
}
var commitMsgFile string
if len(os.Args) == 3 {
commitMsgFile = os.Args[2]
}
config := model.Config{
CommitMsgFile: commitMsgFile,
GitPath: gitPath,
Version: version,
TagUrl: "https://api.github.com/repos/rockstaedt/commit-message-check/releases/latest",
BinaryBaseUrl: "https://github.com/rockstaedt/commit-message-check/releases/latest/download/",
DownloadPath: cwd,
}
handler := cmd.NewHandler(config)
handler.Writer = os.Stdout
handler.Reader = os.Stdin
os.Exit(handler.Run(os.Args[1]))
}