Skip to content

Commit

Permalink
refactor getPackageNameAndVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Spacca committed Dec 1, 2023
1 parent 2af2e1d commit e5acd64
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
23 changes: 7 additions & 16 deletions cmd/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ func rallyCommandAction(cmd *cobra.Command, args []string) error {
rally.WithProfile(profile),
rally.WithRallyTrackOutputDir(rallyTrackOutputDir),
rally.WithRallyDryRun(rallyDryRun),
rally.WithRallyPackageName(packageName),
rally.WithRallyPackageVersion(packageVersion),
rally.WithRallyPackageFromRegistry(packageName, packageVersion),
rally.WithRallyCorpusAtPath(corpusAtPath),
}

Expand Down Expand Up @@ -370,28 +369,20 @@ func rallyCommandAction(cmd *cobra.Command, args []string) error {
}

func getPackageNameAndVersion(packageFromRegistry string) (string, string, error) {
packageFromRegistryReverse := make([]byte, 0, len(packageFromRegistry))
for i := len(packageFromRegistry) - 1; i > -1; i-- {
packageFromRegistryReverse = append(packageFromRegistryReverse, packageFromRegistry[i])
}

packageData := strings.SplitN(string(packageFromRegistryReverse), "-", 2)
packageData := strings.SplitN(packageFromRegistry, "-", 2)

packageName := make([]byte, 0, len(packageData[1]))
for i := len(packageData[1]) - 1; i > -1; i-- {
packageName = append(packageName, packageData[1][i])
if len(packageData) != 2 {
return "", "", fmt.Errorf("package name and version from registry not valid (%s)", packageFromRegistry)
}

packageVersion := make([]byte, 0, len(packageData[0]))
for i := len(packageData[0]) - 1; i > -1; i-- {
packageVersion = append(packageVersion, packageData[0][i])
}
packageName := packageData[0]
packageVersion := packageData[1]

if len(packageName) > 0 && len(packageVersion) == 0 {
return "", "", fmt.Errorf("package name and version from registry not valid (%s)", packageFromRegistry)
}

return string(packageName), string(packageVersion), nil
return packageName, packageVersion, nil
}

func getSystemCommand() *cobra.Command {
Expand Down
7 changes: 1 addition & 6 deletions internal/benchrunner/runners/rally/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,9 @@ func WithRallyDryRun(d bool) OptionFunc {
}
}

func WithRallyPackageName(n string) OptionFunc {
func WithRallyPackageFromRegistry(n, v string) OptionFunc {
return func(opts *Options) {
opts.PackageName = n
}
}

func WithRallyPackageVersion(v string) OptionFunc {
return func(opts *Options) {
opts.PackageVersion = v
}
}
Expand Down

0 comments on commit e5acd64

Please sign in to comment.