Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 17, 2023
1 parent 4379c3e commit f661e8e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
10 changes: 5 additions & 5 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ func getVersionFromFile() (string, error) {
return "", fmtc.Errorf("Can't read version file: %v", err)
}

versionName := strings.Trim(string(versionData[:]), " \n\r")
versionName := strings.Trim(string(versionData), " \n\r")

if versionName == "" {
return "", fmtc.Errorf("Can't use version file - file malformed")
Expand Down Expand Up @@ -1731,7 +1731,7 @@ func isVersionSupportedByBundler(rubyVersion string) bool {

// getNameWithoutPatchLevel return name without -p0
func getNameWithoutPatchLevel(name string) string {
return strings.Replace(name, "-p0", "", -1)
return strings.ReplaceAll(name, "-p0", "")
}

// parseGemInfo extract name and version of gem
Expand Down Expand Up @@ -1800,11 +1800,11 @@ func printCompletion() int {

switch options.GetS(OPT_COMPLETION) {
case "bash":
fmt.Printf(bash.Generate(info, "rbinstall"))
fmt.Print(bash.Generate(info, "rbinstall"))
case "fish":
fmt.Printf(fish.Generate(info, "rbinstall"))
fmt.Print(fish.Generate(info, "rbinstall"))
case "zsh":
fmt.Printf(zsh.Generate(info, optMap, "rbinstall"))
fmt.Print(zsh.Generate(info, optMap, "rbinstall"))
default:
return 1
}
Expand Down
6 changes: 3 additions & 3 deletions clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,11 @@ func printCompletion() int {

switch options.GetS(OPT_COMPLETION) {
case "bash":
fmt.Printf(bash.Generate(info, "rbinstall-clone"))
fmt.Print(bash.Generate(info, "rbinstall-clone"))
case "fish":
fmt.Printf(fish.Generate(info, "rbinstall-clone"))
fmt.Print(fish.Generate(info, "rbinstall-clone"))
case "zsh":
fmt.Printf(zsh.Generate(info, optMap, "rbinstall-clone"))
fmt.Print(zsh.Generate(info, optMap, "rbinstall-clone"))
default:
return 1
}
Expand Down
1 change: 1 addition & 0 deletions common/rbinstall.spec
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ rm -rf %{buildroot}
* Tue Oct 17 2023 Anton Novojilov <[email protected]> - 3.1.2-0
- [gen] Improved alias and eol info handling
- [cli|gen|clone] Improve verbose version info
- [cli|gen|clone] Code refactoring
- Dependencies update

* Tue Oct 03 2023 Anton Novojilov <[email protected]> - 3.1.1-0
Expand Down
8 changes: 4 additions & 4 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func buildIndex(dataDir string) {
alreadyExist := false

filePath := path.Join(dataDir, fileInfo.OS, fileInfo.Arch, fileInfo.File)
fileName := strings.Replace(fileInfo.File, ".tzst", "", -1)
fileName := strutil.Exclude(fileInfo.File, ".tzst")
fileSize := fsutil.GetSize(filePath)
fileAdded, _ := fsutil.GetCTime(filePath)

Expand Down Expand Up @@ -554,11 +554,11 @@ func printCompletion() int {

switch options.GetS(OPT_COMPLETION) {
case "bash":
fmt.Printf(bash.Generate(info, "rbinstall-clone"))
fmt.Print(bash.Generate(info, "rbinstall-clone"))
case "fish":
fmt.Printf(fish.Generate(info, "rbinstall-clone"))
fmt.Print(fish.Generate(info, "rbinstall-clone"))
case "zsh":
fmt.Printf(zsh.Generate(info, optMap, "rbinstall-clone"))
fmt.Print(zsh.Generate(info, optMap, "rbinstall-clone"))
default:
return 1
}
Expand Down
6 changes: 3 additions & 3 deletions index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ type versionInfoSlice []*VersionInfo
func (s versionInfoSlice) Len() int { return len(s) }
func (s versionInfoSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s versionInfoSlice) Less(i, j int) bool {
iv := strings.Replace(s[i].Name, "-", ".", -1)
jv := strings.Replace(s[j].Name, "-", ".", -1)
iv := strings.ReplaceAll(s[i].Name, "-", ".")
jv := strings.ReplaceAll(s[j].Name, "-", ".")

return sortutil.VersionCompare(iv, jv)
}
Expand All @@ -86,7 +86,7 @@ func (s versionInfoSlice) Less(i, j int) bool {
// NewIndex return pointer to new index struct
func NewIndex() *Index {
return &Index{
UUID: uuid.GenUUID(),
UUID: uuid.UUID4().String(),
Meta: &Metadata{},
Data: make(map[string]DistData),
}
Expand Down
2 changes: 1 addition & 1 deletion support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func getHashColorBullet(v string) string {

// printInfo formats and prints info record
func printInfo(size int, name, value string) {
name = name + ":"
name += ":"
size++

if value == "" {
Expand Down
8 changes: 3 additions & 5 deletions support/support_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ func showOSInfo() {

if err != nil {
return
} else {
if osInfo == nil {
fmtutil.Separator(false, "SYSTEM INFO")
printInfo(12, "Name", systemInfo.OS)
}
} else if osInfo == nil {
fmtutil.Separator(false, "SYSTEM INFO")
printInfo(12, "Name", systemInfo.OS)
}

printInfo(12, "Arch", systemInfo.Arch)
Expand Down

0 comments on commit f661e8e

Please sign in to comment.