-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
104 lines (80 loc) · 1.74 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
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"errors"
"fmt"
"os"
"github.com/deeper-x/svm/git"
"github.com/deeper-x/svm/settings"
)
func main() {
out, err := svm()
if err != nil {
fmt.Println(err)
}
fmt.Print(out)
}
func svm() (string, error) {
tag, err := git.NewTag()
if err != nil {
return settings.DefaultErrMsg, err
}
err = git.CheckNumArgs(2)
if err != nil {
return settings.DefaultErrMsg, err
}
switch action := os.Args[1]; action {
case "show":
tag, err := git.NewTag()
if err != nil {
return settings.DefaultErrMsg, err
}
out := fmt.Sprintf("Current version: %s\n", tag.String())
return out, nil
case "major":
newVer := fmt.Sprintf("v%d.%d.%d\n", tag.Major+1, 0, 0)
err := tag.SetNewVer(newVer)
if err != nil {
return settings.DefaultErrMsg, err
}
return newVer, nil
case "minor":
newVer := fmt.Sprintf("v%d.%d.%d\n", tag.Major, tag.Minor+1, 0)
err := tag.SetNewVer(newVer)
if err != nil {
return settings.DefaultErrMsg, err
}
return newVer, nil
case "patch":
newVer := fmt.Sprintf("v%d.%d.%d\n", tag.Major, tag.Minor, tag.Patch+1)
err := tag.SetNewVer(newVer)
if err != nil {
return settings.DefaultErrMsg, err
}
return newVer, nil
case "undo":
res, err := tag.Undo()
if err != nil {
return settings.DefaultErrMsg, err
}
return res, nil
case "all":
res, err := tag.ShowAll()
if err != nil {
return settings.DefaultErrMsg, err
}
return res, nil
case "write":
err = git.CheckNumArgs(3)
if err != nil {
return settings.DefaultErrMsg, err
}
fName := os.Args[2]
err := tag.WriteFile(fName)
if err != nil {
return settings.DefaultErrMsg, err
}
return "Saved to file", nil
default:
return settings.DefaultErrMsg, errors.New(settings.DefaultOut)
}
}