This repository has been archived by the owner on Aug 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
94 lines (76 loc) · 1.97 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
package main
import (
"fmt"
"github.com/spf13/cobra"
"log"
"runtime"
"strings"
)
func main() {
var semantic *Semantic
var major, minor, patch, release, beta, alpha bool
var (
version = "dev"
commit = "none"
date = "unknown"
builtBy = "unknown"
)
var info = fmt.Sprintf(
"verg %s (%s, %s, %s) on %s (%s)",
version,
builtBy,
date,
commit,
runtime.GOOS,
runtime.GOARCH,
)
var cmd = &cobra.Command{
Use: "verg",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
s, err := New(args[0])
if err != nil {
log.Fatal(err)
return
}
semantic = s
semantic.Inc(major, minor, patch, release, beta, alpha)
},
PostRun: func(cmd *cobra.Command, args []string) {
fmt.Println(semantic.String())
},
}
var compareCmd = &cobra.Command{
Use: "compare",
Example: "1.0.0 [< or <= or > or >= or ==] 2.0.0",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
items := strings.SplitN(args[0], " ", 3)
if len(items) != 3 {
log.Fatal("Command is not valid argumant. Ex: 1.0.0 [< or <= or > or >= or ==] 2.0.0")
return
}
result, err := Compare(items[0], items[1], items[2])
if err != nil {
log.Fatal(err)
return
}
fmt.Println(result)
},
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of verg",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(info)
},
}
cmd.Flags().BoolVarP(&major, "major", "x", false, "increment major version")
cmd.Flags().BoolVarP(&minor, "minor", "y", false, "increment minor version")
cmd.Flags().BoolVarP(&patch, "patch", "z", false, "increment patch version")
cmd.Flags().BoolVarP(&release, "release", "r", false, "increment release version")
cmd.Flags().BoolVarP(&beta, "beta", "b", false, "increment beta version")
cmd.Flags().BoolVarP(&alpha, "alpha", "a", false, "increment alpha version")
cmd.AddCommand(compareCmd, versionCmd)
_ = cmd.Execute()
}