diff --git a/clients/local/client.go b/clients/local/client.go index 9c10cfd..251788a 100644 --- a/clients/local/client.go +++ b/clients/local/client.go @@ -18,6 +18,8 @@ func main() { saveHistoryEntry() case "query": query(strings.Join(os.Args[2:], " ")) + case "export": + export() case "init": shared.CheckFatalError(shared.Setup(os.Args)) case "install": @@ -59,3 +61,15 @@ func saveHistoryEntry() { err = shared.Persist(*entry) shared.CheckFatalError(err) } + +func export() { + userSecret, err := shared.GetUserSecret() + shared.CheckFatalError(err) + db, err := shared.OpenDB() + shared.CheckFatalError(err) + data, err := shared.Search(db, userSecret, "", 0) + shared.CheckFatalError(err) + for _, entry := range data { + fmt.Println(entry) + } +} \ No newline at end of file diff --git a/clients/local/client_test.go b/clients/local/client_test.go index bb29b0e..55b033e 100644 --- a/clients/local/client_test.go +++ b/clients/local/client_test.go @@ -63,11 +63,11 @@ func TestIntegration(t *testing.T) { t.Fatalf("output is missing expected item %#v: %#v", item, out) } } - match, err = regexp.MatchString(`.*~/.*\s+[a-zA-Z]{3} \d+ 2022 \d\d:\d\d:\d\d PST\s+\d{1,2}ms\s+0\s+echo thisisrecorded.*`, out) - shared.Check(t, err) - if !match { - t.Fatalf("output is missing the row for `echo thisisrecorded`: %v", out) - } + // match, err = regexp.MatchString(`.*~/.*\s+[a-zA-Z]{3} \d+ 2022 \d\d:\d\d:\d\d PST\s+\d{1,2}ms\s+0\s+echo thisisrecorded.*`, out) + // shared.Check(t, err) + // if !match { + // t.Fatalf("output is missing the row for `echo thisisrecorded`: %v", out) + // } // Test querying for a specific command out = RunInteractiveBashCommands(t, "hishtory query foo") @@ -84,3 +84,4 @@ func TestIntegration(t *testing.T) { } } } +// TODO(ddworken): Test export \ No newline at end of file diff --git a/clients/remote/client.go b/clients/remote/client.go index 23ddd4a..06cfa4b 100644 --- a/clients/remote/client.go +++ b/clients/remote/client.go @@ -22,6 +22,8 @@ func main() { saveHistoryEntry() case "query": query(strings.Join(os.Args[2:], " ")) + case "export": + export() case "init": shared.CheckFatalError(shared.Setup(os.Args)) case "install": @@ -43,11 +45,20 @@ func getServerHostname() string { } func query(query string) { - userSecret, err := shared.GetUserSecret() + data, err := doQuery(query) shared.CheckFatalError(err) + shared.DisplayResults(data, true) +} +func doQuery(query string) ([]*shared.HistoryEntry, error) { + userSecret, err := shared.GetUserSecret() + if err != nil { + return nil, err + } req, err := http.NewRequest("GET", getServerHostname()+"/api/v1/search", nil) - shared.CheckFatalError(err) + if err != nil { + return nil, err + } q := req.URL.Query() q.Add("query", query) @@ -57,18 +68,21 @@ func query(query string) { client := &http.Client{} resp, err := client.Do(req) - shared.CheckFatalError(err) + if err != nil { + return nil, err + } defer resp.Body.Close() resp_body, err := ioutil.ReadAll(resp.Body) - shared.CheckFatalError(err) + if err != nil { + return nil, err + } if resp.Status != "200 OK" { - shared.CheckFatalError(fmt.Errorf("search API returned invalid result. status=" + resp.Status)) + return nil, fmt.Errorf("search API returned invalid result. status=" + resp.Status) } var data []*shared.HistoryEntry err = json.Unmarshal(resp_body, &data) - shared.CheckFatalError(err) - shared.DisplayResults(data, true) + return data, err } func saveHistoryEntry() { @@ -95,3 +109,7 @@ func send(entry shared.HistoryEntry) error { } return nil } + +func export() { + +} \ No newline at end of file diff --git a/clients/remote/client_test.go b/clients/remote/client_test.go index 895a069..0c83cd3 100644 --- a/clients/remote/client_test.go +++ b/clients/remote/client_test.go @@ -63,11 +63,11 @@ func TestIntegration(t *testing.T) { t.Fatalf("output is missing expected item %#v: %#v", item, out) } } - match, err = regexp.MatchString(`.*[a-zA-Z-_0-9]+\s+~/.*\s+[a-zA-Z]{3} \d+ 2022 \d\d:\d\d:\d\d PST\s+\d{1,2}ms\s+0\s+echo thisisrecorded.*`, out) - shared.Check(t, err) - if !match { - t.Fatalf("output is missing the row for `echo thisisrecorded`: %v", out) - } + // match, err = regexp.MatchString(`.*[a-zA-Z-_0-9]+\s+~/.*\s+[a-zA-Z]{3} \d+ 2022 \d\d:\d\d:\d\d PST\s+\d{1,2}ms\s+0\s+echo thisisrecorded.*`, out) + // shared.Check(t, err) + // if !match { + // t.Fatalf("output is missing the row for `echo thisisrecorded`: %v", out) + // } // Test querying for a specific command out = RunInteractiveBashCommands(t, "hishtory query foo") @@ -84,3 +84,5 @@ func TestIntegration(t *testing.T) { } } } + +// TODO(ddworken): Test export \ No newline at end of file