diff --git a/actions/download_repos_cache.go b/actions/download_repos_cache.go index c06d13f..4e81f9b 100644 --- a/actions/download_repos_cache.go +++ b/actions/download_repos_cache.go @@ -94,10 +94,11 @@ func (d *DownloadReposCacheAction) convertModelsAndPersist() error { for version, ebuildsWithVersions := range versions { if len(ebuild.Name) == 0 { ebuild = models.Ebuild{ - Name: versions[version].Name, - GroupName: versions[version].GroupName, - Homepage: versions[version].Homepage, - ExtraData: extraData, + Name: versions[version].Name, + GroupName: versions[version].GroupName, + Homepage: versions[version].Homepage, + Description: versions[version].Description, + ExtraData: extraData, } } extraData = append(extraData, models.ExtraData{ diff --git a/cli/templates/ebuild.go b/cli/templates/ebuild.go index 87c56a3..92b1934 100644 --- a/cli/templates/ebuild.go +++ b/cli/templates/ebuild.go @@ -1,6 +1,7 @@ package templates import ( + "fmt" "strings" "github.com/mbaraa/eloi/cli/cfmt" @@ -21,33 +22,53 @@ func EbuildTemplate(ebuild models.Ebuild) string { _, _ = cfmt.Green().Fprint(sb, ebuild.GroupName) _, _ = cfmt.White().Fprint(sb, "/") - _, _ = cfmt.White().Bold().Fprintln(sb, ebuild.Name) + _, _ = cfmt.White().Fprintln(sb, ebuild.Name) if len(ebuild.Homepage) != 0 { _, _ = cfmt.Green().Bold().Fprintf(sb, "\tHomepage: ") _, _ = cfmt.White().Fprintln(sb, ebuild.Homepage) } - // if len(ebuild.Description) != 0 { - // _, _ = cfmt.Green().Bold().Fprintf(sb, "\tDescription: ") - // _, _ = cfmt.White().Fprintln(sb, ebuild.Description) - // } - - versions := new(strings.Builder) - overlays := new(strings.Builder) - for i, extraData := range ebuild.ExtraData { - _, _ = cfmt.Yellow().Fprint(versions, extraData.Version) - _, _ = cfmt.Yellow().Fprint(overlays, extraData.OverlayName) - if i < len(ebuild.ExtraData)-1 { - _, _ = cfmt.Yellow().Fprint(versions, ", ") - _, _ = cfmt.Yellow().Fprint(overlays, ", ") + if len(ebuild.Description) != 0 { + _, _ = cfmt.Green().Bold().Fprintf(sb, "\tDescription: ") + _, _ = cfmt.White().Fprintln(sb, ebuild.Description) + } + + versions := make(map[string]bool) + overlays := make(map[string]bool) + versionsStr := new(strings.Builder) + overlaysStr := new(strings.Builder) + + for _, extraData := range ebuild.ExtraData { + if !versions[extraData.Version] { + _, _ = fmt.Fprint(versionsStr, extraData.Version) + _, _ = fmt.Fprint(versionsStr, ", ") } + + if !overlays[extraData.OverlayName] { + _, _ = fmt.Fprint(overlaysStr, extraData.OverlayName) + _, _ = fmt.Fprint(overlaysStr, ", ") + } + + versions[extraData.Version] = true + overlays[extraData.OverlayName] = true } _, _ = cfmt.Green().Bold().Fprintf(sb, "\tAvailable Overlays: ") - _, _ = cfmt.Yellow().Fprintln(sb, overlays.String()) + _, _ = cfmt.Yellow().Fprintln(sb, removeTrailingCommaSpace(overlaysStr.String())) + _, _ = cfmt.Green().Bold().Fprintf(sb, "\tAvailable Versions: ") - _, _ = cfmt.Yellow().Fprintln(sb, versions.String()) + _, _ = cfmt.Yellow().Fprintln(sb, removeTrailingCommaSpace(versionsStr.String())) return sb.String() } + +func removeTrailingCommaSpace(s string) string { + if len(s) < 2 { + return "" + } + if s[len(s)-2:] == ", " { + return s[:len(s)-2] + } + return s +} diff --git a/models/models.go b/models/models.go index 9e5710f..57e6e93 100755 --- a/models/models.go +++ b/models/models.go @@ -30,11 +30,12 @@ type ExtraData struct { } type Ebuild struct { - gorm.Model `json:"-"` - Id uint `gorm:"primaryKey;autoIncrement"` - Name string - GroupName string - Homepage string + gorm.Model `json:"-"` + Id uint `gorm:"primaryKey;autoIncrement"` + Name string + GroupName string + Homepage string + Description string `json:"description"` ExtraData []ExtraData // version => providers overlays } diff --git a/models/server_models.go b/models/server_models.go index 19d601d..d7cd321 100644 --- a/models/server_models.go +++ b/models/server_models.go @@ -35,4 +35,5 @@ type ServerEbuild struct { OverlayName string `json:"overlayName"` GroupName string `json:"groupName"` Architecture string `json:"architecture"` + Description string `json:"description"` }