Skip to content

Commit 4289ace

Browse files
committed
Fix metadata formatting
1 parent d24fd58 commit 4289ace

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

term_helpers.go

+31-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"fmt"
5-
"strconv"
65
"strings"
76

87
"github.com/blugelabs/bluge"
@@ -35,18 +34,40 @@ func printRow(header, value, color string) {
3534
}
3635

3736
func printMetadata(field string, value []byte, color string) {
38-
f := strings.Title(field)
37+
var f string
3938
if field == "_id" {
4039
f = "ID"
41-
}
42-
if field == "year" {
43-
y, _ := bluge.DecodeNumericFloat64(value)
44-
printRow(f, strconv.Itoa(int(y)), headerColor)
40+
} else if field == "repository_id" {
41+
f = "Repository ID"
4542
} else {
46-
v := string(value)
47-
if v == "" {
48-
v = "unknown"
43+
f = strings.Title(strings.ReplaceAll(field, "_", " "))
44+
}
45+
46+
var v string
47+
switch field {
48+
case "mtime":
49+
t, err := bluge.DecodeDateTime(value)
50+
if err != nil {
51+
v = "error"
52+
} else {
53+
v = fmt.Sprintf(t.Format("2006-1-2"))
54+
}
55+
case "size":
56+
t, err := bluge.DecodeNumericFloat64(value)
57+
if err != nil {
58+
v = "error"
59+
} else {
60+
v = fmt.Sprintf("%0.f", t)
4961
}
50-
printRow(f, v, headerColor)
62+
case "year":
63+
y, err := bluge.DecodeNumericFloat64(value)
64+
if err != nil {
65+
v = "error"
66+
}
67+
v = fmt.Sprintf("%0.f", y)
68+
default:
69+
v = string(value)
5170
}
71+
72+
printRow(f, v, headerColor)
5273
}

0 commit comments

Comments
 (0)