aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--main.go57
1 files changed, 49 insertions, 8 deletions
diff --git a/main.go b/main.go
index 8bf3496..34e30cb 100644
--- a/main.go
+++ b/main.go
@@ -19,6 +19,31 @@ import (
"github.com/Masterminds/semver/v3"
)
+var (
+ cmdExamples = `
+**stdin**
+❯ echo "1.1.1\n1.2.1" | bumpver patch -
+1.2.2
+
+**file**
+❯ echo v0.1.0 > VERSION
+❯ bumpver patch VERSION
+0.1.1
+
+**a minor**
+❯ bumpver minor <(git tag -l)
+3.4.0
+
+**a major**
+❯ bumpver major <(git tag -l)
+4.0.0
+
+**create new prerelease**
+❯ echo "0.1.0" | bumpver patch --prerelease --prerelease-fmt 'rc.$BumpInt' -
+0.1.1-rc.0
+`
+)
+
// FmtPart format keywords
type FmtPart string
@@ -59,8 +84,10 @@ func (prf *preReleaseVersion) incPreRelease() (semver.Version, error) {
// current int ++
currentVerStrPart := currentPreReleaseParts[idx]
currentVerPart, err := strconv.Atoi(currentVerStrPart)
+ // the current part is not an int, make it one
if err != nil {
- return semver.Version{}, err
+ newPreReleaseParts = append(newPreReleaseParts, "0")
+ continue
}
newPreReleaseParts = append(newPreReleaseParts, strconv.Itoa(currentVerPart+1))
case string(KeyArg):
@@ -107,10 +134,11 @@ var (
preReleaseFmtArgs = make(map[string]string)
preRelease bool
rootCmd = &cobra.Command{
- Use: "bumpver part [major|minor|patch] file [-|file]",
- Short: "A tool for bumping semver git tags.",
- Args: cobra.MatchAll(cobra.ExactArgs(2)),
- Long: `Inspired by the python bump2version tool.`,
+ Use: "bumpver part [major|minor|patch] file [-|file]",
+ Short: "A tool for bumping semver git tags.",
+ Example: cmdExamples,
+ Args: cobra.MatchAll(cobra.ExactArgs(2)),
+ Long: `Inspired by the python bump2version tool.`,
RunE: func(cmd *cobra.Command, argz []string) error {
part := argz[0]
var err error
@@ -157,9 +185,13 @@ var (
case "patch":
nextVersion = lastVersion.IncPatch()
case "prerelease":
+ parsedFmt, err := parseFmtString(preReleaseFmtString)
+ if err != nil {
+ return err
+ }
preRelVersion := preReleaseVersion{
// []string{"PR", "$KeyArg PR_NUM"},
- parseFmtString(preReleaseFmtString),
+ parsedFmt,
preReleaseFmtArgs,
lastVersion,
versionPart,
@@ -207,8 +239,17 @@ func checkArgPart(arg string) error {
return nil
}
-func parseFmtString(toSplit string) []string {
- return strings.Split(toSplit, ".")
+func parseFmtString(toSplit string) ([]string, error) {
+ splitted := strings.Split(toSplit, ".")
+ for _, section := range splitted {
+ keyWord := strings.Split(section, " ")
+ if keyWord[0] == string(KeyArg) {
+ if len(keyWord) != 2 {
+ return []string{}, errors.New("$KeyArg expected to find an argument")
+ }
+ }
+ }
+ return strings.Split(toSplit, "."), nil
}
func main() {