Make the custom column display code support entries that lack a newly configured custom column

This commit is contained in:
David Dworken 2022-10-26 00:44:26 -07:00
parent ef8695ec86
commit 10d26fa407

View File

@ -397,12 +397,18 @@ func AddToDbIfNew(db *gorm.DB, entry data.HistoryEntry) {
} }
} }
func getCustomColumnValue(header string, entry *data.HistoryEntry) (string, error) { func getCustomColumnValue(ctx *context.Context, header string, entry *data.HistoryEntry) (string, error) {
for _, c := range entry.CustomColumns { for _, c := range entry.CustomColumns {
if strings.EqualFold(c.Name, header) { if strings.EqualFold(c.Name, header) {
return c.Val, nil return c.Val, nil
} }
} }
config := hctx.GetConf(ctx)
for _, c := range config.CustomColumns {
if strings.EqualFold(c.ColumnName, header) {
return "", nil
}
}
return "", fmt.Errorf("failed to find a column matching the column name %#v (is there a typo?)", header) return "", fmt.Errorf("failed to find a column matching the column name %#v (is there a typo?)", header)
} }
@ -434,7 +440,7 @@ func DisplayResults(ctx *context.Context, results []*data.HistoryEntry) error {
case "Command": case "Command":
row = append(row, result.Command) row = append(row, result.Command)
default: default:
customColumnValue, err := getCustomColumnValue(header, result) customColumnValue, err := getCustomColumnValue(ctx, header, result)
if err != nil { if err != nil {
return err return err
} }