mirror of
https://github.com/ddworken/hishtory.git
synced 2025-02-13 00:50:22 +01:00
Display the hostname in the table
This commit is contained in:
parent
5c508e7cfc
commit
97670c92f5
@ -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()
|
headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc()
|
||||||
tbl := table.New("CWD", "Timestamp", "Runtime", "Exit Code", "Command")
|
tbl := table.New("Hostname", "CWD", "Timestamp", "Runtime", "Exit Code", "Command")
|
||||||
if displayHostname {
|
|
||||||
tbl = table.New("Hostname", "CWD", "Timestamp", "Runtime", "Exit Code", "Command")
|
|
||||||
}
|
|
||||||
tbl.WithHeaderFormatter(headerFmt)
|
tbl.WithHeaderFormatter(headerFmt)
|
||||||
|
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
timestamp := result.StartTime.Format("Jan 2 2006 15:04:05 MST")
|
timestamp := result.StartTime.Format("Jan 2 2006 15:04:05 MST")
|
||||||
duration := result.EndTime.Sub(result.StartTime).Round(time.Millisecond).String()
|
duration := result.EndTime.Sub(result.StartTime).Round(time.Millisecond).String()
|
||||||
if displayHostname {
|
|
||||||
tbl.AddRow(result.Hostname, result.CurrentWorkingDirectory, timestamp, duration, result.ExitCode, result.Command)
|
tbl.AddRow(result.Hostname, result.CurrentWorkingDirectory, timestamp, duration, result.ExitCode, result.Command)
|
||||||
} else {
|
|
||||||
tbl.AddRow(result.CurrentWorkingDirectory, timestamp, duration, result.ExitCode, result.Command)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tbl.Print()
|
tbl.Print()
|
||||||
|
@ -97,7 +97,7 @@ func query(query string) {
|
|||||||
lib.CheckFatalError(displayBannerIfSet())
|
lib.CheckFatalError(displayBannerIfSet())
|
||||||
data, err := data.Search(db, query, 25)
|
data, err := data.Search(db, query, 25)
|
||||||
lib.CheckFatalError(err)
|
lib.CheckFatalError(err)
|
||||||
lib.DisplayResults(data, false)
|
lib.DisplayResults(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func displayBannerIfSet() error {
|
func displayBannerIfSet() error {
|
||||||
|
Loading…
Reference in New Issue
Block a user