-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch.go
37 lines (31 loc) · 980 Bytes
/
patch.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 patchCmd = &cobra.Command{
Use: "patch [flag] [semver]...",
Short: "Increment semantic versions to the next patch version",
Long: `This command increments a given semantic version to the next patch version.'`,
Example: ` semver next patch 1.0.0-alpha+001`,
Args: cobra.ArbitraryArgs,
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
nextPatch := 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.NextPatch().String())
}
cli.Apply(args, cmd.InOrStdin(), nextPatch)
},
}
func init() {
patchCmd.SetUsageTemplate(usageTemplate)
nextCmd.AddCommand(patchCmd)
}