(ctx context.Context, columnNames []string, entry data.HistoryEntry, commandRenderer func(string) string)
| 92 | } |
| 93 | |
| 94 | func BuildTableRow(ctx context.Context, columnNames []string, entry data.HistoryEntry, commandRenderer func(string) string) ([]string, error) { |
| 95 | row := make([]string, 0) |
| 96 | for _, header := range columnNames { |
| 97 | switch header { |
| 98 | case "Hostname", "hostname", "hn": |
| 99 | row = append(row, entry.Hostname) |
| 100 | case "CWD", "cwd": |
| 101 | row = append(row, entry.CurrentWorkingDirectory) |
| 102 | case "Timestamp", "timestamp", "ts": |
| 103 | if entry.StartTime.UnixMilli() == 0 { |
| 104 | row = append(row, "N/A") |
| 105 | } else { |
| 106 | row = append(row, entry.StartTime.Local().Format(hctx.GetConf(ctx).TimestampFormat)) |
| 107 | } |
| 108 | case "Runtime", "runtime", "rt": |
| 109 | if entry.EndTime.UnixMilli() == 0 { |
| 110 | // An EndTime of zero means this is a pre-saved entry that never finished |
| 111 | row = append(row, "N/A") |
| 112 | } else { |
| 113 | row = append(row, entry.EndTime.Local().Sub(entry.StartTime.Local()).Round(time.Millisecond).String()) |
| 114 | } |
| 115 | case "Exit Code", "Exit_Code", "ExitCode", "exitcode", "$?", "EC": |
| 116 | row = append(row, fmt.Sprintf("%d", entry.ExitCode)) |
| 117 | case "Command", "command", "cmd": |
| 118 | row = append(row, commandRenderer(entry.Command)) |
| 119 | case "User", "user": |
| 120 | row = append(row, entry.LocalUsername) |
| 121 | default: |
| 122 | customColumnValue, err := getCustomColumnValue(ctx, header, entry) |
| 123 | if err != nil { |
| 124 | return nil, err |
| 125 | } |
| 126 | row = append(row, customColumnValue) |
| 127 | } |
| 128 | } |
| 129 | return row, nil |
| 130 | } |
| 131 | |
| 132 | // Make a regex that matches the non-tokenized bits of the given query |
| 133 | func MakeRegexFromQuery(query string) string { |
no test coverage detected