-
Notifications
You must be signed in to change notification settings - Fork 0
/
major.go
37 lines (31 loc) · 979 Bytes
/
major.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
// SPDX-License-Identifier: MIT
package main
import (
"os"
"github.com/spf13/cobra"
"github.com/ffurrer2/semver/v2/internal/pkg/cli"
"github.com/ffurrer2/semver/v2/pkg/semver"
)
var majorCmd = &cobra.Command{
Use: "major [flag] [semver]...",
Short: "Increment semantic versions to the next major version",
Long: `This command increments a given semantic version to the next major version.`,
Example: ` semver next major 1.0.0-alpha+001`,
Args: cobra.ArbitraryArgs,
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
nextMajor := func(s string) {
semver, err := semver.Parse(s)
if err != nil {
cmd.PrintErrf("error: %v\n", err)
os.Exit(1)
}
cmd.Printf("%s\n", semver.NextMajor().String())
}
cli.Apply(args, cmd.InOrStdin(), nextMajor)
},
}
func init() {
majorCmd.SetUsageTemplate(usageTemplate)
nextCmd.AddCommand(majorCmd)
}