From bbeaa014851b45d6ca2e6b121f832067f442f7aa Mon Sep 17 00:00:00 2001 From: Nitish Tiwari Date: Tue, 13 Aug 2024 22:28:57 +0530 Subject: [PATCH] fix: cleanup the query list command (#52) --- cmd/{filterList.go => filterlist.go} | 16 ++++++++-------- pkg/model/{savedFilters.go => savedfilters.go} | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) rename cmd/{filterList.go => filterlist.go} (89%) rename pkg/model/{savedFilters.go => savedfilters.go} (99%) diff --git a/cmd/filterList.go b/cmd/filterlist.go similarity index 89% rename from cmd/filterList.go rename to cmd/filterlist.go index 7563e97..2f686c2 100644 --- a/cmd/filterList.go +++ b/cmd/filterlist.go @@ -28,15 +28,14 @@ import ( var FilterList = &cobra.Command{ Use: "list", Example: "pb query list ", - Short: "List of saved filter for a stream", - Long: "\nShow a list of saved filter for a stream ", + Short: "List of saved filters", + Long: "\nShow the list of saved filters for current user", PreRunE: PreRunDefaultProfile, Run: func(_ *cobra.Command, _ []string) { client := DefaultClient() p := model.UIApp() - _, err := p.Run() - if err != nil { + if _, err := p.Run(); err != nil { os.Exit(1) } @@ -46,17 +45,18 @@ var FilterList = &cobra.Command{ filterToPbQuery(a.Stream(), a.StartTime(), a.EndTime()) } if d.FilterID() != "" { - deleteFilter(&client, d.FilterID()) + deleteFilter(&client, d.FilterID(), d.Title()) } }, } // Delete a saved filter from the list of filter -func deleteFilter(client *HTTPClient, filterID string) { +func deleteFilter(client *HTTPClient, filterID, title string) { + fmt.Printf("\nAttempting to delete '%s'", title) deleteURL := `filters/filter/` + filterID req, err := client.NewRequest("DELETE", deleteURL, nil) if err != nil { - fmt.Println("Error deleting the filter") + fmt.Println("Failed to delete the filter with error: ", err) } resp, err := client.client.Do(req) @@ -66,7 +66,7 @@ func deleteFilter(client *HTTPClient, filterID string) { defer resp.Body.Close() if resp.StatusCode == 200 { - fmt.Printf("\n\nFilter Deleted") + fmt.Printf("\nFilter deleted\n\n") } } diff --git a/pkg/model/savedFilters.go b/pkg/model/savedfilters.go similarity index 99% rename from pkg/model/savedFilters.go rename to pkg/model/savedfilters.go index 5d2fd2b..d498381 100644 --- a/pkg/model/savedFilters.go +++ b/pkg/model/savedfilters.go @@ -254,6 +254,8 @@ func fetchFilters(client *http.Client, profile *config.Profile) []list.Item { fmt.Println("Error unmarshalling response:", err) return nil } + + // This returns only the SQL type filters var userFilters []list.Item for _, filter := range filters { var userFilter Item