Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cleanup the query list command #52

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading