For some reason macos includes N at the end of ints, fix this

This commit is contained in:
David Dworken 2022-04-17 11:09:30 -07:00
parent 787ee8dfd9
commit 8259fc4e45
2 changed files with 23 additions and 1 deletions

View File

@ -85,7 +85,7 @@ func BuildHistoryEntry(args []string) (*data.HistoryEntry, error) {
entry.CurrentWorkingDirectory = cwd
// start time
nanos, err := strconv.ParseInt(args[4], 10, 64)
nanos, err := parseCrossPlatformInt(args[4])
if err != nil {
return nil, fmt.Errorf("failed to parse start time %s as int: %v", args[4], err)
}
@ -122,6 +122,11 @@ func BuildHistoryEntry(args []string) (*data.HistoryEntry, error) {
return &entry, nil
}
func parseCrossPlatformInt(data string) (int64, error) {
data = strings.TrimSuffix(data, "N")
return strconv.ParseInt(data, 10, 64)
}
func getLastCommand(history string) (string, error) {
return strings.SplitN(strings.TrimSpace(history), " ", 2)[1][1:], nil
}

View File

@ -151,3 +151,20 @@ func TestAddToDbIfNew(t *testing.T) {
t.Fatalf("entries has an incorrect length: %d", len(entries))
}
}
func TestParseCrossPlatformInt(t *testing.T) {
res, err := parseCrossPlatformInt("123")
if err != nil {
t.Fatalf("failed to parse int: %v", err)
}
if res != 123 {
t.Fatalf("failed to parse cross platform int %d", res)
}
res, err = parseCrossPlatformInt("123N")
if err != nil {
t.Fatalf("failed to parse int: %v", err)
}
if res != 123 {
t.Fatalf("failed to parse cross platform int %d", res)
}
}