diff --git a/cli/cli.go b/cli/cli.go index 0a992d9..993bf29 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -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") @@ -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 @@ -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 } diff --git a/clone/clone.go b/clone/clone.go index 8ce8e83..eddf655 100644 --- a/clone/clone.go +++ b/clone/clone.go @@ -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 } diff --git a/common/rbinstall.spec b/common/rbinstall.spec index 33f3311..748577b 100644 --- a/common/rbinstall.spec +++ b/common/rbinstall.spec @@ -10,7 +10,7 @@ Summary: Utility for installing prebuilt Ruby to rbenv Name: rbinstall -Version: 3.1.1 +Version: 3.1.2 Release: 0%{?dist} Group: Applications/System License: Apache License, Version 2.0 @@ -38,7 +38,7 @@ Utility for installing different prebuilt versions of Ruby to rbenv. %package gen Summary: Utility for generating RBInstall index -Version: 3.0.4 +Version: 3.1.0 Release: 0%{?dist} Group: Development/Tools @@ -50,7 +50,7 @@ Utility for generating RBInstall index. %package clone Summary: Utility for cloning RBInstall repository -Version: 3.0.4 +Version: 3.0.5 Release: 0%{?dist} Group: Development/Tools @@ -118,6 +118,12 @@ rm -rf %{buildroot} ################################################################################ %changelog +* Tue Oct 17 2023 Anton Novojilov - 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 - 3.1.1-0 - [gen] Fixed bug with searching base version - Dependencies update diff --git a/gen/gen.go b/gen/gen.go index a6bf208..5d4ee5a 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -40,7 +40,7 @@ import ( // App info const ( APP = "RBInstall Gen" - VER = "3.0.4" + VER = "3.1.0" DESC = "Utility for generating RBInstall index" ) @@ -80,10 +80,7 @@ type fileInfoSlice []FileInfo func (s fileInfoSlice) Len() int { return len(s) } func (s fileInfoSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s fileInfoSlice) Less(i, j int) bool { - return sortutil.VersionCompare( - fmtVersionName(s[i].File), - fmtVersionName(s[j].File), - ) + return sortutil.VersionCompare(fmtVersionName(s[i].File), fmtVersionName(s[j].File)) } // ////////////////////////////////////////////////////////////////////////////////// // @@ -93,8 +90,8 @@ var aliasInfo map[string]string var optMap = options.Map{ OPT_OUTPUT: {Value: INDEX_NAME}, - OPT_EOL: {}, - OPT_ALIAS: {}, + OPT_EOL: {Value: "eol.json"}, + OPT_ALIAS: {Value: "alias.json"}, OPT_NO_COLOR: {Type: options.BOOL}, OPT_HELP: {Type: options.BOOL, Alias: "u:usage"}, OPT_VER: {Type: options.BOOL, Alias: "ver"}, @@ -190,18 +187,20 @@ func configureUI() { } } -// loadEOLInfo load EOL info from file +// loadEOLInfo loads EOL info from file func loadEOLInfo() { eolInfo = make(map[string]bool) - if !options.Has(OPT_EOL) { - return + if !fsutil.CheckPerms("FRS", options.GetS(OPT_EOL)) { + if !options.Has(OPT_EOL) { + return + } } err := jsonutil.Read(options.GetS(OPT_EOL), &eolInfo) if err != nil { - printErrorAndExit(err.Error()) + printErrorAndExit("Can't read EOL data: %v", err) } } @@ -209,14 +208,16 @@ func loadEOLInfo() { func loadAliasInfo() { aliasInfo = make(map[string]string) - if !options.Has(OPT_ALIAS) { - return + if !fsutil.CheckPerms("FRS", options.GetS(OPT_ALIAS)) { + if !options.Has(OPT_ALIAS) { + return + } } err := jsonutil.Read(options.GetS(OPT_ALIAS), &aliasInfo) if err != nil { - printErrorAndExit(err.Error()) + printErrorAndExit("Can't read alias data: %v", err) } } @@ -268,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) @@ -330,6 +331,10 @@ func buildIndex(dataDir string) { } printIndexStats(newIndex) + printExtraInfo() + + fmtutil.Separator(false) + saveIndex(outputFile, newIndex) fmtc.Printf( @@ -415,8 +420,28 @@ func printIndexStats(i *index.Index) { fmtutil.PrettyNum(i.Meta.Items), fmtutil.PrettySize(i.Meta.Size, " "), ) +} - fmtutil.Separator(false) +// printExtraInfo prints info about used alias/eol data +func printExtraInfo() { + fmtutil.Separator(false, "EXTRA") + + eolModTime, _ := fsutil.GetMTime(options.GetS(OPT_EOL)) + aliasModTime, _ := fsutil.GetMTime(options.GetS(OPT_ALIAS)) + + fmtc.If(len(eolInfo) == 0).Println(" {*}EOL: {!} {s}—{!}") + fmtc.If(len(eolInfo) != 0).Printf( + " {*}EOL: {!} %s {s-}(%s){!}\n", + options.GetS(OPT_EOL), + timeutil.Format(eolModTime, "%Y/%m/%d %H:%M"), + ) + + fmtc.If(len(aliasInfo) == 0).Println(" {*}Alias:{!} {s}—{!}") + fmtc.If(len(aliasInfo) != 0).Printf( + " {*}Alias:{!} %s {s-}(%s){!}\n", + options.GetS(OPT_ALIAS), + timeutil.Format(aliasModTime, "%Y/%m/%d %H:%M"), + ) } // saveIndex saves index data as JSON to file @@ -435,7 +460,7 @@ func saveIndex(outputFile string, i *index.Index) { err = os.WriteFile(outputFile, indexData, 0644) if err != nil { - printErrorAndExit(err.Error()) + printErrorAndExit("Can't save index: %v", err) } os.Chmod(outputFile, 0644) @@ -529,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 } @@ -558,8 +583,8 @@ func genUsage() *usage.Info { info.AppNameColorTag = "{*}" + colorTagApp info.AddOption(OPT_OUTPUT, "Custom index output {s-}(default: index.json){!}", "file") - info.AddOption(OPT_EOL, "File with EOL information", "file") - info.AddOption(OPT_ALIAS, "File with aliases information", "file") + info.AddOption(OPT_EOL, "File with EOL information {s-}(default: eol.json){!}", "file") + info.AddOption(OPT_ALIAS, "File with aliases information {s-}(default: alias.json){!}", "file") info.AddOption(OPT_NO_COLOR, "Disable colors in output") info.AddOption(OPT_HELP, "Show this help message") info.AddOption(OPT_VER, "Show version") diff --git a/go.mod b/go.mod index 26e610f..556bc10 100644 --- a/go.mod +++ b/go.mod @@ -4,13 +4,13 @@ go 1.18 require ( github.com/essentialkaos/depsy v1.1.0 - github.com/essentialkaos/ek/v12 v12.79.0 + github.com/essentialkaos/ek/v12 v12.82.0 github.com/essentialkaos/npck v1.6.1 ) require ( github.com/essentialkaos/go-linenoise/v3 v3.4.0 // indirect - github.com/klauspost/compress v1.17.0 // indirect - golang.org/x/crypto v0.13.0 // indirect - golang.org/x/sys v0.12.0 // indirect + github.com/klauspost/compress v1.17.1 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/sys v0.13.0 // indirect ) diff --git a/go.sum b/go.sum index 8b2f60c..705dc58 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,18 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk= github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI= github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= -github.com/essentialkaos/ek/v12 v12.79.0 h1:Dq/bCqk8/N5h/r5jJA2UHc1YoUEVYcc7xnR0DI5L9wA= -github.com/essentialkaos/ek/v12 v12.79.0/go.mod h1:S9/XSKhEAdylL3PF8GAnUeKKyd92VrDGR4YGacHfz0c= +github.com/essentialkaos/ek/v12 v12.82.0 h1:8JqG7E1RWhMJq2CuSV0oaR96pmEjngLPG3cnJ++EJeQ= +github.com/essentialkaos/ek/v12 v12.82.0/go.mod h1:X0gkyjBCP4QiD+sV4D52aquLDLGUmHteMEL7Rsgbev0= github.com/essentialkaos/go-linenoise/v3 v3.4.0 h1:g72w8x+/HIwOMBVvNaPYp+wMWVHrYZwzFAF7OfZR5Ts= github.com/essentialkaos/go-linenoise/v3 v3.4.0/go.mod h1:t1kNLY2bSMQCy1JXOefD2BDLs/TTPMtTv3DFNV5uDSI= github.com/essentialkaos/npck v1.6.1 h1:cFhLRRFNbl7tBXQD2+EkzTHy6y7+oxfvwsVgbhaFvUg= github.com/essentialkaos/npck v1.6.1/go.mod h1:Leny9a2R4otIGqZdnrs8swhI9KvwO+Rmmn2zThpPoN4= -github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM= -github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.17.1 h1:NE3C767s2ak2bweCZo3+rdP4U/HoyVXLv/X9f2gPS5g= +github.com/klauspost/compress v1.17.1/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= -golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/index/index.go b/index/index.go index 7daf05f..effd966 100644 --- a/index/index.go +++ b/index/index.go @@ -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) } @@ -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), } diff --git a/support/support.go b/support/support.go index 9374af0..7ebfd40 100644 --- a/support/support.go +++ b/support/support.go @@ -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 == "" { diff --git a/support/support_linux.go b/support/support_linux.go index 08ec75d..9068a93 100644 --- a/support/support_linux.go +++ b/support/support_linux.go @@ -15,6 +15,7 @@ import ( "github.com/essentialkaos/ek/v12/fmtutil" "github.com/essentialkaos/ek/v12/fsutil" "github.com/essentialkaos/ek/v12/system" + "github.com/essentialkaos/ek/v12/system/container" ) // ////////////////////////////////////////////////////////////////////////////////// // @@ -26,13 +27,14 @@ func showOSInfo() { if err == nil { fmtutil.Separator(false, "OS INFO") - printInfo(12, "Name", osInfo.Name) - printInfo(12, "Pretty Name", osInfo.PrettyName) - printInfo(12, "Version", osInfo.VersionID) + printInfo(12, "Name", osInfo.ColoredName()) + printInfo(12, "Pretty Name", osInfo.ColoredPrettyName()) + printInfo(12, "Version", osInfo.Version) printInfo(12, "ID", osInfo.ID) printInfo(12, "ID Like", osInfo.IDLike) printInfo(12, "Version ID", osInfo.VersionID) printInfo(12, "Version Code", osInfo.VersionCodename) + printInfo(12, "Platform ID", osInfo.PlatformID) printInfo(12, "CPE", osInfo.CPEName) } @@ -40,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) @@ -52,11 +52,13 @@ func showOSInfo() { containerEngine := "No" - switch { - case fsutil.IsExist("/.dockerenv"): + switch container.GetEngine() { + case container.DOCKER: containerEngine = "Yes (Docker)" - case fsutil.IsExist("/run/.containerenv"): + case container.PODMAN: containerEngine = "Yes (Podman)" + case container.LXC: + containerEngine = "Yes (LXC)" } fmtc.NewLine()