Skip to content

Commit

Permalink
fixup: always output full TM name in list; use safe parsing option fo…
Browse files Browse the repository at this point in the history
…r TMIDs for comparison
  • Loading branch information
alexbrdn committed Dec 1, 2023
1 parent e48d256 commit 625de52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions internal/app/cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func printToC(toc model.SearchResult, filter string) {
colWidth := columnWidth()
table := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)

_, _ = fmt.Fprintf(table, "NAME\tMANUFACTURER\tMODEL\n")
_, _ = fmt.Fprintf(table, "MANUFACTURER\tMODEL\tNAME\n")
for _, value := range toc.Entries {
name := elideString(value.Name, colWidth)
name := value.Name
man := elideString(value.Manufacturer.Name, colWidth)
mdl := elideString(value.Mpn, colWidth)
_, _ = fmt.Fprintf(table, "%s\t%s\t%s\n", name, man, mdl)
_, _ = fmt.Fprintf(table, "%s\t%s\t%s\n", man, mdl, name)
}
_ = table.Flush()
}
Expand Down
10 changes: 5 additions & 5 deletions internal/model/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ func NewFoundEntryFromTOCEntry(e *TOCEntry, foundIn string) FoundEntry {

func mergeFoundVersions(vs1, vs2 []FoundVersion) []FoundVersion {
vs1 = append(vs1, vs2...)
// whether the TMIDs are official or not is not important for these comparisons
// whether the TMIDs are actually official or not is not important for these comparisons
slices.SortStableFunc(vs1, func(a, b FoundVersion) int {
tmid1, _ := ParseTMID(a.TMID, false)
tmid2, _ := ParseTMID(b.TMID, false)
tmid1, _ := ParseTMID(a.TMID, true)
tmid2, _ := ParseTMID(b.TMID, true)
if tmid1.Equals(tmid2) {
return -strings.Compare(tmid1.Version.Timestamp, tmid2.Version.Timestamp) // sort in reverse chronological order within the same TMID
}
return strings.Compare(a.TMID, b.TMID)
})
return slices.CompactFunc(vs1, func(v1, v2 FoundVersion) bool {
tmid1, _ := ParseTMID(v1.TMID, false)
tmid2, _ := ParseTMID(v2.TMID, false)
tmid1, _ := ParseTMID(v1.TMID, true)
tmid2, _ := ParseTMID(v2.TMID, true)
return tmid1.Equals(tmid2)
})
}
Expand Down

0 comments on commit 625de52

Please sign in to comment.