-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonova.go
95 lines (82 loc) · 1.73 KB
/
monova.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
92
93
94
95
package main
import (
"flag"
"fmt"
"os"
"path"
)
var version string
var debugFlag *bool
var infoFlag *bool
var versionFlag *bool
var checkpointFlag *bool
var resetFlag *bool
var historyFlag *bool
func init() {
infoFlag = flag.Bool("info", false, "Print old and new version")
versionFlag = flag.Bool("version", false, "Print version information")
checkpointFlag = flag.Bool("checkpoint", false, "Create checkpoint [version]")
resetFlag = flag.Bool("reset", false, "Recalculate version")
debugFlag = flag.Bool("debug", false, "Enable extra logging")
historyFlag = flag.Bool("history", false, "Print version history")
flag.Parse()
}
func main() {
var oldVersion string
// Print application version and exit
if *versionFlag {
if version == "" {
fmt.Println("latest")
} else {
fmt.Println(version)
}
return
}
cwd, _ := os.Getwd()
// Remove .monova.history file to recalculate the version
if *resetFlag {
historyPath := path.Join(cwd, historyFilename)
err := os.Remove(historyPath)
if err != nil {
fmt.Println(err)
return
}
}
// Create repository instance
repo, err := CreateRepository(cwd)
if err != nil {
fmt.Println(err)
return
}
// Save old version
if *infoFlag {
oldVersion = repo.GetVersion()
}
// Calculate new version
newVersion, err := repo.UpdateVersion()
if err != nil {
fmt.Println(err)
return
}
if *checkpointFlag {
err = repo.CreateCheckpoint(flag.Args())
if err != nil {
fmt.Println(err)
return
}
return
}
if *infoFlag {
fmt.Printf("%s -> %s\n", oldVersion, newVersion)
fmt.Printf("Commits inspected: %d\n", repo.commitCursor)
} else {
fmt.Println(newVersion)
}
if *historyFlag {
err = PrintHistory()
if err != nil {
fmt.Println(err)
return
}
}
}