-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroot.go
More file actions
61 lines (53 loc) · 1.56 KB
/
root.go
File metadata and controls
61 lines (53 loc) · 1.56 KB
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
/*
Copyright © 2024 Koen van Zuijlen <[email protected]>
*/
package cmd
import (
"os"
"go.uber.org/zap"
"github.com/spf13/cobra"
)
var (
count int
major, minor, patch bool
versionLevel string
useSemver bool
VERSION string
rootCmd = &cobra.Command{
Use: "version",
Short: "A tool to handle version numbers",
Long: `A tool to handle version numbers, i.e. bumping versions and retrieving the latest version of a dependency.`,
PersistentPreRun: setVersionLevel,
Version: VERSION,
}
)
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
rootCmd.PersistentFlags().IntVarP(&count, "count", "c", 1, "Number of versions")
rootCmd.PersistentFlags().BoolVarP(&major, "major", "M", false, "Set version level to major")
rootCmd.PersistentFlags().BoolVarP(&minor, "minor", "m", false, "Set version level to minor")
rootCmd.PersistentFlags().BoolVarP(&patch, "patch", "p", true, "Set version level to patch")
rootCmd.MarkFlagsMutuallyExclusive("major", "minor", "patch")
rootCmd.PersistentFlags().BoolVarP(&useSemver, "semver", "S", true, "Use semver as the versioning type")
}
func setVersionLevel(_ *cobra.Command, _ []string) {
switch {
case major:
versionLevel = "major"
case minor:
versionLevel = "minor"
case patch:
versionLevel = "patch"
default:
versionLevel = "patch"
}
zap.L().Debug("Starting...",
zap.String("version level", versionLevel),
zap.Int("number of versions", count),
)
}