diff options
| author | Max Resnick <max@ofmax.li> | 2024-01-27 16:18:38 -0800 |
|---|---|---|
| committer | Max Resnick <max@ofmax.li> | 2024-02-25 08:42:58 -0800 |
| commit | 4b6a22c3e0b3a3eece007fd1abbcf2be7ac5aa39 (patch) | |
| tree | 4776853fbcebbde37dc03246b49932b01b362277 /main.go | |
| parent | 8e365468cec859da974a5e617ab3eb8d0a59df63 (diff) | |
| download | go-bumpver-4b6a22c3e0b3a3eece007fd1abbcf2be7ac5aa39.tar.gz | |
fix: not validated
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 57 |
1 files changed, 49 insertions, 8 deletions
@@ -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() { |