Display the hostname in the table

This commit is contained in:
David Dworken 2022-04-09 14:52:10 -07:00
parent 5c508e7cfc
commit 97670c92f5
2 changed files with 4 additions and 11 deletions

View File

@ -190,22 +190,15 @@ func AddToDbIfNew(db *gorm.DB, entry data.HistoryEntry) {
}
}
func DisplayResults(results []*data.HistoryEntry, displayHostname bool) {
func DisplayResults(results []*data.HistoryEntry) {
headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc()
tbl := table.New("CWD", "Timestamp", "Runtime", "Exit Code", "Command")
if displayHostname {
tbl = table.New("Hostname", "CWD", "Timestamp", "Runtime", "Exit Code", "Command")
}
tbl := table.New("Hostname", "CWD", "Timestamp", "Runtime", "Exit Code", "Command")
tbl.WithHeaderFormatter(headerFmt)
for _, result := range results {
timestamp := result.StartTime.Format("Jan 2 2006 15:04:05 MST")
duration := result.EndTime.Sub(result.StartTime).Round(time.Millisecond).String()
if displayHostname {
tbl.AddRow(result.Hostname, result.CurrentWorkingDirectory, timestamp, duration, result.ExitCode, result.Command)
} else {
tbl.AddRow(result.CurrentWorkingDirectory, timestamp, duration, result.ExitCode, result.Command)
}
tbl.AddRow(result.Hostname, result.CurrentWorkingDirectory, timestamp, duration, result.ExitCode, result.Command)
}
tbl.Print()

View File

@ -97,7 +97,7 @@ func query(query string) {
lib.CheckFatalError(displayBannerIfSet())
data, err := data.Search(db, query, 25)
lib.CheckFatalError(err)
lib.DisplayResults(data, false)
lib.DisplayResults(data)
}
func displayBannerIfSet() error {