mirror of
https://github.com/ddworken/hishtory.git
synced 2025-02-02 11:39:24 +01:00
Add ability to display columns that map to a custom column
This commit is contained in:
parent
f8c822bab5
commit
890ddfd99c
@ -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 {
|
func DisplayResults(ctx *context.Context, results []*data.HistoryEntry) error {
|
||||||
config := hctx.GetConf(ctx)
|
config := hctx.GetConf(ctx)
|
||||||
headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc()
|
headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc()
|
||||||
@ -425,7 +434,11 @@ 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:
|
||||||
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...)
|
tbl.AddRow(row...)
|
||||||
|
Loading…
Reference in New Issue
Block a user