From 91fe0cd7672aefc4c36d6629aba539ecb5a5b80b Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 17 Oct 2023 18:20:23 +0300 Subject: [PATCH] [gen] Improve alias and eol info handling --- common/rbinstall.spec | 10 ++++--- gen/gen.go | 61 ++++++++++++++++++++++++++++++------------- 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/common/rbinstall.spec b/common/rbinstall.spec index 33f3311..d8babe7 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,10 @@ rm -rf %{buildroot} ################################################################################ %changelog +* Tue Oct 17 2023 Anton Novojilov - 3.1.2-0 +- [gen] Improved alias and eol info handling +- 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..f4df2b5 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) } } @@ -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) @@ -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")