Skip to content

Commit

Permalink
fix: cleanup the query list command (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
nitisht authored Aug 13, 2024
1 parent e7eca08 commit bbeaa01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cmd/filterList.go → cmd/filterlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
Expand All @@ -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")
}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/model/savedFilters.go → pkg/model/savedfilters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bbeaa01

Please sign in to comment.