From 890ddfd99c1be14f69520edb324a4f1eca01d550 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Wed, 26 Oct 2022 00:35:36 -0700 Subject: [PATCH] Add ability to display columns that map to a custom column --- client/lib/lib.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/client/lib/lib.go b/client/lib/lib.go index f22cf4e..0859aaa 100644 --- a/client/lib/lib.go +++ b/client/lib/lib.go @@ -397,6 +397,15 @@ func AddToDbIfNew(db *gorm.DB, entry data.HistoryEntry) { } } +func getCustomColumnValue(header string, entry *data.HistoryEntry) (string, error) { + for _, c := range entry.CustomColumns { + if strings.EqualFold(c.Name, header) { + return c.Val, nil + } + } + return "", fmt.Errorf("failed to find a column matching the column name %#v (is there a typo?)", header) +} + func DisplayResults(ctx *context.Context, results []*data.HistoryEntry) error { config := hctx.GetConf(ctx) headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc() @@ -425,7 +434,11 @@ func DisplayResults(ctx *context.Context, results []*data.HistoryEntry) error { case "Command": row = append(row, result.Command) default: - return fmt.Errorf("failed to map column %#v to a value", header) + customColumnValue, err := getCustomColumnValue(header, result) + if err != nil { + return err + } + row = append(row, customColumnValue) } } tbl.AddRow(row...)