Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Some minor refactoring + miscellaneous fixes #13

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var bumpCmd = &cobra.Command{
Long: `Bumps the specified version number with the specified version level.
Can also be used to bump multiple levels with the --number flag`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
version, err := semver.Bump(args[0], versionLevel, numberOfVersions)
version, err := semver.Bump(args[0], versionLevel, count)
if err != nil {
zap.L().Error(err.Error())
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ If a different version level is specified, this command will return the latest n
if err != nil {
return err
}
versions := semver.Select(tags, numberOfVersions, versionLevel)
versions := semver.Select(tags, count, versionLevel)
for _, version := range versions {
fmt.Println(version)
}
Expand Down
8 changes: 5 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var (
numberOfVersions int
count int
major, minor, patch bool
versionLevel string
useSemver bool
Expand All @@ -34,12 +34,14 @@ func Execute() {
}

func init() {
rootCmd.PersistentFlags().IntVarP(&numberOfVersions, "count", "c", 1, "Number of versions")
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.MarkFlagsOneRequired("major", "minor", "patch")
rootCmd.PersistentFlags().BoolVarP(&useSemver, "semver", "S", true, "Use semver as the versioning type")
rootCmd.MarkFlagsOneRequired("semver")
}

func setVersionLevel(_ *cobra.Command, _ []string) {
Expand All @@ -56,6 +58,6 @@ func setVersionLevel(_ *cobra.Command, _ []string) {

zap.L().Debug("Starting...",
zap.String("version level", versionLevel),
zap.Int("number of versions", numberOfVersions),
zap.Int("number of versions", count),
)
}
5 changes: 1 addition & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ func init() {
logger := createLogger()

defer func(logger *zap.Logger) {
err := logger.Sync()
if err != nil {
panic(err)
}
_ = logger.Sync()
}(logger)

zap.ReplaceGlobals(logger)
Expand Down
4 changes: 2 additions & 2 deletions pkg/versioning/semver/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"go.uber.org/zap"
)

func Bump(versionNumber string, versionLevel string, numberOfVersions int) (version *semver.Version, err error) {
func Bump(versionNumber string, versionLevel string, count int) (version *semver.Version, err error) {
version, err = parse(versionNumber)
if err != nil {
zap.L().Error("Error while parsing version", zap.String("versionNumber", versionNumber))
return nil, err
}
for i := 0; i < numberOfVersions; i++ {
for i := 0; i < count; i++ {
version = bumpVersion(versionLevel, version)
}
return version, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/versioning/semver/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"go.uber.org/zap"
)

func Select(tags []string, numberOfVersions int, versionLevel string) (selectedVersions []*semver.Version) {
func Select(tags []string, count int, versionLevel string) (selectedVersions []*semver.Version) {
versions := semverSort(tags)

versionMap := make(map[string]*semver.Version)
Expand All @@ -24,7 +24,7 @@ func Select(tags []string, numberOfVersions int, versionLevel string) (selectedV
if _, exists := versionMap[key]; !exists {
versionMap[key] = version
selectedVersions = append(selectedVersions, version)
if len(selectedVersions) == numberOfVersions {
if len(selectedVersions) == count {
break
}
}
Expand Down
Loading