Skip to content

Commit

Permalink
[gen] Improve alias and eol info handling
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 17, 2023
1 parent 88881ed commit 91fe0cd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
10 changes: 7 additions & 3 deletions common/rbinstall.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -118,6 +118,10 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Tue Oct 17 2023 Anton Novojilov <[email protected]> - 3.1.2-0
- [gen] Improved alias and eol info handling
- Dependencies update

* Tue Oct 03 2023 Anton Novojilov <[email protected]> - 3.1.1-0
- [gen] Fixed bug with searching base version
- Dependencies update
Expand Down
61 changes: 43 additions & 18 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))
}

// ////////////////////////////////////////////////////////////////////////////////// //
Expand All @@ -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"},
Expand Down Expand Up @@ -190,33 +187,37 @@ 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)
}
}

// loadAliasInfo loads aliases info
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)
}
}

Expand Down Expand Up @@ -330,6 +331,10 @@ func buildIndex(dataDir string) {
}

printIndexStats(newIndex)
printExtraInfo()

fmtutil.Separator(false)

saveIndex(outputFile, newIndex)

fmtc.Printf(
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 91fe0cd

Please sign in to comment.