mirror of
https://github.com/ddworken/hishtory.git
synced 2025-01-22 22:28:51 +01:00
For some reason macos includes N at the end of ints, fix this
This commit is contained in:
parent
787ee8dfd9
commit
8259fc4e45
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user